From 6766fb3e5129ce8c7f5623266827907b79b51d3c Mon Sep 17 00:00:00 2001 From: M_Viper Date: Sun, 16 Mar 2025 19:24:55 +0000 Subject: [PATCH] custom-search-plugin.php aktualisiert --- custom-search-plugin.php | 67 +++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 25 deletions(-) diff --git a/custom-search-plugin.php b/custom-search-plugin.php index b7142b1..0ce1645 100644 --- a/custom-search-plugin.php +++ b/custom-search-plugin.php @@ -14,11 +14,11 @@ * Tags: search Autor-search */ -if (!defined('ABSPATH')) { + if (!defined('ABSPATH')) { exit; // Sicherheitsmaßnahme } -// 1️⃣ **Aktualisiertes Suchformular mit Umschaltoption** +// 1️⃣ **Suchformular-Funktion mit integriertem CSS** function csp_search_form() { ob_start(); $search_type = isset($_GET['search_type']) ? sanitize_text_field($_GET['search_type']) : 'all'; @@ -28,7 +28,7 @@ function csp_search_form() { display: flex; flex-direction: column; gap: 8px; - max-width: 400px; + max-width: auto; margin: 10px auto; padding: 15px; background: #f8f9fa; @@ -108,7 +108,7 @@ function csp_search_form() { // 2️⃣ **Shortcode für das Suchformular** add_shortcode('custom_search', 'csp_search_form'); -// 3️⃣ **Aktualisiertes Suchfeld als Widget** +// 3️⃣ **Suchfeld als Widget** class CSP_Search_Widget extends WP_Widget { public function __construct() { parent::__construct( @@ -161,19 +161,19 @@ function csp_render_settings_page() { // 6️⃣ **Einstellungen registrieren** function csp_register_settings() { - register_setting('csp_settings_group', 'csp_selected_menu'); + register_setting('csp_settings_group', 'csp_shiftnav_position'); add_settings_section( 'csp_main_section', - 'Menu Selection', + 'ShiftNav Position', 'csp_section_callback', 'custom-search-settings' ); add_settings_field( - 'csp_menu_select', - 'Select Menu', - 'csp_menu_select_callback', + 'csp_shiftnav_position_select', + 'Select ShiftNav Position', + 'csp_shiftnav_position_select_callback', 'custom-search-settings', 'csp_main_section' ); @@ -182,31 +182,48 @@ add_action('admin_init', 'csp_register_settings'); // 7️⃣ **Callback für die Sektion** function csp_section_callback() { - echo 'Choose which menu to display the search form in:'; + echo 'Choose where to display the search form in ShiftNav:'; } // 8️⃣ **Callback für das Auswahlfeld** -function csp_menu_select_callback() { - $menus = wp_get_nav_menus(); - $selected_menu = get_option('csp_selected_menu'); +function csp_shiftnav_position_select_callback() { + $positions = array( + 'top' => 'Top of ShiftNav', + 'bottom' => 'Bottom of ShiftNav', + 'none' => 'Do not display in ShiftNav' + ); + $selected_position = get_option('csp_shiftnav_position', 'none'); - echo ''; + foreach ($positions as $value => $label) { + echo ''; } echo ''; } -// 9️⃣ **Suchfeld zum ausgewählten Menü hinzufügen** -function csp_add_search_to_menus($items, $args) { - $selected_menu = get_option('csp_selected_menu'); - if ($selected_menu && $args->menu->term_id == $selected_menu) { - $items .= ''; +// 9️⃣ **Funktion zum Einfügen des Suchformulars in ShiftNav** +function csp_insert_search_form_in_shiftnav($nav_menu, $args) { + // Überprüfen, ob es sich um das ShiftNav-Menü handelt + if ($args->theme_location !== 'shiftnav') { + return $nav_menu; } - return $items; + + $position = get_option('csp_shiftnav_position', 'none'); + if ($position === 'none') { + return $nav_menu; + } + + $search_form = ''; + + if ($position === 'top') { + return $search_form . $nav_menu; + } elseif ($position === 'bottom') { + return $nav_menu . $search_form; + } + + return $nav_menu; } -add_filter('wp_nav_menu_items', 'csp_add_search_to_menus', 10, 2); +add_filter('wp_nav_menu_items', 'csp_insert_search_form_in_shiftnav', 10, 2); // 🔟 **Aktualisierte Suchfunktion mit Suchtyp-Unterscheidung** function csp_custom_search_results($query) { @@ -305,4 +322,4 @@ function csp_guest_author_search_where($where, $query) { } add_filter('posts_where', 'csp_guest_author_search_where', 10, 2); -?> +?> \ No newline at end of file