refactor(widget): remove search history display

This commit is contained in:
kate522 committed 2026-08-15 17:15:27 +08:00
1 parent 389ab4f19a
commit 7127f4c3a8
3 files changed
+4 -220

No files matched your search

+3 -36
View File
@@ -1,6 +1,6 @@
<?php
/**
* Search box with hot keywords and search history.
* Search box with hot keywords.
*
* @package AKSRT
*/
@@ -16,7 +16,7 @@ class SearchWidget extends \WP_Widget {
public function __construct() {
parent::__construct('aksrt_search', esc_html__('AKSRT 搜索', 'aksrt'), [
'description' => esc_html__('搜索框:热门关键词与搜索历史。', 'aksrt'),
'description' => esc_html__('搜索框:热门关键词。', 'aksrt'),
'classname' => 'widget_aksrt_search',
]);
}
@@ -33,19 +33,14 @@ class SearchWidget extends \WP_Widget {
$placeholder = aksrt_get_search_placeholder();
}
$show_kw = !empty($instance['show_keywords']);
$show_history = !empty($instance['show_history']);
$kw_title = sanitize_text_field((string) ($instance['keywords_title'] ?? __('热门搜索', 'aksrt')));
$keyword_limit = max(1, min(50, (int) ($instance['keyword_limit'] ?? 12)));
$history_limit = max(1, min(8, (int) ($instance['history_limit'] ?? 8)));
// 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';
$history_enabled = function_exists('aksrt_search_history_enabled')
? aksrt_search_history_enabled()
: true;
$keywords = [];
if ($show_kw) {
@@ -96,30 +91,10 @@ class SearchWidget extends \WP_Widget {
placeholder="<?php echo esc_attr($placeholder); ?>"
value="<?php echo esc_attr(get_search_query()); ?>"
autocomplete="off"
aria-haspopup="true"
aria-controls="<?php echo $uid; ?>-history"
aria-expanded="false"
>
<button type="submit" class="widget-search-box__btn" aria-label="<?php esc_attr_e('搜索', 'aksrt'); ?>">
<i class="fas fa-search" aria-hidden="true"></i>
</button>
<?php if ($show_history && $history_enabled) : ?>
<div
id="<?php echo $uid; ?>-history"
class="aksrt-search-widget__history"
data-aksrt-search-history
data-history-limit="<?php echo esc_attr((string) $history_limit); ?>"
role="region"
aria-label="<?php esc_attr_e('搜索历史', 'aksrt'); ?>"
hidden
>
<div class="aksrt-search-widget__kw-head">
<div class="aksrt-search-widget__kw-title"><?php esc_html_e('搜索历史', 'aksrt'); ?></div>
<button type="button" class="aksrt-search-widget__history-clear" data-aksrt-search-history-clear hidden><?php esc_html_e('清空', 'aksrt'); ?></button>
</div>
<div class="aksrt-search-widget__history-list" data-aksrt-search-history-list role="list"></div>
</div>
<?php endif; ?>
</div>
</div>
@@ -173,8 +148,7 @@ class SearchWidget extends \WP_Widget {
</label>
</p>
<p>
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_keywords')); ?>" value="1" <?php checked(!empty($instance['show_keywords'])); ?>> <?php esc_html_e('显示热门关键词', 'aksrt'); ?></label><br>
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_history')); ?>" value="1" <?php checked(!empty($instance['show_history'])); ?>> <?php esc_html_e('显示搜索历史', 'aksrt'); ?></label>
<label><input type="checkbox" name="<?php echo esc_attr($this->get_field_name('show_keywords')); ?>" value="1" <?php checked(!empty($instance['show_keywords'])); ?>> <?php esc_html_e('显示热门关键词', 'aksrt'); ?></label>
</p>
<p>
<label><?php esc_html_e('关键词标题', 'aksrt'); ?>
@@ -191,11 +165,6 @@ class SearchWidget extends \WP_Widget {
<input class="tiny-text" type="number" min="1" max="50" name="<?php echo esc_attr($this->get_field_name('keyword_limit')); ?>" value="<?php echo esc_attr((string) max(1, min(50, (int) ($instance['keyword_limit'] ?? 12)))); ?>">
</label>
</p>
<p>
<label><?php esc_html_e('搜索历史最多显示数量', 'aksrt'); ?>
<input class="tiny-text" type="number" min="1" max="8" name="<?php echo esc_attr($this->get_field_name('history_limit')); ?>" value="<?php echo esc_attr((string) max(1, min(8, (int) ($instance['history_limit'] ?? 8)))); ?>">
</label>
</p>
<?php
}
@@ -204,11 +173,9 @@ class SearchWidget extends \WP_Widget {
'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,
'show_history' => !empty($new_instance['show_history']) ? 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))),
'history_limit' => max(1, min(8, (int) ($new_instance['history_limit'] ?? 8))),
]);
}
}