' . $html . ''; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped wp_die(); } endif; if (!function_exists('aksrt_get_menu_search_panel_html')) : /** * Build inner search panel HTML (no outer dropdown wrapper). */ function aksrt_get_menu_search_panel_html(): string { $show_keywords = true; $show_history = true; $show_posts = true; if (class_exists('\AKSRT\Settings\Settings')) { $show_keywords = method_exists('\AKSRT\Settings\Settings', 'hot_search_enabled') ? (bool) \AKSRT\Settings\Settings::hot_search_enabled() : true; $show_history = method_exists('\AKSRT\Settings\Settings', 'search_history_enabled') ? (bool) \AKSRT\Settings\Settings::search_history_enabled() : true; $show_posts = method_exists('\AKSRT\Settings\Settings', 'search_posts_enabled') ? (bool) \AKSRT\Settings\Settings::search_posts_enabled() : !empty(\AKSRT\Settings\Settings::get_value('search_posts', true)); } $out = ''; // History (client may also fill via localStorage; server returns logged-in history). if ($show_history) { $hist = []; if (is_user_logged_in()) { $saved = get_user_meta(get_current_user_id(), 'aksrt_search_history', true); if (is_array($saved)) { foreach (array_slice($saved, 0, 10) as $item) { if (is_array($item) && !empty($item['keyword'])) { $hist[] = (string) $item['keyword']; } elseif (is_string($item) && $item !== '') { $hist[] = $item; } } } } $out .= '
'; $out .= '
' . esc_html__('搜索历史', 'aksrt') . ''; $out .= '' . esc_html__('清空', 'aksrt') . '
'; $out .= '
'; if ($hist) { foreach ($hist as $kw) { $out .= '' . esc_html($kw) . ' '; } } else { $out .= '' . esc_html__('暂无历史', 'aksrt') . ''; } $out .= '
'; } // Hot keywords. if ($show_keywords) { $hots = function_exists('aksrt_get_search_hot_keywords') ? aksrt_get_search_hot_keywords() : []; if ($hots) { $title = class_exists('\AKSRT\Settings\Settings') && method_exists('\AKSRT\Settings\Settings', 'search_popular_title') ? \AKSRT\Settings\Settings::search_popular_title() : __('热门搜索', 'aksrt'); $out .= '
'; $out .= '
' . esc_html($title) . '
'; $out .= '
'; } } // Latest / popular posts (optional). if ($show_posts) { $posts = get_posts([ 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => 6, 'ignore_sticky_posts' => true, 'no_found_rows' => true, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, ]); if ($posts) { $out .= '
'; $out .= '
' . esc_html__('推荐内容', 'aksrt') . '
'; $out .= '
'; foreach ($posts as $p) { $out .= ''; $out .= '' . esc_html(get_the_title($p)) . ''; $out .= '' . esc_html(get_the_date('', $p)) . ''; $out .= ''; } $out .= '
'; } } // Live suggestions mount point. $out .= ''; return $out; } endif; add_action('wp_ajax_aksrt_menu_search', 'aksrt_ajax_menu_search'); add_action('wp_ajax_nopriv_aksrt_menu_search', 'aksrt_ajax_menu_search'); // Alias for zibll-compatible remote-box query action name used in markup. add_action('wp_ajax_menu_search', 'aksrt_ajax_menu_search'); add_action('wp_ajax_nopriv_menu_search', 'aksrt_ajax_menu_search');