fix(frontend): restore missing search hot keywords renderer
Add aksrt_render_search_hot_keywords() used by header/search/404 panels to stop fatal undefined function on front-page.
This commit is contained in:
1 parent
2ead893923
commit
0ce257086c
2 files changed
+54
No files matched your search
@@ -567,6 +567,58 @@ function aksrt_get_search_hot_keywords(): array {
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_render_search_hot_keywords')):
|
||||
/**
|
||||
* Render hot search keyword chips.
|
||||
*
|
||||
* Used by header drawer, global search panel, search results, and 404.
|
||||
*
|
||||
* @param array<int,string>|null $keywords Optional preloaded keywords.
|
||||
* @param string $class Wrapper class name.
|
||||
*/
|
||||
function aksrt_render_search_hot_keywords($keywords = null, string $class = 'aksrt-search-hot-keywords'): void {
|
||||
if ($keywords === null) {
|
||||
$keywords = aksrt_get_search_hot_keywords();
|
||||
}
|
||||
if (!is_array($keywords)) {
|
||||
$keywords = [];
|
||||
}
|
||||
|
||||
$items = [];
|
||||
foreach ($keywords as $keyword) {
|
||||
$keyword = trim(sanitize_text_field((string) $keyword));
|
||||
if ($keyword !== '') {
|
||||
$items[] = $keyword;
|
||||
}
|
||||
}
|
||||
$items = array_values(array_unique($items));
|
||||
if ($items === []) {
|
||||
return;
|
||||
}
|
||||
|
||||
$class = trim(sanitize_html_class(str_replace(' ', '-', $class), 'aksrt-search-hot-keywords'));
|
||||
if ($class === '') {
|
||||
$class = 'aksrt-search-hot-keywords';
|
||||
}
|
||||
|
||||
$label = class_exists('AKSRT_Settings') && method_exists('AKSRT_Settings', 'search_popular_title')
|
||||
? (string) AKSRT_Settings::search_popular_title()
|
||||
: __('热门搜索', 'aksrt');
|
||||
if ($label === '') {
|
||||
$label = __('热门搜索', 'aksrt');
|
||||
}
|
||||
|
||||
echo '<div class="' . esc_attr($class) . '">';
|
||||
echo '<span class="' . esc_attr($class . '__label') . '">' . esc_html($label) . '</span>';
|
||||
echo '<div class="' . esc_attr($class . '__list') . '">';
|
||||
foreach ($items as $keyword) {
|
||||
$url = add_query_arg('s', rawurlencode($keyword), home_url('/'));
|
||||
echo '<a class="' . esc_attr($class . '__item') . '" href="' . esc_url($url) . '">' . esc_html($keyword) . '</a>';
|
||||
}
|
||||
echo '</div></div>';
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_search_history_enabled')):
|
||||
/**
|
||||
* 是否启用搜索历史
|
||||
|
||||
Reference in new issue
Block a user