feat(widgets): announcement swiper, layout gap, partners/about polish
Announcement defaults to vertical new-swiper; gap supports PC/mobile heights; partners lazy+empty admin; about card uses identity name/bio.
This commit is contained in:
1 parent
93ab4650dd
commit
f529e88862
5 files changed
+455
-142
No files matched your search
@@ -70,8 +70,8 @@ class AboutWidget extends \WP_Widget {
|
||||
</div>
|
||||
|
||||
<div class="aksrt-user-card__info">
|
||||
<div class="aksrt-user-card__name"><?php echo esc_html($u->display_name); ?></div>
|
||||
<div class="aksrt-user-card__desc"><?php echo esc_html($u->user_email); ?></div>
|
||||
<div class="aksrt-user-card__name"><?php if (function_exists('aksrt_get_user_name')) { echo aksrt_get_user_name(['id' => (int) $u->ID, 'class' => 'flex ac', 'follow' => false, 'medal' => true, 'auth' => true, 'level' => true]); } else { echo esc_html($u->display_name); } ?></div>
|
||||
<div class="aksrt-user-card__desc"><?php $bio = trim((string) get_user_meta($u->ID, 'description', true)); echo esc_html($bio !== '' ? $bio : $u->user_email); ?></div>
|
||||
</div>
|
||||
|
||||
<div class="aksrt-user-card__btns">
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* Custom HTML / layout gap (zibll zib_widget_ui_layout_gap + custom HTML).
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
@@ -9,59 +11,98 @@ defined('ABSPATH') || exit;
|
||||
|
||||
class CustomHtmlGapWidget extends \WP_Widget {
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct('aksrt_custom_html_gap', esc_html__('AKSRT 自定义HTML/间距', 'aksrt'), [
|
||||
'description' => esc_html__('插入自定义 HTML 或间距', 'aksrt'),
|
||||
]);
|
||||
}
|
||||
public function __construct() {
|
||||
parent::__construct('aksrt_custom_html_gap', esc_html__('AKSRT 自定义HTML/间距', 'aksrt'), [
|
||||
'description' => esc_html__('插入自定义 HTML 或布局间距(PC/移动可分设)。', 'aksrt'),
|
||||
'classname' => 'widget_aksrt_custom_html_gap',
|
||||
]);
|
||||
}
|
||||
|
||||
public function widget($args, $instance): void {
|
||||
$mode = sanitize_key($instance['mode'] ?? 'html');
|
||||
/**
|
||||
* @param array<string,mixed> $args
|
||||
* @param array<string,mixed> $instance
|
||||
*/
|
||||
public function widget($args, $instance): void {
|
||||
$mode = sanitize_key((string) ($instance['mode'] ?? 'html'));
|
||||
|
||||
if ($mode === 'gap') {
|
||||
$height = max(0, min(500, (int) ($instance['gap_height'] ?? 20)));
|
||||
echo '<div class="widget-custom-gap" style="height:' . (int) $height . 'px;" aria-hidden="true"></div>';
|
||||
return;
|
||||
}
|
||||
if ($mode === 'gap') {
|
||||
$pc = max(0, min(500, (int) ($instance['gap_height'] ?? 20)));
|
||||
$m = max(0, min(500, (int) ($instance['gap_height_m'] ?? $pc)));
|
||||
// zibll layout gap: empty spacing block without widget chrome.
|
||||
$style = sprintf('--aksrt-gap-pc:%dpx;--aksrt-gap-m:%dpx;height:%dpx;', $pc, $m, $pc);
|
||||
echo '<div class="widget-custom-gap aksrt-layout-gap" style="' . esc_attr($style) . '" aria-hidden="true"></div>';
|
||||
return;
|
||||
}
|
||||
|
||||
echo $args['before_widget'];
|
||||
$title = apply_filters('widget_title', $instance['title'] ?? '', $instance, $this->id_base);
|
||||
if ($title) echo $args['before_title'] . esc_html($title) . $args['after_title'];
|
||||
echo '<div class="widget-custom-html">' . wp_kses_post($instance['content'] ?? '') . '</div>';
|
||||
echo $args['after_widget'];
|
||||
}
|
||||
$content = (string) ($instance['content'] ?? '');
|
||||
if (trim(wp_strip_all_tags($content)) === '' && trim($content) === '') {
|
||||
if (current_user_can('manage_options')) {
|
||||
echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo '<div class="c-red muted-box mb10"><b>' . esc_html__('自定义 HTML:', 'aksrt') . '</b>' . esc_html__('请填写内容或切换为间距模式', 'aksrt') . '</div>';
|
||||
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
public function form($instance): void {
|
||||
$mode = sanitize_key($instance['mode'] ?? 'html');
|
||||
?>
|
||||
<p>
|
||||
<label for="<?php echo $this->get_field_id('mode'); ?>"><?php esc_html_e('模式:', 'aksrt'); ?></label>
|
||||
<select class="widefat" id="<?php echo $this->get_field_id('mode'); ?>" name="<?php echo $this->get_field_name('mode'); ?>">
|
||||
<option value="html" <?php selected($mode, 'html'); ?>><?php esc_html_e('自定义 HTML', 'aksrt'); ?></option>
|
||||
<option value="gap" <?php selected($mode, 'gap'); ?>><?php esc_html_e('间距', 'aksrt'); ?></option>
|
||||
</select>
|
||||
</p>
|
||||
<p>
|
||||
<label for="<?php echo $this->get_field_id('title'); ?>"><?php esc_html_e('标题(仅 HTML 模式,可选):', 'aksrt'); ?></label>
|
||||
<input class="widefat" type="text" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr($instance['title'] ?? ''); ?>">
|
||||
</p>
|
||||
<p>
|
||||
<label for="<?php echo $this->get_field_id('content'); ?>"><?php esc_html_e('HTML 内容:', 'aksrt'); ?></label>
|
||||
<textarea class="widefat" rows="6" id="<?php echo $this->get_field_id('content'); ?>" name="<?php echo $this->get_field_name('content'); ?>"><?php echo esc_textarea($instance['content'] ?? ''); ?></textarea>
|
||||
</p>
|
||||
<p>
|
||||
<label for="<?php echo $this->get_field_id('gap_height'); ?>"><?php esc_html_e('间距高度(px,仅间距模式):', 'aksrt'); ?></label>
|
||||
<input class="tiny-text" type="number" min="0" max="500" id="<?php echo $this->get_field_id('gap_height'); ?>" name="<?php echo $this->get_field_name('gap_height'); ?>" value="<?php echo (int) ($instance['gap_height'] ?? 20); ?>">
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
$title = apply_filters('widget_title', (string) ($instance['title'] ?? ''), $instance, $this->id_base);
|
||||
if ($title !== '') {
|
||||
echo $args['before_title'] . esc_html($title) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
$full_width = !empty($instance['full_width']);
|
||||
$cls = 'widget-custom-html' . ($full_width ? ' is-full' : '');
|
||||
echo '<div class="' . esc_attr($cls) . '">' . wp_kses_post($content) . '</div>';
|
||||
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
|
||||
public function update($new_instance, $old_instance): array {
|
||||
return [
|
||||
'mode' => in_array($new_instance['mode'] ?? '', ['html', 'gap'], true) ? $new_instance['mode'] : 'html',
|
||||
'title' => sanitize_text_field($new_instance['title'] ?? ''),
|
||||
'content' => wp_kses_post($new_instance['content'] ?? ''),
|
||||
'gap_height' => max(0, min(500, (int) ($new_instance['gap_height'] ?? 20))),
|
||||
];
|
||||
}
|
||||
/**
|
||||
* @param array<string,mixed> $instance
|
||||
*/
|
||||
public function form($instance): void {
|
||||
$mode = sanitize_key((string) ($instance['mode'] ?? 'html'));
|
||||
?>
|
||||
<p>
|
||||
<label for="<?php echo esc_attr($this->get_field_id('mode')); ?>"><?php esc_html_e('模式:', 'aksrt'); ?></label>
|
||||
<select class="widefat" id="<?php echo esc_attr($this->get_field_id('mode')); ?>" name="<?php echo esc_attr($this->get_field_name('mode')); ?>">
|
||||
<option value="html" <?php selected($mode, 'html'); ?>><?php esc_html_e('自定义 HTML', 'aksrt'); ?></option>
|
||||
<option value="gap" <?php selected($mode, 'gap'); ?>><?php esc_html_e('布局间距', 'aksrt'); ?></option>
|
||||
</select>
|
||||
</p>
|
||||
<p>
|
||||
<label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_html_e('标题(仅 HTML 模式,可选):', 'aksrt'); ?></label>
|
||||
<input class="widefat" type="text" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" value="<?php echo esc_attr((string) ($instance['title'] ?? '')); ?>">
|
||||
</p>
|
||||
<p>
|
||||
<label for="<?php echo esc_attr($this->get_field_id('content')); ?>"><?php esc_html_e('HTML 内容:', 'aksrt'); ?></label>
|
||||
<textarea class="widefat" rows="6" id="<?php echo esc_attr($this->get_field_id('content')); ?>" name="<?php echo esc_attr($this->get_field_name('content')); ?>"><?php echo esc_textarea((string) ($instance['content'] ?? '')); ?></textarea>
|
||||
</p>
|
||||
<p>
|
||||
<label for="<?php echo esc_attr($this->get_field_id('gap_height')); ?>"><?php esc_html_e('PC 间距高度 px:', 'aksrt'); ?></label>
|
||||
<input class="tiny-text" type="number" min="0" max="500" id="<?php echo esc_attr($this->get_field_id('gap_height')); ?>" name="<?php echo esc_attr($this->get_field_name('gap_height')); ?>" value="<?php echo esc_attr((string) ((int) ($instance['gap_height'] ?? 20))); ?>">
|
||||
</p>
|
||||
<p>
|
||||
<label for="<?php echo esc_attr($this->get_field_id('gap_height_m')); ?>"><?php esc_html_e('移动间距高度 px:', 'aksrt'); ?></label>
|
||||
<input class="tiny-text" type="number" min="0" max="500" id="<?php echo esc_attr($this->get_field_id('gap_height_m')); ?>" name="<?php echo esc_attr($this->get_field_name('gap_height_m')); ?>" value="<?php echo esc_attr((string) ((int) ($instance['gap_height_m'] ?? $instance['gap_height'] ?? 20))); ?>">
|
||||
</p>
|
||||
<p>
|
||||
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('full_width')); ?>" value="1" <?php checked(!empty($instance['full_width'])); ?>> <?php esc_html_e('HTML 通栏', 'aksrt'); ?></label>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $new_instance
|
||||
* @param array<string,mixed> $old_instance
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public function update($new_instance, $old_instance): array {
|
||||
return [
|
||||
'mode' => in_array(($new_instance['mode'] ?? ''), ['html', 'gap'], true) ? $new_instance['mode'] : 'html',
|
||||
'title' => sanitize_text_field((string) ($new_instance['title'] ?? '')),
|
||||
'content' => wp_kses_post((string) ($new_instance['content'] ?? '')),
|
||||
'gap_height' => max(0, min(500, (int) ($new_instance['gap_height'] ?? 20))),
|
||||
'gap_height_m' => max(0, min(500, (int) ($new_instance['gap_height_m'] ?? $new_instance['gap_height'] ?? 20))),
|
||||
'full_width' => !empty($new_instance['full_width']) ? 1 : 0,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* Announcement marquee → vertical notice swiper (zibll notice family parity).
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
@@ -9,101 +11,156 @@ defined('ABSPATH') || exit;
|
||||
|
||||
class WidgetAnnouncement extends \WP_Widget {
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct(
|
||||
'aksrt_announcement',
|
||||
__('公告跑马灯', 'aksrt'),
|
||||
['description' => __('滚动显示公告/通知。', 'aksrt')]
|
||||
);
|
||||
}
|
||||
public function __construct() {
|
||||
parent::__construct(
|
||||
'aksrt_announcement',
|
||||
__('公告跑马灯', 'aksrt'),
|
||||
[
|
||||
'description' => __('滚动显示公告/通知(共享垂直 Swiper)。', 'aksrt'),
|
||||
'classname' => 'widget_aksrt_announcement',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function widget($args, $instance): void {
|
||||
$title = !empty($instance['title']) ? $instance['title'] : '';
|
||||
$items = !empty($instance['items']) ? $instance['items'] : '';
|
||||
$icon = !empty($instance['icon']) ? $instance['icon'] : 'fas fa-bullhorn';
|
||||
$speed = !empty($instance['speed']) ? max(5, min(30, (int) $instance['speed'])) : 10;
|
||||
/**
|
||||
* @param array<string,mixed> $args
|
||||
* @param array<string,mixed> $instance
|
||||
*/
|
||||
public function widget($args, $instance): void {
|
||||
$title = !empty($instance['title']) ? (string) $instance['title'] : '';
|
||||
$items = !empty($instance['items']) ? (string) $instance['items'] : '';
|
||||
$icon = !empty($instance['icon']) ? (string) $instance['icon'] : 'fas fa-bullhorn';
|
||||
$speed = !empty($instance['speed']) ? max(5, min(30, (int) $instance['speed'])) : 10;
|
||||
$mode = sanitize_key((string) ($instance['mode'] ?? 'swiper'));
|
||||
if (!in_array($mode, ['swiper', 'marquee'], true)) {
|
||||
$mode = 'swiper';
|
||||
}
|
||||
$interval = max(2, min(15, (int) ($instance['interval'] ?? max(3, (int) round($speed / 2)))));
|
||||
$blank = !empty($instance['blank']);
|
||||
|
||||
$lines = array_filter(array_map('trim', explode("\n", $items)));
|
||||
if (empty($lines)) return;
|
||||
$lines = array_values(array_filter(array_map('trim', explode("\n", $items))));
|
||||
if (!$lines) {
|
||||
return;
|
||||
}
|
||||
|
||||
echo $args['before_widget'];
|
||||
echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
|
||||
if ($title) {
|
||||
echo $args['before_title'] . esc_html($title) . $args['after_title'];
|
||||
}
|
||||
if ($title !== '') {
|
||||
echo $args['before_title'] . esc_html($title) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
|
||||
echo '<div class="aksrt-announcement">';
|
||||
echo '<span class="aksrt-announcement__icon"><i class="' . esc_attr($icon) . '"></i></span>';
|
||||
echo '<div class="aksrt-announcement__track">';
|
||||
echo '<ul class="aksrt-announcement__list" style="animation-duration: ' . esc_attr((string) $speed) . 's;">';
|
||||
if ($mode === 'marquee') {
|
||||
// Legacy CSS marquee path.
|
||||
echo '<div class="aksrt-announcement">';
|
||||
echo '<span class="aksrt-announcement__icon"><i class="' . esc_attr($icon) . '" aria-hidden="true"></i></span>';
|
||||
echo '<div class="aksrt-announcement__track">';
|
||||
echo '<ul class="aksrt-announcement__list" style="animation-duration: ' . esc_attr((string) $speed) . 's;">';
|
||||
$render = function (string $line) use ($blank): void {
|
||||
$parts = explode('|', $line, 2);
|
||||
$text = trim($parts[0]);
|
||||
$link = isset($parts[1]) ? trim($parts[1]) : '';
|
||||
echo '<li class="aksrt-announcement__item">';
|
||||
if ($link !== '') {
|
||||
echo '<a href="' . esc_url($link) . '"' . ($blank ? ' target="_blank" rel="noopener noreferrer"' : '') . '>' . esc_html($text) . '</a>';
|
||||
} else {
|
||||
echo esc_html($text);
|
||||
}
|
||||
echo '</li>';
|
||||
};
|
||||
foreach ($lines as $line) {
|
||||
$render($line);
|
||||
}
|
||||
// Duplicate first for seamless CSS loop.
|
||||
$render($lines[0]);
|
||||
echo '</ul></div></div>';
|
||||
} else {
|
||||
// Shared vertical new-swiper (same stack as NoticeWidget).
|
||||
echo '<div class="aksrt-scroll-notice aksrt-announcement-swiper-wrap swiper-bulletin">';
|
||||
echo '<div class="aksrt-scroll-notice__icon bulletin-icon"><i class="' . esc_attr($icon) . '" aria-hidden="true"></i></div>';
|
||||
echo '<div class="new-swiper aksrt-notice-swiper aksrt-announcement-swiper" data-direction="vertical" data-loop data-autoplay data-interval="' . esc_attr((string) ($interval * 1000)) . '">';
|
||||
echo '<div class="swiper-wrapper">';
|
||||
foreach ($lines as $line) {
|
||||
$parts = explode('|', $line, 2);
|
||||
$text = trim($parts[0]);
|
||||
$link = isset($parts[1]) ? trim($parts[1]) : '';
|
||||
echo '<div class="swiper-slide notice-slide">';
|
||||
if ($link !== '') {
|
||||
echo '<a class="text-ellipsis"' . ($blank ? ' target="_blank" rel="noopener noreferrer"' : '') . ' href="' . esc_url($link) . '">' . esc_html($text) . '</a>';
|
||||
} else {
|
||||
echo '<span class="text-ellipsis">' . esc_html($text) . '</span>';
|
||||
}
|
||||
echo '</div>';
|
||||
}
|
||||
echo '</div></div></div>';
|
||||
}
|
||||
|
||||
foreach ($lines as $line) {
|
||||
// 支持 "文本|链接" 格式
|
||||
$parts = explode('|', $line, 2);
|
||||
$text = trim($parts[0]);
|
||||
$link = isset($parts[1]) ? trim($parts[1]) : '';
|
||||
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
|
||||
echo '<li class="aksrt-announcement__item">';
|
||||
if ($link) {
|
||||
echo '<a href="' . esc_url($link) . '">' . esc_html($text) . '</a>';
|
||||
} else {
|
||||
echo esc_html($text);
|
||||
}
|
||||
echo '</li>';
|
||||
}
|
||||
/**
|
||||
* @param array<string,mixed> $instance
|
||||
*/
|
||||
public function form($instance): void {
|
||||
$title = !empty($instance['title']) ? (string) $instance['title'] : '';
|
||||
$items = !empty($instance['items']) ? (string) $instance['items'] : '';
|
||||
$icon = !empty($instance['icon']) ? (string) $instance['icon'] : 'fas fa-bullhorn';
|
||||
$speed = !empty($instance['speed']) ? (int) $instance['speed'] : 10;
|
||||
$mode = (string) ($instance['mode'] ?? 'swiper');
|
||||
?>
|
||||
<p>
|
||||
<label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_html_e('标题(可选):', 'aksrt'); ?></label>
|
||||
<input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr($title); ?>">
|
||||
</p>
|
||||
<p>
|
||||
<label for="<?php echo esc_attr($this->get_field_id('items')); ?>"><?php esc_html_e('公告内容(每行一条):', 'aksrt'); ?></label>
|
||||
<textarea class="widefat" id="<?php echo esc_attr($this->get_field_id('items')); ?>" name="<?php echo esc_attr($this->get_field_name('items')); ?>" rows="5" placeholder="系统维护通知 新功能上线|https://example.com"><?php echo esc_textarea($items); ?></textarea>
|
||||
<small><?php esc_html_e('每行一条,格式:文本 或 文本|链接', 'aksrt'); ?></small>
|
||||
</p>
|
||||
<p>
|
||||
<label><?php esc_html_e('模式', 'aksrt'); ?>
|
||||
<select name="<?php echo esc_attr($this->get_field_name('mode')); ?>">
|
||||
<option value="swiper" <?php selected($mode, 'swiper'); ?>><?php esc_html_e('垂直轮播(推荐)', 'aksrt'); ?></option>
|
||||
<option value="marquee" <?php selected($mode, 'marquee'); ?>><?php esc_html_e('横向跑马灯', 'aksrt'); ?></option>
|
||||
</select>
|
||||
</label>
|
||||
</p>
|
||||
<p>
|
||||
<label for="<?php echo esc_attr($this->get_field_id('icon')); ?>"><?php esc_html_e('图标:', 'aksrt'); ?></label>
|
||||
<input class="widefat" id="<?php echo esc_attr($this->get_field_id('icon')); ?>" name="<?php echo esc_attr($this->get_field_name('icon')); ?>" type="text" value="<?php echo esc_attr($icon); ?>">
|
||||
</p>
|
||||
<p>
|
||||
<label for="<?php echo esc_attr($this->get_field_id('speed')); ?>"><?php esc_html_e('滚动速度(秒,跑马灯):', 'aksrt'); ?></label>
|
||||
<input class="tiny-text" id="<?php echo esc_attr($this->get_field_id('speed')); ?>" name="<?php echo esc_attr($this->get_field_name('speed')); ?>" type="number" value="<?php echo esc_attr((string) $speed); ?>" min="5" max="30">
|
||||
</p>
|
||||
<p>
|
||||
<label><?php esc_html_e('轮播间隔(秒)', 'aksrt'); ?>
|
||||
<input class="tiny-text" type="number" min="2" max="15" name="<?php echo esc_attr($this->get_field_name('interval')); ?>" value="<?php echo esc_attr((string) ((int) ($instance['interval'] ?? 4))); ?>">
|
||||
</label>
|
||||
</p>
|
||||
<p>
|
||||
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('blank')); ?>" value="1" <?php checked(!empty($instance['blank'])); ?>> <?php esc_html_e('链接新窗口', 'aksrt'); ?></label>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
|
||||
// 复制第一条实现无缝滚动
|
||||
$first_line = $lines[0];
|
||||
$first_parts = explode('|', $first_line, 2);
|
||||
$first_text = trim($first_parts[0]);
|
||||
$first_link = isset($first_parts[1]) ? trim($first_parts[1]) : '';
|
||||
echo '<li class="aksrt-announcement__item">';
|
||||
if ($first_link) {
|
||||
echo '<a href="' . esc_url($first_link) . '">' . esc_html($first_text) . '</a>';
|
||||
} else {
|
||||
echo esc_html($first_text);
|
||||
}
|
||||
echo '</li>';
|
||||
|
||||
echo '</ul>';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
|
||||
echo $args['after_widget'];
|
||||
}
|
||||
|
||||
public function form($instance): void {
|
||||
$title = !empty($instance['title']) ? $instance['title'] : '';
|
||||
$items = !empty($instance['items']) ? $instance['items'] : '';
|
||||
$icon = !empty($instance['icon']) ? $instance['icon'] : 'fas fa-bullhorn';
|
||||
$speed = !empty($instance['speed']) ? (int) $instance['speed'] : 10;
|
||||
?>
|
||||
<p>
|
||||
<label for="<?php echo esc_attr($this->get_field_id('title')); ?>"><?php esc_html_e('标题(可选):', 'aksrt'); ?></label>
|
||||
<input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr($title); ?>">
|
||||
</p>
|
||||
<p>
|
||||
<label for="<?php echo esc_attr($this->get_field_id('items')); ?>"><?php esc_html_e('公告内容(每行一条):', 'aksrt'); ?></label>
|
||||
<textarea class="widefat" id="<?php echo esc_attr($this->get_field_id('items')); ?>" name="<?php echo esc_attr($this->get_field_name('items')); ?>" rows="5" placeholder="系统维护通知 新功能上线|https://example.com 活动公告"><?php echo esc_textarea($items); ?></textarea>
|
||||
<small><?php esc_html_e('每行一条,格式:文本 或 文本|链接', 'aksrt'); ?></small>
|
||||
</p>
|
||||
<p>
|
||||
<label for="<?php echo esc_attr($this->get_field_id('icon')); ?>"><?php esc_html_e('图标:', 'aksrt'); ?></label>
|
||||
<input class="widefat" id="<?php echo esc_attr($this->get_field_id('icon')); ?>" name="<?php echo esc_attr($this->get_field_name('icon')); ?>" type="text" value="<?php echo esc_attr($icon); ?>">
|
||||
</p>
|
||||
<p>
|
||||
<label for="<?php echo esc_attr($this->get_field_id('speed')); ?>"><?php esc_html_e('滚动速度(秒):', 'aksrt'); ?></label>
|
||||
<input class="tiny-text" id="<?php echo esc_attr($this->get_field_id('speed')); ?>" name="<?php echo esc_attr($this->get_field_name('speed')); ?>" type="number" value="<?php echo esc_attr((string) $speed); ?>" min="5" max="30">
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
|
||||
public function update($new_instance, $old_instance): array {
|
||||
$instance = [];
|
||||
$instance['title'] = sanitize_text_field($new_instance['title'] ?? '');
|
||||
$instance['items'] = sanitize_textarea_field($new_instance['items'] ?? '');
|
||||
$instance['icon'] = sanitize_text_field($new_instance['icon'] ?? 'fas fa-bullhorn');
|
||||
$instance['speed'] = max(5, min(30, (int) ($new_instance['speed'] ?? 10)));
|
||||
return $instance;
|
||||
}
|
||||
/**
|
||||
* @param array<string,mixed> $new_instance
|
||||
* @param array<string,mixed> $old_instance
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public function update($new_instance, $old_instance): array {
|
||||
$mode = sanitize_key((string) ($new_instance['mode'] ?? 'swiper'));
|
||||
if (!in_array($mode, ['swiper', 'marquee'], true)) {
|
||||
$mode = 'swiper';
|
||||
}
|
||||
return [
|
||||
'title' => sanitize_text_field((string) ($new_instance['title'] ?? '')),
|
||||
'items' => sanitize_textarea_field((string) ($new_instance['items'] ?? '')),
|
||||
'icon' => sanitize_text_field((string) ($new_instance['icon'] ?? 'fas fa-bullhorn')),
|
||||
'speed' => max(5, min(30, (int) ($new_instance['speed'] ?? 10))),
|
||||
'mode' => $mode,
|
||||
'interval' => max(2, min(15, (int) ($new_instance['interval'] ?? 4))),
|
||||
'blank' => !empty($new_instance['blank']) ? 1 : 0,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,13 @@ class WidgetPartnersScroll extends \WP_Widget {
|
||||
public function widget($args, $instance): void {
|
||||
$partners = $this->resolve_partners($instance);
|
||||
if (!$partners) {
|
||||
if (current_user_can('manage_options')) {
|
||||
echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo function_exists('aksrt_get_widget_null')
|
||||
? aksrt_get_widget_null(__('暂无合作伙伴,请在模块中添加', 'aksrt')) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
: '<p class="widget-empty">' . esc_html__('暂无合作伙伴', 'aksrt') . '</p>';
|
||||
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -125,7 +132,7 @@ class WidgetPartnersScroll extends \WP_Widget {
|
||||
|
||||
$alt = esc_attr($title !== '' ? $title : __('合作伙伴', 'aksrt'));
|
||||
$img_tag = $image !== ''
|
||||
? '<img class="aksrt-ps-img" src="' . esc_url($image) . '" alt="' . $alt . '" loading="lazy" />'
|
||||
? '<img class="aksrt-ps-img aksrt-lazy lazyload" data-src="' . esc_url($image) . '" src="' . esc_url(get_template_directory_uri() . '/assets/img/placeholder.svg') . '" alt="' . $alt . '" loading="lazy" />'
|
||||
: '';
|
||||
|
||||
$inner = '';
|
||||
|
||||
Reference in new issue
Block a user