refactor(widgets): remove shared redundant settings

This commit is contained in:
kate522 committed 2026-08-16 15:03:49 +08:00
1 parent 30b08282f5
commit d97174dadb
31 files changed
+199 -1321

No files matched your search

+3 -28
View File
@@ -7,17 +7,15 @@
namespace AKSRT\Widgets;
use AKSRT\Widgets\Traits\CommonWidgetFields;
defined('ABSPATH') || exit;
class ButtonsWidget extends \WP_Widget {
use CommonWidgetFields;
public function __construct() {
parent::__construct('aksrt_buttons', esc_html__('AKSRT 按钮组', 'aksrt'), [
'description' => esc_html__('显示一组自定义按钮,支持外链跳转、色系与入场动画。', 'aksrt'),
'description' => esc_html__('显示一组自定义按钮,支持外链跳转与色系。', 'aksrt'),
'classname' => 'widget_aksrt_buttons',
]);
}
@@ -60,8 +58,6 @@ class ButtonsWidget extends \WP_Widget {
if (!in_array($m_pad, ['small', 'medium', 'large'], true)) {
$m_pad = 'medium';
}
$anim = sanitize_key((string) ($instance['obs_animation'] ?? ''));
$anim_repeat = !empty($instance['animation_repeat']);
$pc_width = max(0, min(400, (int) ($instance['pc_width'] ?? 0)));
$m_width = max(0, min(400, (int) ($instance['m_width'] ?? 0)));
@@ -74,7 +70,6 @@ class ButtonsWidget extends \WP_Widget {
}
$buts = '';
$key = 0;
foreach ($buttons as $btn) {
if (!is_array($btn)) {
continue;
@@ -122,19 +117,13 @@ class ButtonsWidget extends \WP_Widget {
$left_html = $icon_left !== '' ? '<i class="' . esc_attr($icon_left) . '" aria-hidden="true"></i> ' : '';
$right_html = $icon_right !== '' ? ' <span class="ml6"><i class="' . esc_attr($icon_right) . '" aria-hidden="true"></i></span>' : '';
$anim_pack = function_exists('aksrt_obs_animate_attrs')
? aksrt_obs_animate_attrs($anim, $anim_repeat, $key * 0.15)
: ['class' => '', 'attr' => ''];
$tgt = $target !== '' && strpos($url, 'javascript:') !== 0
? ' target="' . esc_attr($target) . '" rel="noopener noreferrer"'
: '';
$buts .= '<div class="' . esc_attr(trim($anim_pack['class'])) . '"' . $anim_pack['attr'] . '>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
$buts .= '<a class="' . esc_attr($item_class) . '" href="' . esc_url($url) . '"' . $tgt . '>'
$buts .= '<div><a class="' . esc_attr($item_class) . '" href="' . esc_url($url) . '"' . $tgt . '>'
. $left_html . esc_html($text) . $right_html . '</a>';
$buts .= '</div>';
$key++;
}
if ($buts === '') {
@@ -192,17 +181,6 @@ class ButtonsWidget extends \WP_Widget {
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('hollow')); ?>" value="1" <?php checked(!empty($instance['hollow'])); ?>> <?php esc_html_e('镂空', 'aksrt'); ?></label>
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('go_link')); ?>" value="1" <?php checked(!empty($instance['go_link'])); ?>> <?php esc_html_e('外链跳转页', 'aksrt'); ?></label>
</p>
<p>
<label><?php esc_html_e('入场动画', 'aksrt'); ?>
<select name="<?php echo esc_attr($this->get_field_name('obs_animation')); ?>">
<option value="" <?php selected(($instance['obs_animation'] ?? ''), ''); ?>><?php esc_html_e('无', 'aksrt'); ?></option>
<option value="fade" <?php selected(($instance['obs_animation'] ?? ''), 'fade'); ?>><?php esc_html_e('淡入', 'aksrt'); ?></option>
<option value="slideup" <?php selected(($instance['obs_animation'] ?? ''), 'slideup'); ?>><?php esc_html_e('上滑', 'aksrt'); ?></option>
<option value="slideright" <?php selected(($instance['obs_animation'] ?? ''), 'slideright'); ?>><?php esc_html_e('右滑', 'aksrt'); ?></option>
<option value="zoomin" <?php selected(($instance['obs_animation'] ?? ''), 'zoomin'); ?>><?php esc_html_e('放大', 'aksrt'); ?></option>
</select>
</label>
</p>
<?php foreach ($buttons as $i => $btn) : ?>
<div style="border:1px solid #ddd;padding:6px;margin-bottom:6px;border-radius:4px;">
<input class="widefat" type="text" name="<?php echo esc_attr($this->get_field_name("buttons[{$i}][text]")); ?>" value="<?php echo esc_attr((string) ($btn['text'] ?? '')); ?>" placeholder="<?php esc_attr_e('按钮文字', 'aksrt'); ?>">
@@ -217,7 +195,6 @@ class ButtonsWidget extends \WP_Widget {
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name("buttons[{$i}][new_window]")); ?>" value="1" <?php checked(!empty($btn['new_window'])); ?>> <?php esc_html_e('新窗口', 'aksrt'); ?></label>
</div>
<?php endforeach;
$this->render_common_form_section($instance);
}
/**
@@ -262,9 +239,7 @@ class ButtonsWidget extends \WP_Widget {
'm_padding' => in_array(($new_instance['m_padding'] ?? 'medium'), ['small', 'medium', 'large'], true) ? $new_instance['m_padding'] : 'medium',
'pc_width' => max(0, min(500, (int) ($new_instance['pc_width'] ?? 0))),
'm_width' => max(0, min(500, (int) ($new_instance['m_width'] ?? 0))),
'obs_animation' => sanitize_key((string) ($new_instance['obs_animation'] ?? '')),
'animation_repeat'=> !empty($new_instance['animation_repeat']) ? 1 : 0,
'buttons' => $buttons,
]; return $this->update_common_fields($new_instance, $old_instance, $business);
]; return $business;
}
}
+2 -12
View File
@@ -7,12 +7,10 @@
namespace AKSRT\Widgets;
use AKSRT\Widgets\Traits\CommonWidgetFields;
defined('ABSPATH') || exit;
class CategoriesWidget extends \WP_Widget {
use CommonWidgetFields;
public function __construct() {
parent::__construct(
@@ -179,14 +177,7 @@ class CategoriesWidget extends \WP_Widget {
if ($title !== '') {
echo $args['before_title'] . esc_html($title) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
$affix = function_exists('aksrt_widget_affix_attrs') ? aksrt_widget_affix_attrs($instance) : ['class' => '', 'attr' => ''];
if ($affix['class'] !== '') {
echo '<div class="is-affix"' . $affix['attr'] . '>';
}
echo self::render_html($instance); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
if ($affix['class'] !== '') {
echo '</div>';
}
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
@@ -241,7 +232,6 @@ class CategoriesWidget extends \WP_Widget {
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('hide_empty')); ?>" value="1" <?php checked(!isset($instance['hide_empty']) || !empty($instance['hide_empty'])); ?>> <?php esc_html_e('隐藏空分类', 'aksrt'); ?></label><br>
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('hierarchical')); ?>" value="1" <?php checked(!empty($instance['hierarchical'])); ?>> <?php esc_html_e('层级树', 'aksrt'); ?></label>
</p>
<?php $this->render_common_form_section($instance); ?>
<?php
}
@@ -255,7 +245,7 @@ class CategoriesWidget extends \WP_Widget {
if (!in_array($orderby, ['count', 'name', 'id', 'slug'], true)) {
$orderby = 'count';
}
return $this->update_common_fields($new_instance, $old_instance, [
return [
'title' => sanitize_text_field((string) ($new_instance['title'] ?? '')),
'count' => max(1, min(50, (int) ($new_instance['count'] ?? 8))),
'orderby' => $orderby,
@@ -268,6 +258,6 @@ class CategoriesWidget extends \WP_Widget {
'show_thumb' => !empty($new_instance['show_thumb']) ? 1 : 0,
'hide_empty' => !empty($new_instance['hide_empty']) ? 1 : 0,
'hierarchical' => !empty($new_instance['hierarchical']) ? 1 : 0,
]);
];
}
}
+1 -4
View File
@@ -5,7 +5,6 @@
namespace AKSRT\Widgets;
use AKSRT\Widgets\Traits\CommonWidgetFields;
defined('ABSPATH') || exit;
@@ -313,7 +312,6 @@ if (!function_exists('aksrt_home_widget_get_lazyload_args')) {
* Homepage category block widget.
*/
class CategoryBlockWidget extends \WP_Widget {
use CommonWidgetFields;
public function __construct() {
@@ -490,7 +488,6 @@ class CategoryBlockWidget extends \WP_Widget {
</p>
<?php if (function_exists('aksrt_widget_render_location_help')) { aksrt_widget_render_location_help('hybrid'); } ?>
<?php
$this->render_common_form_section($instance);
}
public function update($new_instance, $old_instance): array {
@@ -502,7 +499,7 @@ class CategoryBlockWidget extends \WP_Widget {
'layout' => aksrt_home_widget_resolve_layout($new_instance['layout'] ?? 'card', 'card'),
'show_more' => ! empty($new_instance['show_more']) ? 1 : 0,
'paginate' => in_array(sanitize_key((string) ($new_instance['paginate'] ?? 'none')), ['none', 'ajax', 'number'], true) ? sanitize_key((string) ($new_instance['paginate'] ?? 'none')) : 'none',
]; return $this->update_common_fields($new_instance, $old_instance, $business);
]; return $business;
}
public static function resolve_category_id_static(array $instance): int {
+1 -4
View File
@@ -5,7 +5,6 @@
namespace AKSRT\Widgets;
use AKSRT\Widgets\Traits\CommonWidgetFields;
defined('ABSPATH') || exit;
@@ -13,7 +12,6 @@ defined('ABSPATH') || exit;
* Homepage category recommend cards widget.
*/
class CategoryRecommendWidget extends \WP_Widget {
use CommonWidgetFields;
public function __construct() {
@@ -198,7 +196,6 @@ class CategoryRecommendWidget extends \WP_Widget {
</p>
<?php if (function_exists('aksrt_widget_render_location_help')) { aksrt_widget_render_location_help('homepage'); } ?>
<?php
$this->render_common_form_section($instance);
}
public function update($new_instance, $old_instance): array {
@@ -211,7 +208,7 @@ class CategoryRecommendWidget extends \WP_Widget {
'show_description' => ! empty($new_instance['show_description']) ? 1 : 0,
'show_dates' => ! empty($new_instance['show_dates']) ? 1 : 0,
'show_more' => ! empty($new_instance['show_more']) ? 1 : 0,
]; return $this->update_common_fields($new_instance, $old_instance, $business);
]; return $business;
}
/**
+1 -4
View File
@@ -5,7 +5,6 @@
namespace AKSRT\Widgets;
use AKSRT\Widgets\Traits\CommonWidgetFields;
defined('ABSPATH') || exit;
@@ -13,7 +12,6 @@ defined('ABSPATH') || exit;
* Homepage category tabs widget.
*/
class CategoryTabsWidget extends \WP_Widget {
use CommonWidgetFields;
public function __construct() {
@@ -161,7 +159,6 @@ public function form($instance): void {
</p>
<?php if (function_exists('aksrt_widget_render_location_help')) { aksrt_widget_render_location_help('hybrid'); } ?>
<?php
$this->render_common_form_section($instance);
}
public function update($new_instance, $old_instance): array {
@@ -172,7 +169,7 @@ public function form($instance): void {
'columns' => max(1, min(4, absint($new_instance['columns'] ?? 3))),
'layout' => aksrt_home_widget_resolve_layout($new_instance['layout'] ?? 'card', 'card'),
'show_more' => ! empty($new_instance['show_more']) ? 1 : 0,
]; return $this->update_common_fields($new_instance, $old_instance, $business);
]; return $business;
}
/**
+3 -8
View File
@@ -7,12 +7,10 @@
namespace AKSRT\Widgets;
use AKSRT\Widgets\Traits\CommonWidgetFields;
defined('ABSPATH') || exit;
class HotPostsWidget extends \WP_Widget {
use CommonWidgetFields;
public function __construct() {
parent::__construct(
@@ -209,12 +207,10 @@ class HotPostsWidget extends \WP_Widget {
if ($title) {
echo $args['before_title'] . esc_html($title) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
$affix = function_exists('aksrt_widget_affix_attrs') ? aksrt_widget_affix_attrs($instance) : ['class' => '', 'attr' => ''];
$instance['paginate'] = sanitize_key((string) ($instance['paginate'] ?? 'ajax'));
$payload = self::query_payload($instance, 1);
$rest = rest_url('aksrt/v1/widgets/hot-posts');
$wrap = 'ajaxpager' . $affix['class'];
echo '<div class="' . esc_attr($wrap) . '" data-aksrt-ajaxpager data-aksrt-ajax-url="' . esc_url($rest) . '"' . $affix['attr'] . '>';
echo '<div class="ajaxpager" data-aksrt-ajaxpager data-aksrt-ajax-url="' . esc_url($rest) . '">';
echo $payload['html']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $payload['paginate_html']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo '<div class="post_ajax_loader" data-aksrt-ajax-loader data-aksrt-ajax-loader-hide hidden></div>';
@@ -263,12 +259,11 @@ class HotPostsWidget extends \WP_Widget {
</select>
</label>
</p>
<?php $this->render_common_form_section($instance); ?>
<?php
}
public function update($new_instance, $old_instance): array {
return $this->update_common_fields($new_instance, $old_instance, [
return [
'title' => sanitize_text_field($new_instance['title'] ?? ''),
'count' => absint($new_instance['count'] ?? 5),
'order_by' => in_array($new_instance['order_by'] ?? '', ['views', 'comments', 'likes', 'favorites', 'downloads'], true) ? $new_instance['order_by'] : 'views',
@@ -276,6 +271,6 @@ class HotPostsWidget extends \WP_Widget {
'show_thumb' => !empty($new_instance['show_thumb']) ? 1 : 0,
'target_blank' => !empty($new_instance['target_blank']) ? 1 : 0,
'paginate' => in_array(sanitize_key((string) ($new_instance['paginate'] ?? 'ajax')), ['none', 'ajax', 'number'], true) ? sanitize_key((string) ($new_instance['paginate'] ?? 'ajax')) : 'ajax',
]);
];
}
}
+3 -17
View File
@@ -7,12 +7,10 @@
namespace AKSRT\Widgets;
use AKSRT\Widgets\Traits\CommonWidgetFields;
defined('ABSPATH') || exit;
class IconCardsWidget extends \WP_Widget {
use CommonWidgetFields;
public function __construct() {
@@ -45,8 +43,6 @@ class IconCardsWidget extends \WP_Widget {
$show_bg = !isset($instance['show_widget_bg']) || !empty($instance['show_widget_bg']);
$icon_size = max(0, min(64, (int) ($instance['icon_size'] ?? $instance['size'] ?? 0)));
$icon_radius = !empty($instance['icon_radius']);
$anim = sanitize_key((string) ($instance['obs_animation'] ?? ''));
$anim_repeat = !empty($instance['animation_repeat']);
echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
$title = apply_filters('widget_title', (string) ($instance['title'] ?? ''), $instance, $this->id_base);
@@ -64,7 +60,6 @@ class IconCardsWidget extends \WP_Widget {
echo '<div class="row gutters-5">';
}
$idx = 0;
foreach ($cards as $card) {
$url = (string) ($card['url'] ?? '');
if ($url !== '' && $go_link && function_exists('aksrt_go_link')) {
@@ -86,24 +81,17 @@ class IconCardsWidget extends \WP_Widget {
],
];
$anim_pack = function_exists('aksrt_obs_animate_attrs')
? aksrt_obs_animate_attrs($anim, $anim_repeat, $idx * 0.08)
: ['class' => '', 'attr' => ''];
if ($is_row) {
echo '<div class="' . esc_attr(trim($row_class . $anim_pack['class'])) . '"' . $anim_pack['attr'] . '>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
} elseif ($anim_pack['class'] !== '') {
echo '<div class="' . esc_attr(trim($anim_pack['class'])) . '"' . $anim_pack['attr'] . '>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo '<div class="' . esc_attr($row_class) . '">'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
if (function_exists('aksrt_icon_card')) {
echo aksrt_icon_card($card_args); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
if ($is_row || $anim_pack['class'] !== '') {
if ($is_row) {
echo '</div>';
}
$idx++;
}
if ($is_row) {
@@ -197,7 +185,6 @@ class IconCardsWidget extends \WP_Widget {
<input class="widefat" type="url" name="<?php echo esc_attr($this->get_field_name("cards[{$i}][url]")); ?>" value="<?php echo esc_attr((string) ($card['url'] ?? '')); ?>" placeholder="<?php esc_attr_e('链接', 'aksrt'); ?>">
</div>
<?php endforeach;
$this->render_common_form_section($instance);
}
/**
@@ -213,8 +200,7 @@ class IconCardsWidget extends \WP_Widget {
'go_link' => !empty($new_instance['go_link']) ? 1 : 0,
'show_widget_bg' => !empty($new_instance['show_widget_bg']) ? 1 : 0,
'icon_radius' => !empty($new_instance['icon_radius']) ? 1 : 0,
'obs_animation' => sanitize_key((string) ($new_instance['obs_animation'] ?? '')),
'cards' => $this->normalize($new_instance['cards'] ?? []),
]; return $this->update_common_fields($new_instance, $old_instance, $business);
]; return $business;
}
}
+3 -9
View File
@@ -7,12 +7,10 @@
namespace AKSRT\Widgets;
use AKSRT\Widgets\Traits\CommonWidgetFields;
defined('ABSPATH') || exit;
class NoticeWidget extends \WP_Widget {
use CommonWidgetFields;
public function __construct() {
parent::__construct('aksrt_notice', esc_html__('AKSRT 滚动公告', 'aksrt'), [
@@ -39,7 +37,6 @@ if (!$items) {
$radius = !empty($instance['radius']);
$interval = max(2, min(15, (int) ($instance['interval'] ?? 4)));
$align = sanitize_html_class((string) ($instance['alignment'] ?? ''));
$affix = function_exists('aksrt_widget_affix_attrs') ? aksrt_widget_affix_attrs($instance) : ['class' => '', 'attr' => ''];
echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
$title = apply_filters('widget_title', (string) ($instance['title'] ?? ''), $instance, $this->id_base);
@@ -54,9 +51,7 @@ if (!$items) {
if ($align !== '') {
$wrap_cls .= ' ' . $align;
}
$wrap_cls .= $affix['class'];
echo '<div class="' . esc_attr($wrap_cls) . '"' . $affix['attr'] . '>';
echo '<div class="' . esc_attr($wrap_cls) . '">';
echo '<div class="aksrt-scroll-notice__icon bulletin-icon"><i class="fas fa-bullhorn" aria-hidden="true"></i></div>';
// Prefer shared vertical new-swiper (zib_notice parity) via slider.js Type C.
@@ -194,12 +189,11 @@ if (!$items) {
<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><br>
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('radius')); ?>" value="1" <?php checked(!empty($instance['radius'])); ?>> <?php esc_html_e('两端圆形', 'aksrt'); ?></label>
</p>
<?php $this->render_common_form_section($instance); ?>
<?php
}
public function update($new_instance, $old_instance): array {
return $this->update_common_fields($new_instance, $old_instance, [
return [
'title' => sanitize_text_field((string) ($new_instance['title'] ?? '')),
'items' => $this->normalize_items(['items' => $new_instance['items'] ?? []]),
'interval' => max(2, min(15, (int) ($new_instance['interval'] ?? 4))),
@@ -207,6 +201,6 @@ if (!$items) {
'alignment' => sanitize_html_class((string) ($new_instance['alignment'] ?? '')),
'blank' => !empty($new_instance['blank']) ? 1 : 0,
'radius' => !empty($new_instance['radius']) ? 1 : 0,
]);
];
}
}
+2 -12
View File
@@ -7,12 +7,10 @@
namespace AKSRT\Widgets;
use AKSRT\Widgets\Traits\CommonWidgetFields;
defined('ABSPATH') || exit;
class RecentCommentsWidget extends \WP_Widget {
use CommonWidgetFields;
public function __construct() {
parent::__construct('aksrt_recent_comments', esc_html__('AKSRT 最新评论', 'aksrt'), [
@@ -162,14 +160,7 @@ class RecentCommentsWidget extends \WP_Widget {
if ($title !== '') {
echo $args['before_title'] . esc_html($title) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
$affix = function_exists('aksrt_widget_affix_attrs') ? aksrt_widget_affix_attrs($instance) : ['class' => '', 'attr' => ''];
if ($affix['class'] !== '') {
echo '<div class="is-affix"' . $affix['attr'] . '>';
}
echo self::render_html($instance); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
if ($affix['class'] !== '') {
echo '</div>';
}
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
@@ -202,7 +193,6 @@ class RecentCommentsWidget extends \WP_Widget {
</label>
<small><?php esc_html_e('填数字 ID 时按作者排除;填文字时按内容关键词排除(兼容旧配置)。', 'aksrt'); ?></small>
</p>
<?php $this->render_common_form_section($instance); ?>
<?php
}
@@ -212,13 +202,13 @@ class RecentCommentsWidget extends \WP_Widget {
* @return array<string,mixed>
*/
public function update($new_instance, $old_instance): array {
return $this->update_common_fields($new_instance, $old_instance, [
return [
'title' => sanitize_text_field((string) ($new_instance['title'] ?? '')),
'count' => max(1, min(50, (int) ($new_instance['count'] ?? 5))),
'show_avatar' => !empty($new_instance['show_avatar']) ? 1 : 0,
'outpost' => sanitize_text_field((string) ($new_instance['outpost'] ?? '')),
'outer' => sanitize_text_field((string) ($new_instance['outer'] ?? '')),
'outer_keywords' => sanitize_text_field((string) ($new_instance['outer_keywords'] ?? '')),
]);
];
}
}
+3 -8
View File
@@ -7,12 +7,10 @@
namespace AKSRT\Widgets;
use AKSRT\Widgets\Traits\CommonWidgetFields;
defined('ABSPATH') || exit;
class SearchWidget extends \WP_Widget {
use CommonWidgetFields;
public function __construct() {
parent::__construct('aksrt_search', esc_html__('AKSRT 搜索', 'aksrt'), [
@@ -35,9 +33,6 @@ class SearchWidget extends \WP_Widget {
$show_kw = !empty($instance['show_keywords']);
$kw_title = sanitize_text_field((string) ($instance['keywords_title'] ?? __('热门搜索', 'aksrt')));
$keyword_limit = max(1, min(50, (int) ($instance['keyword_limit'] ?? 12)));
// Affix helper (shared layer sidebar_affix).
$affix = function_exists('aksrt_widget_affix_attrs') ? aksrt_widget_affix_attrs($instance) : ['class' => '', 'attr' => ''];
$search_type = function_exists('aksrt_get_default_search_type')
? aksrt_get_default_search_type()
: 'post';
@@ -71,7 +66,7 @@ class SearchWidget extends \WP_Widget {
$uid = 'aksrt-sw-' . esc_attr($this->id);
?>
<div class="widget-search-box aksrt-search-widget search-input<?php echo $affix['class']; ?>" id="<?php echo $uid; ?>"<?php echo $affix['attr']; ?>>
<div class="widget-search-box aksrt-search-widget search-input" id="<?php echo $uid; ?>">
<form
role="search"
method="get"
@@ -169,13 +164,13 @@ class SearchWidget extends \WP_Widget {
}
public function update($new_instance, $old_instance): array {
return $this->update_common_fields($new_instance, $old_instance, [
return [
'title' => sanitize_text_field((string) ($new_instance['title'] ?? '')),
'placeholder' => sanitize_text_field((string) ($new_instance['placeholder'] ?? '')),
'show_keywords' => !empty($new_instance['show_keywords']) ? 1 : 0,
'keywords_title' => sanitize_text_field((string) ($new_instance['keywords_title'] ?? '')),
'keywords' => sanitize_textarea_field((string) ($new_instance['keywords'] ?? '')),
'keyword_limit' => max(1, min(50, (int) ($new_instance['keyword_limit'] ?? 12))),
]);
];
}
}
+1 -4
View File
@@ -7,12 +7,10 @@
namespace AKSRT\Widgets;
use AKSRT\Widgets\Traits\CommonWidgetFields;
defined('ABSPATH') || exit;
class TabPostsWidget extends \WP_Widget {
use CommonWidgetFields;
public function __construct() {
@@ -353,7 +351,6 @@ class TabPostsWidget extends \WP_Widget {
</p>
</div>
<?php endforeach;
$this->render_common_form_section($instance);
}
public function update($new_instance, $old_instance): array {
@@ -396,6 +393,6 @@ class TabPostsWidget extends \WP_Widget {
}
}
$result['tabs'] = !empty($tabs) ? $tabs : 'latest,comments,random';
return $this->update_common_fields($new_instance, $old_instance, $result);
return $result;
}
}
+2 -12
View File
@@ -7,12 +7,10 @@
namespace AKSRT\Widgets;
use AKSRT\Widgets\Traits\CommonWidgetFields;
defined('ABSPATH') || exit;
class TagCloudWidget extends \WP_Widget {
use CommonWidgetFields;
public function __construct() {
parent::__construct(
@@ -108,14 +106,7 @@ class TagCloudWidget extends \WP_Widget {
if ($title !== '') {
echo $args['before_title'] . esc_html($title) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
$affix = function_exists('aksrt_widget_affix_attrs') ? aksrt_widget_affix_attrs($instance) : ['class' => '', 'attr' => ''];
if ($affix['class'] !== '') {
echo '<div class="is-affix"' . $affix['attr'] . '>';
}
echo self::render_html($instance); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
if ($affix['class'] !== '') {
echo '</div>';
}
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
@@ -180,12 +171,11 @@ class TagCloudWidget extends \WP_Widget {
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('hide_empty')); ?>" value="1" <?php checked(!empty($instance['hide_empty'])); ?>> <?php esc_html_e('隐藏空标签', 'aksrt'); ?></label><br>
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('scale')); ?>" value="1" <?php checked(!empty($instance['scale'])); ?>> <?php esc_html_e('按数量缩放字号', 'aksrt'); ?></label>
</p>
<?php $this->render_common_form_section($instance); ?>
<?php
}
public function update($new_instance, $old_instance): array {
return $this->update_common_fields($new_instance, $old_instance, [
return [
'title' => sanitize_text_field((string) ($new_instance['title'] ?? '')),
'taxonomy' => sanitize_key((string) ($new_instance['taxonomy'] ?? 'post_tag')),
'count' => max(1, min(100, (int) ($new_instance['count'] ?? 20))),
@@ -197,6 +187,6 @@ class TagCloudWidget extends \WP_Widget {
'fixed_width' => !empty($new_instance['fixed_width']) ? 1 : 0,
'hide_empty' => !empty($new_instance['hide_empty']) ? 1 : 0,
'scale' => !empty($new_instance['scale']) ? 1 : 0,
]);
];
}
}
-73
View File
@@ -1,73 +0,0 @@
<?php
/**
* CommonWidgetFields trait — single seat-belt for shared widget form/update.
*
* Every AKSRT widget `use`s this trait so the Zibll common-field family
* (title block, display rules, affix, animation, layout bg) is declared and
* persisted in exactly one place: inc/modules/widget-common.php.
*
* Widgets keep only their business fields; the trait wires the shared section
* into form() and folds the shared keys into update().
*
* @package AKSRT\Widgets\Traits
*/
namespace AKSRT\Widgets\Traits;
defined('ABSPATH') || exit;
trait CommonWidgetFields {
/**
* Whether this widget should render the shared common-form section.
*
* Override and return false for pure-display widgets with no admin form.
* Default: true (every widget gets the shared block).
*
* @return bool
*/
protected function use_common_form(): bool {
return true;
}
/**
* Render the shared common-form section at the end of a widget's form().
*
* Call from form(): render business fields, then `$this->render_common_form_section($instance);`.
*
* @param array<string,mixed> $instance Widget instance.
*/
protected function render_common_form_section(array $instance): void {
if (!$this->use_common_form()) {
return;
}
if (function_exists('aksrt_widget_render_common_form')) {
aksrt_widget_render_common_form($instance);
}
}
/**
* Merge shared common fields into a widget's update() result.
*
* Usage in update():
* return $this->update_common_fields($new_instance, $old_instance, [
* 'title' => sanitize_text_field(...),
* ...business fields...
* ]);
*
* @param array<string,mixed> $new_instance New submitted instance.
* @param array<string,mixed> $old_instance Previous instance.
* @param array<string,mixed> $business Sanitized business fields to keep.
* @return array<string,mixed>
*/
protected function update_common_fields(array $new_instance, array $old_instance, array $business = []): array {
if (!$this->use_common_form()) {
return $business;
}
if (function_exists('aksrt_widget_update_common')) {
$common = aksrt_widget_update_common($new_instance, $old_instance);
return array_merge($business, $common);
}
return $business;
}
}
+1 -4
View File
@@ -7,12 +7,10 @@
namespace AKSRT\Widgets;
use AKSRT\Widgets\Traits\CommonWidgetFields;
defined('ABSPATH') || exit;
class WidgetAnnouncement extends \WP_Widget {
use CommonWidgetFields;
public function __construct() {
@@ -152,7 +150,6 @@ class WidgetAnnouncement extends \WP_Widget {
<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
$this->render_common_form_section($instance);
}
/**
@@ -173,6 +170,6 @@ class WidgetAnnouncement extends \WP_Widget {
'mode' => $mode,
'interval' => max(2, min(15, (int) ($new_instance['interval'] ?? 4))),
'blank' => !empty($new_instance['blank']) ? 1 : 0,
]; return $this->update_common_fields($new_instance, $old_instance, $business);
]; return $business;
}
}
+2 -24
View File
@@ -7,12 +7,10 @@
namespace AKSRT\Widgets;
use AKSRT\Widgets\Traits\CommonWidgetFields;
defined('ABSPATH') || exit;
class WidgetComboInfo extends \WP_Widget {
use CommonWidgetFields;
private const BANDS = ['blue', 'cyan', 'green', 'yellow', 'pink', 'purple'];
@@ -57,27 +55,20 @@ class WidgetComboInfo extends \WP_Widget {
$style = sprintf('--aksrt-zci-radius:%dpx;--aksrt-zci-band-h:%dpx;--aksrt-zci-pc:%d;--aksrt-zci-m:%d;--zci-radius:%dpx;--zci-band-h:%dpx;', $radius, $band_h, $pc_row, $m_row, $radius, $band_h);
$wrap = 'aksrt-combo-info zib-combo-info-card row gutters-10' . ($top_band ? ' has-band zci-has-band' : '');
$anim = sanitize_key((string) ($instance['obs_animation'] ?? ''));
$anim_repeat = !empty($instance['animation_repeat']);
$pc_span = max(1, (int) floor(12 / $pc_row));
$m_span = max(1, (int) floor(12 / $m_row));
$col = 'col-sm-' . $pc_span . ' col-xs-' . $m_span;
echo '<div class="' . esc_attr($wrap) . '" style="' . esc_attr($style) . '">';
$auto_idx = 0;
$ci = 0;
foreach ($cards as $card) {
$html = $this->render_card($card, $cta_default, $auto_idx, $go_link, $top_band);
if ($html === '') {
continue;
}
$pack = function_exists('aksrt_obs_animate_attrs')
? aksrt_obs_animate_attrs($anim, $anim_repeat, $ci * 0.1)
: ['class' => '', 'attr' => ''];
echo '<div class="' . esc_attr(trim($col . $pack['class'])) . '"' . $pack['attr'] . '>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo '<div class="' . esc_attr($col) . '">'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo '</div>';
$ci++;
}
echo '</div>';
@@ -243,18 +234,7 @@ class WidgetComboInfo extends \WP_Widget {
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('top_band')); ?>" value="1" <?php checked(!empty($instance['top_band']) || !isset($instance['top_band'])); ?>> <?php esc_html_e('顶部色带', 'aksrt'); ?></label><br>
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('go_link')); ?>" value="1" <?php checked(!empty($instance['go_link'])); ?>> <?php esc_html_e('外链跳转页', 'aksrt'); ?></label>
</p>
<p>
<label><?php esc_html_e('入场动画', 'aksrt'); ?>
<select name="<?php echo esc_attr($this->get_field_name('obs_animation')); ?>">
<option value="" <?php selected(($instance['obs_animation'] ?? ''), ''); ?>><?php esc_html_e('无', 'aksrt'); ?></option>
<option value="slideup" <?php selected(($instance['obs_animation'] ?? ''), 'slideup'); ?>><?php esc_html_e('上滑', 'aksrt'); ?></option>
<option value="fade" <?php selected(($instance['obs_animation'] ?? ''), 'fade'); ?>><?php esc_html_e('淡入', 'aksrt'); ?></option>
<option value="zoomin" <?php selected(($instance['obs_animation'] ?? ''), 'zoomin'); ?>><?php esc_html_e('放大', 'aksrt'); ?></option>
</select>
</label>
</p>
<?php
$this->render_common_form_section($instance);
}
public function update($new_instance, $old_instance): array {
@@ -268,8 +248,6 @@ class WidgetComboInfo extends \WP_Widget {
'top_band_height' => max(20, min(160, (int) ($new_instance['top_band_height'] ?? 70))),
'cta_text' => sanitize_text_field((string) ($new_instance['cta_text'] ?? '')),
'go_link' => !empty($new_instance['go_link']) ? 1 : 0,
'obs_animation' => sanitize_key((string) ($new_instance['obs_animation'] ?? '')),
'animation_repeat'=> !empty($new_instance['animation_repeat']) ? 1 : 0,
]; return $this->update_common_fields($new_instance, $old_instance, $business);
]; return $business;
}
}
+1 -4
View File
@@ -7,12 +7,10 @@
namespace AKSRT\Widgets;
use AKSRT\Widgets\Traits\CommonWidgetFields;
defined('ABSPATH') || exit;
class WidgetCoverCards extends \WP_Widget {
use CommonWidgetFields;
public function __construct() {
@@ -204,7 +202,6 @@ class WidgetCoverCards extends \WP_Widget {
<small><?php esc_html_e('字段: image, video, title, link, target, hide(pc|m), height, mask', 'aksrt'); ?></small>
</p>
<?php
$this->render_common_form_section($instance);
}
/**
@@ -225,6 +222,6 @@ class WidgetCoverCards extends \WP_Widget {
'font_bold' => !empty($new_instance['font_bold']) ? 1 : 0,
'font_color' => sanitize_hex_color((string) ($new_instance['font_color'] ?? '')) ?: '',
'items' => $this->normalize($new_instance['items'] ?? []),
]; return $this->update_common_fields($new_instance, $old_instance, $business);
]; return $business;
}
}
+1 -4
View File
@@ -7,12 +7,10 @@
namespace AKSRT\Widgets;
use AKSRT\Widgets\Traits\CommonWidgetFields;
defined('ABSPATH') || exit;
class WidgetIconCoverCards extends \WP_Widget {
use CommonWidgetFields;
public function __construct() {
@@ -187,7 +185,6 @@ class WidgetIconCoverCards extends \WP_Widget {
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('go_link')); ?>" value="1" <?php checked(!empty($instance['go_link'])); ?>> <?php esc_html_e('外链跳转页', 'aksrt'); ?></label>
</p>
<?php
$this->render_common_form_section($instance);
}
/**
@@ -205,6 +202,6 @@ class WidgetIconCoverCards extends \WP_Widget {
'icon_radius4' => !empty($new_instance['icon_radius4']) ? 1 : 0,
'show_widget_bg' => !empty($new_instance['show_widget_bg']) ? 1 : 0,
'go_link' => !empty($new_instance['go_link']) ? 1 : 0,
]; return $this->update_common_fields($new_instance, $old_instance, $business);
]; return $business;
}
}
+1 -4
View File
@@ -7,12 +7,10 @@
namespace AKSRT\Widgets;
use AKSRT\Widgets\Traits\CommonWidgetFields;
defined('ABSPATH') || exit;
class WidgetIframe extends \WP_Widget {
use CommonWidgetFields;
public function __construct() {
@@ -141,7 +139,6 @@ class WidgetIframe extends \WP_Widget {
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('allowfullscreen')); ?>" value="1" <?php checked(!empty($instance['allowfullscreen'])); ?>> <?php esc_html_e('允许全屏', 'aksrt'); ?></label>
</p>
<?php
$this->render_common_form_section($instance);
}
/**
@@ -155,6 +152,6 @@ class WidgetIframe extends \WP_Widget {
'url' => trim((string) ($new_instance['url'] ?? '')),
'aspect' => max(20, min(300, (int) ($new_instance['aspect'] ?? 55))),
'allowfullscreen' => !empty($new_instance['allowfullscreen']) ? 1 : 0,
]; return $this->update_common_fields($new_instance, $old_instance, $business);
]; return $business;
}
}
+3 -8
View File
@@ -7,12 +7,10 @@
namespace AKSRT\Widgets;
use AKSRT\Widgets\Traits\CommonWidgetFields;
defined('ABSPATH') || exit;
class WidgetMainPosts extends \WP_Widget {
use CommonWidgetFields;
public function __construct() {
parent::__construct(
@@ -331,13 +329,11 @@ class WidgetMainPosts extends \WP_Widget {
], static function ($v) {
return $v !== '' && $v !== null;
}));
$affix = function_exists('aksrt_widget_affix_attrs') ? aksrt_widget_affix_attrs($instance) : ['class' => '', 'attr' => ''];
$wrap_cls = 'aksrt-main-posts style-' . $style . ' ajaxpager';
if ($style === 'mini') {
$wrap_cls .= ' zib-widget posts-mini-lists';
}
$wrap_cls .= $affix['class'];
echo '<div class="' . esc_attr($wrap_cls) . '" data-aksrt-ajaxpager data-aksrt-ajax-url="' . esc_url($rest) . '" data-load-mode="' . esc_attr($load_mode) . '" data-query="' . esc_attr($qs) . '"' . ($load_mode === 'ajax' ? ' data-loaded="0"' : ' data-loaded="1"') . $affix['attr'] . '>';
echo '<div class="' . esc_attr($wrap_cls) . '" data-aksrt-ajaxpager data-aksrt-ajax-url="' . esc_url($rest) . '" data-load-mode="' . esc_attr($load_mode) . '" data-query="' . esc_attr($qs) . '"' . ($load_mode === 'ajax' ? ' data-loaded="0"' : ' data-loaded="1"') . '>';
if ($load_mode === 'ajax') {
// Skeleton first paint (zibll load_mode=ajax).
@@ -450,7 +446,6 @@ class WidgetMainPosts extends \WP_Widget {
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_meta')); ?>" value="1" <?php checked(!isset($instance['show_meta']) || !empty($instance['show_meta'])); ?>> <?php esc_html_e('显示 meta', 'aksrt'); ?></label><br>
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_number')); ?>" value="1" <?php checked(!empty($instance['show_number'])); ?>> <?php esc_html_e('显示序号', 'aksrt'); ?></label>
</p>
<?php $this->render_common_form_section($instance); ?>
<?php
}
@@ -467,7 +462,7 @@ class WidgetMainPosts extends \WP_Widget {
if (!in_array($paginate, ['none', 'ajax', 'number'], true)) {
$paginate = 'none';
}
return $this->update_common_fields($new_instance, $old_instance, [
return [
'title' => sanitize_text_field((string) ($new_instance['title'] ?? '')),
'count' => max(1, min(30, (int) ($new_instance['count'] ?? 6))),
'style' => $style,
@@ -482,6 +477,6 @@ class WidgetMainPosts extends \WP_Widget {
'show_thumb' => !empty($new_instance['show_thumb']) ? 1 : 0,
'show_meta' => !empty($new_instance['show_meta']) ? 1 : 0,
'show_number' => !empty($new_instance['show_number']) ? 1 : 0,
]);
];
}
}
+1 -4
View File
@@ -9,12 +9,10 @@
namespace AKSRT\Widgets;
use AKSRT\Widgets\Traits\CommonWidgetFields;
defined('ABSPATH') || exit;
class WidgetOnelinePosts extends \WP_Widget {
use CommonWidgetFields;
public function __construct() {
@@ -275,7 +273,6 @@ class WidgetOnelinePosts extends \WP_Widget {
</label>
</p>
<?php
$this->render_common_form_section($instance);
}
/**
@@ -302,6 +299,6 @@ class WidgetOnelinePosts extends \WP_Widget {
'limit_day' => max(0, (int) ($new_instance['limit_day'] ?? 0)),
'topics' => sanitize_text_field((string) ($new_instance['topics'] ?? '')),
'pay_type' => sanitize_key((string) ($new_instance['pay_type'] ?? '')),
]; return $this->update_common_fields($new_instance, $old_instance, $business);
]; return $business;
}
}
+1 -4
View File
@@ -7,12 +7,10 @@
namespace AKSRT\Widgets;
use AKSRT\Widgets\Traits\CommonWidgetFields;
defined('ABSPATH') || exit;
class WidgetPostPayBox extends \WP_Widget {
use CommonWidgetFields;
public function __construct() {
parent::__construct(
@@ -173,7 +171,6 @@ class WidgetPostPayBox extends \WP_Widget {
</select>
</label>
</p>
<?php $this->render_common_form_section($instance); ?>
<?php
}
@@ -184,6 +181,6 @@ class WidgetPostPayBox extends \WP_Widget {
$theme = 'jb-red';
}
return $this->update_common_fields($new_instance, $old_instance, ['theme' => $theme]);
return ['theme' => $theme];
}
}
+1 -4
View File
@@ -7,12 +7,10 @@
namespace AKSRT\Widgets;
use AKSRT\Widgets\Traits\CommonWidgetFields;
defined('ABSPATH') || exit;
class WidgetSlider extends \WP_Widget {
use CommonWidgetFields;
public function __construct() {
@@ -230,7 +228,6 @@ class WidgetSlider extends \WP_Widget {
<p class="description"><?php esc_html_e('使用主题共享 Swiper(.new-swiper)。图片 URL 必填;仅 1 张时不滑动。', 'aksrt'); ?></p>
<p class="description"><?php esc_html_e('对齐 Zibll 幻灯片:方向/效果/比例自动高度/间距/速度/自动播放/间隔。视频背景与图层视差由共享 Swiper 栈支持。', 'aksrt'); ?></p>
<?php
$this->render_common_form_section($instance);
}
public function update($new_instance, $old_instance): array {
@@ -260,7 +257,7 @@ class WidgetSlider extends \WP_Widget {
'autoplay' => !empty($new_instance['autoplay']) ? 1 : 0,
'blank' => !empty($new_instance['blank']) ? 1 : 0,
'slides' => $slides,
]; return $this->update_common_fields($new_instance, $old_instance, $business);
]; return $business;
}
/**
+1 -4
View File
@@ -7,12 +7,10 @@
namespace AKSRT\Widgets;
use AKSRT\Widgets\Traits\CommonWidgetFields;
defined('ABSPATH') || exit;
class WidgetTermAggregation extends \WP_Widget {
use CommonWidgetFields;
public function __construct() {
@@ -329,7 +327,6 @@ class WidgetTermAggregation extends \WP_Widget {
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('target_blank')); ?>" value="1" <?php checked(!empty($instance['target_blank'])); ?>> <?php esc_html_e('新窗口打开', 'aksrt'); ?></label>
</p>
<?php
$this->render_common_form_section($instance);
}
/**
@@ -352,6 +349,6 @@ class WidgetTermAggregation extends \WP_Widget {
'order' => strtoupper(sanitize_key((string) ($new_instance['order'] ?? 'desc'))) === 'ASC' ? 'ASC' : 'DESC',
'auto_terms' => max(1, min(4, (int) ($new_instance['auto_terms'] ?? 2))),
'target_blank' => !empty($new_instance['target_blank']) ? 1 : 0,
]; return $this->update_common_fields($new_instance, $old_instance, $business);
]; return $business;
}
}
+1 -4
View File
@@ -7,12 +7,10 @@
namespace AKSRT\Widgets;
use AKSRT\Widgets\Traits\CommonWidgetFields;
defined('ABSPATH') || exit;
class WidgetTermCards extends \WP_Widget {
use CommonWidgetFields;
public function __construct() {
@@ -275,7 +273,6 @@ class WidgetTermCards extends \WP_Widget {
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('target_blank')); ?>" value="1" <?php checked(!empty($instance['target_blank'])); ?>> <?php esc_html_e('新窗口打开', 'aksrt'); ?></label>
</p>
<?php
$this->render_common_form_section($instance);
}
/**
@@ -302,6 +299,6 @@ class WidgetTermCards extends \WP_Widget {
'include' => sanitize_text_field((string) ($new_instance['include'] ?? '')),
'hide_empty' => !empty($new_instance['hide_empty']) ? 1 : 0,
'target_blank' => !empty($new_instance['target_blank']) ? 1 : 0,
]; return $this->update_common_fields($new_instance, $old_instance, $business);
]; return $business;
}
}
+7 -54
View File
@@ -7,19 +7,17 @@
namespace AKSRT\Widgets;
use AKSRT\Widgets\Traits\CommonWidgetFields;
defined('ABSPATH') || exit;
class WidgetTextTitle extends \WP_Widget {
use CommonWidgetFields;
public function __construct() {
parent::__construct(
'aksrt_text_title',
esc_html__('AKSRT 文字标题', 'aksrt'),
[
'description' => esc_html__('自定义标题 + 副标题区块,支持逐字入场动画。', 'aksrt'),
'description' => esc_html__('自定义标题 + 副标题区块。', 'aksrt'),
'classname' => 'widget_aksrt_text_title',
]
);
@@ -53,8 +51,6 @@ class WidgetTextTitle extends \WP_Widget {
$desc_size = max(11, min(24, (int) ($instance['desc_size'] ?? 14)));
$title_color = sanitize_hex_color((string) ($instance['title_color'] ?? '')) ?: '';
$desc_color = sanitize_hex_color((string) ($instance['desc_color'] ?? '')) ?: '';
$anim = sanitize_key((string) ($instance['obs_animation'] ?? ''));
$anim_repeat = !empty($instance['animation_repeat']);
$icon_width = max(0, min(64, (int) ($instance['title_icon_width'] ?? 0)));
echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
@@ -75,45 +71,15 @@ class WidgetTextTitle extends \WP_Widget {
? '<span class="text-title-icon aksrt-text-title__icon ml6"' . $icon_w_attr . '><i class="' . esc_attr($icon_right) . '" aria-hidden="true"></i></span>'
: '';
$title_html = '';
if ($title !== '' && $anim !== '' && function_exists('aksrt_obs_animate_attrs')) {
// Split title into per-char spans with staggered delay (zibll).
$chars = preg_split('//u', $title, -1, PREG_SPLIT_NO_EMPTY) ?: [];
$pieces = [];
if ($left_html !== '') {
$pieces[] = $left_html;
}
foreach ($chars as $ch) {
$pieces[] = $ch;
}
if ($right_html !== '') {
$pieces[] = $right_html;
}
foreach ($pieces as $i => $piece) {
$pack = aksrt_obs_animate_attrs($anim, $anim_repeat, $i * 0.05);
$is_html = str_starts_with((string) $piece, '<');
$inner = $is_html ? $piece : esc_html((string) $piece);
$title_html .= '<span class="' . esc_attr(trim($pack['class'])) . '"' . $pack['attr']
. ' style="--delay:' . esc_attr((string) ($i * 0.05)) . 's;">' . $inner . '</span>';
}
} elseif ($title !== '') {
$title_html = $left_html . esc_html($title) . $right_html;
}
$title_html = $title !== '' ? $left_html . esc_html($title) . $right_html : '';
$desc_html = '';
if ($desc !== '') {
if ($anim !== '' && function_exists('aksrt_obs_animate_attrs')) {
$pack = aksrt_obs_animate_attrs($anim, $anim_repeat, 0.6);
$desc_html = '<div class="aksrt-text-title__desc' . esc_attr($pack['class']) . '"' . $pack['attr']
. ' style="--delay:.6s;">' . esc_html($desc) . '</div>';
} else {
$desc_html = '<div class="aksrt-text-title__desc">' . esc_html($desc) . '</div>';
}
$desc_html = '<div class="aksrt-text-title__desc">' . esc_html($desc) . '</div>';
}
$affix = function_exists('aksrt_widget_affix_attrs') ? aksrt_widget_affix_attrs($instance) : ['class' => '', 'attr' => ''];
$box = 'aksrt-text-title text-title align-' . esc_attr($align) . $affix['class'];
echo '<div class="' . esc_attr($box) . '" style="' . esc_attr($style) . '"' . $affix['attr'] . '>';
$box = 'aksrt-text-title text-title align-' . esc_attr($align);
echo '<div class="' . esc_attr($box) . '" style="' . esc_attr($style) . '">';
if ($title_html !== '') {
echo '<div class="aksrt-text-title__main">' . $title_html . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
@@ -165,16 +131,6 @@ class WidgetTextTitle extends \WP_Widget {
<input class="tiny-text" type="number" min="11" max="24" name="<?php echo esc_attr($this->get_field_name('desc_size')); ?>" value="<?php echo esc_attr((string) ((int) ($instance['desc_size'] ?? 14))); ?>">
</label>
</p>
<p>
<label><?php esc_html_e('入场动画', 'aksrt'); ?>
<select name="<?php echo esc_attr($this->get_field_name('obs_animation')); ?>">
<option value="" <?php selected(($instance['obs_animation'] ?? ''), ''); ?>><?php esc_html_e('无', 'aksrt'); ?></option>
<option value="fade" <?php selected(($instance['obs_animation'] ?? ''), 'fade'); ?>><?php esc_html_e('淡入', 'aksrt'); ?></option>
<option value="slideup" <?php selected(($instance['obs_animation'] ?? ''), 'slideup'); ?>><?php esc_html_e('上滑', 'aksrt'); ?></option>
<option value="zoomin" <?php selected(($instance['obs_animation'] ?? ''), 'zoomin'); ?>><?php esc_html_e('放大', 'aksrt'); ?></option>
</select>
</label>
</p>
<p>
<label><?php esc_html_e('标题色 #hex', 'aksrt'); ?>
<input class="widefat" type="text" name="<?php echo esc_attr($this->get_field_name('title_color')); ?>" value="<?php echo esc_attr((string) ($instance['title_color'] ?? '')); ?>">
@@ -185,7 +141,6 @@ class WidgetTextTitle extends \WP_Widget {
<input class="widefat" type="text" name="<?php echo esc_attr($this->get_field_name('desc_color')); ?>" value="<?php echo esc_attr((string) ($instance['desc_color'] ?? '')); ?>">
</label>
</p>
<?php $this->render_common_form_section($instance); ?>
<?php
}
@@ -195,7 +150,7 @@ class WidgetTextTitle extends \WP_Widget {
* @return array<string,mixed>
*/
public function update($new_instance, $old_instance): array {
return $this->update_common_fields($new_instance, $old_instance, [
return [
'title' => sanitize_text_field((string) ($new_instance['title'] ?? '')),
'desc' => sanitize_text_field((string) ($new_instance['desc'] ?? '')),
'align' => in_array(($new_instance['align'] ?? ''), ['left', 'center', 'right'], true) ? $new_instance['align'] : 'center',
@@ -205,9 +160,7 @@ class WidgetTextTitle extends \WP_Widget {
'desc_size' => max(11, min(24, (int) ($new_instance['desc_size'] ?? 14))),
'title_color' => sanitize_hex_color((string) ($new_instance['title_color'] ?? '')) ?: '',
'desc_color' => sanitize_hex_color((string) ($new_instance['desc_color'] ?? '')) ?: '',
'obs_animation' => sanitize_key((string) ($new_instance['obs_animation'] ?? '')),
'animation_repeat' => !empty($new_instance['animation_repeat']) ? 1 : 0,
'title_icon_width' => max(0, min(64, (int) ($new_instance['title_icon_width'] ?? 0))),
]);
];
}
}
-14
View File
@@ -28,7 +28,6 @@ class WidgetUserCard extends \WP_Widget {
$show_stats = !empty($instance['show_stats']) || !isset($instance['show_stats']);
$show_actions = !empty($instance['show_button']) || !isset($instance['show_button']);
$show_checkin = !empty($instance['show_checkin']) || !isset($instance['show_checkin']);
$affix = function_exists('aksrt_widget_affix_attrs') ? aksrt_widget_affix_attrs($instance) : ['class' => '', 'attr' => ''];
$loged_title = (string) ($instance['loged_title'] ?? __('Hi!请登录', 'aksrt'));
$btn1_text = (string) ($instance['button_1_text'] ?? __('发布文章', 'aksrt'));
$btn2_text = (string) ($instance['button_2_text'] ?? __('用户中心', 'aksrt'));
@@ -49,24 +48,14 @@ class WidgetUserCard extends \WP_Widget {
if ($title !== '') {
echo $args['before_title'] . esc_html($title) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
if ($affix['class'] !== '') {
echo '<div class="is-affix"' . $affix['attr'] . '>';
}
if ($user_id <= 0) {
$this->render_guest($show_cover, $loged_title, $this->get_guest_cover_url($instance));
if ($affix['class'] !== '') {
echo '</div>';
}
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
return;
}
$user = get_userdata($user_id);
if (!$user) {
if ($affix['class'] !== '') {
echo '</div>';
}
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
return;
}
@@ -148,9 +137,6 @@ class WidgetUserCard extends \WP_Widget {
echo '</div></div>';
if ($affix['class'] !== '') {
echo '</div>';
}
echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
+1 -4
View File
@@ -7,12 +7,10 @@
namespace AKSRT\Widgets;
use AKSRT\Widgets\Traits\CommonWidgetFields;
defined('ABSPATH') || exit;
class WidgetVideoPlayer extends \WP_Widget {
use CommonWidgetFields;
public function __construct() {
@@ -134,7 +132,6 @@ class WidgetVideoPlayer extends \WP_Widget {
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('hide_controller')); ?>" value="1" <?php checked(!empty($instance['hide_controller'])); ?>> <?php esc_html_e('隐藏控制条样式', 'aksrt'); ?></label>
</p>
<?php
$this->render_common_form_section($instance);
}
public function update($new_instance, $old_instance): array {
@@ -148,6 +145,6 @@ class WidgetVideoPlayer extends \WP_Widget {
'loop' => !empty($new_instance['loop']) ? 1 : 0,
'muted' => !empty($new_instance['muted']) ? 1 : 0,
'hide_controller' => !empty($new_instance['hide_controller']) ? 1 : 0,
]; return $this->update_common_fields($new_instance, $old_instance, $business);
]; return $business;
}
}
+3 -29
View File
@@ -7,12 +7,10 @@
namespace AKSRT\Widgets;
use AKSRT\Widgets\Traits\CommonWidgetFields;
defined('ABSPATH') || exit;
class WidgetYiyan extends \WP_Widget {
use CommonWidgetFields;
/**
* @return array<string,string>
@@ -61,9 +59,6 @@ class WidgetYiyan extends \WP_Widget {
$interval = !empty($instance['interval']) ? max(3, min(30, (int) $instance['interval'])) : 5;
$type = self::sanitize_type((string) ($instance['type'] ?? ''));
$icon = !empty($instance['icon']) ? (string) $instance['icon'] : 'fas fa-quote-left';
$affix = function_exists('aksrt_widget_affix_attrs') ? aksrt_widget_affix_attrs($instance) : ['class' => '', 'attr' => ''];
$anim = sanitize_key((string) ($instance['obs_animation'] ?? ''));
$anim_repeat = !empty($instance['animation_repeat']);
echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
@@ -72,15 +67,7 @@ class WidgetYiyan extends \WP_Widget {
}
// zibll shell: theme-box + yiyan-box main-bg text-center box-body radius8 main-shadow.
// NOTE: obs_animation is this widget's own per-widget animation business
// field (kept as-is); the shared common `animation_in` field added via
// render_common_form_section() is a separate additional control.
$pack = function_exists('aksrt_obs_animate_attrs')
? aksrt_obs_animate_attrs($anim, $anim_repeat, 0)
: ['class' => '', 'attr' => ''];
$box_class = 'theme-box yiyan-box-wrap' . $pack['class'];
echo '<div' . $affix['attr'] . ' class="' . esc_attr(trim($box_class)) . '"' . $pack['attr'] . '>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo '<div class="theme-box yiyan-box-wrap">';
echo '<div class="yiyan-box main-bg text-center box-body radius8 main-shadow">';
if (function_exists('aksrt_render_yiyan_block')) {
@@ -160,17 +147,6 @@ class WidgetYiyan extends \WP_Widget {
name="<?php echo esc_attr($this->get_field_name('icon')); ?>" type="text"
value="<?php echo esc_attr($icon); ?>">
</p>
<p>
<label><?php esc_html_e('入场动画', 'aksrt'); ?>
<select name="<?php echo esc_attr($this->get_field_name('obs_animation')); ?>">
<option value="" <?php selected(($instance['obs_animation'] ?? ''), ''); ?>><?php esc_html_e('无', 'aksrt'); ?></option>
<option value="fade" <?php selected(($instance['obs_animation'] ?? ''), 'fade'); ?>><?php esc_html_e('淡入', 'aksrt'); ?></option>
<option value="slideup" <?php selected(($instance['obs_animation'] ?? ''), 'slideup'); ?>><?php esc_html_e('上滑', 'aksrt'); ?></option>
<option value="zoomin" <?php selected(($instance['obs_animation'] ?? ''), 'zoomin'); ?>><?php esc_html_e('放大', 'aksrt'); ?></option>
</select>
</label>
</p>
<?php $this->render_common_form_section($instance); ?>
<?php
}
@@ -180,14 +156,12 @@ class WidgetYiyan extends \WP_Widget {
* @return array<string,mixed>
*/
public function update($new_instance, $old_instance): array {
return $this->update_common_fields($new_instance, $old_instance, [
return [
'title' => sanitize_text_field((string) ($new_instance['title'] ?? '')),
'count' => max(1, min(10, absint($new_instance['count'] ?? 5))),
'interval' => max(3, min(30, absint($new_instance['interval'] ?? 5))),
'type' => self::sanitize_type((string) ($new_instance['type'] ?? '')),
'icon' => sanitize_text_field((string) ($new_instance['icon'] ?? 'fas fa-quote-left')),
'obs_animation' => sanitize_key((string) ($new_instance['obs_animation'] ?? '')),
'animation_repeat' => !empty($new_instance['animation_repeat']) ? 1 : 0,
]);
];
}
}