refactor(widgets): remove shared redundant settings
This commit is contained in:
@@ -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,
|
||||
]);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user