Files
wordpress-theme-aksrt/inc/helpers/header/aksrt-header-menu-search.php
T
kate522 1d1fef50af feat(nav): deep 1:1 zibll search-box + navbar-search + newposts unify
Port aksrt_get_search_box/posts for menu_search and layout 1/3 slide;
unify publish switch; expand user-box admin row; CSS/JS remote-box parity.
2026-07-22 17:06:24 +08:00

82 lines
2.6 KiB
PHP

<?php
/**
* Layout-2 menu search remote panel (zibll menu_search / zib_get_search_box).
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
if (!function_exists('aksrt_ajax_menu_search')) :
/**
* AJAX: HTML panel for navbar inline search (history + hot + posts).
*/
function aksrt_ajax_menu_search(): void {
// Prefer public nonce; also accept no nonce for same-origin remote-box first paint like zibll.
if (!empty($_REQUEST['nonce'])) {
$nonce = sanitize_text_field(wp_unslash((string) $_REQUEST['nonce']));
if (!wp_verify_nonce($nonce, 'aksrt_public_nonce')) {
wp_die('0');
}
}
if (!function_exists('aksrt_get_search_box')) {
wp_die('0');
}
$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));
}
$search = aksrt_get_search_box([
'show_form' => false,
'show_keywords' => $show_keywords,
'show_history' => $show_history,
'show_posts' => $show_posts,
]);
if ($search === '' || $search === null) {
wp_die('0');
}
// zibll contract: outer dropdown + inner .search-input.
echo '<div class="dropdown-menu hover-show-con">' . $search . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
wp_die();
}
endif;
// Panel builder retained as thin alias for any external callers.
if (!function_exists('aksrt_get_menu_search_panel_html')) :
/**
* @return string Inner HTML (without dropdown wrapper).
*/
function aksrt_get_menu_search_panel_html(): string {
if (!function_exists('aksrt_get_search_box')) {
return '';
}
return (string) aksrt_get_search_box([
'show_form' => false,
'show_keywords' => true,
'show_history' => true,
'show_posts' => true,
]);
}
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');