diff --git a/src/assets/scss/style.scss b/src/assets/scss/style.scss index 5c8d1e9..210f52f 100644 --- a/src/assets/scss/style.scss +++ b/src/assets/scss/style.scss @@ -333,6 +333,7 @@ nav { label { white-space: normal; display: flex; + align-items: center; input { margin-right: 0.5rem; } diff --git a/src/functions/customizer.php b/src/functions/customizer.php index bf36e65..b9c6a70 100644 --- a/src/functions/customizer.php +++ b/src/functions/customizer.php @@ -285,6 +285,7 @@ function tainacan_customize_register( $wp_customize ) { $wp_customize->add_control( 'tainacan_hide_search_input', array( 'type' => 'checkbox', 'settings' => 'tainacan_hide_search_input', + 'priority' => '1', 'section' => 'tainacan_header_search', 'label' => __( 'Hide search icon and input', 'tainacan-interface' ) ) ); @@ -304,7 +305,27 @@ function tainacan_customize_register( $wp_customize ) { 'settings' => 'tainacan_search_global_label', 'section' => 'tainacan_header_search', 'label' => __( 'Label for "Global" search option', 'tainacan-interface' ), - 'description' => __( 'The Global search is the default. Its option will only be visible if at least one of the bellow are selected.', 'tainacan-interface') + 'description' => __( 'Includes all kinds of post types. This option will only be visible if at least one of the bellow are selected.', 'tainacan-interface') + ) ); + + /** + * Adds option to change the order of some page sections + */ + $wp_customize->add_setting( 'tainacan_search_default_option', array( + 'type' => 'theme_mod', + 'capability' => 'edit_theme_options', + 'default' => 'global', + 'transport' => 'refresh', + 'sanitize_callback' => 'tainacan_sanitize_search_options', + ) ); + $wp_customize->add_control( 'tainacan_search_default_option', array( + 'type' => 'select', + 'priority' => 9, // Within the section. + 'settings' => 'tainacan_search_default_option', + 'section' => 'tainacan_header_search', + 'label' => __( 'Default search option', 'tainacan-interface' ), + 'description' => __( 'This option will only be valid if at least one of the bellow are selected, otherwise the default search happens on WordPress posts.', 'tainacan-interface'), + 'choices' => tainacan_get_search_options() ) ); // Option to search directly on repository items list @@ -2077,6 +2098,53 @@ if ( ! function_exists( 'tainacan_sanitize_single_item_layout_sections_order' ) endif; // tainacan_sanitize_single_item_layout_sections_order +if ( ! function_exists( 'tainacan_get_search_options' ) ) : + /** + * Retrieves an array of options for the header search on Tainacan Theme. + * + * Create your own tainacan_get_search_options() function to override + * in a child theme. + * + * @since Tainacan Theme + * + * @return array $order - a string with slugs to the section order, separated by hiphen. + */ + function tainacan_get_search_options() { + $search_options = array( + 'global' => __('Global', 'tainacan-interface'), + 'posts' => __('Posts', 'tainacan-interface'), + 'pages' => __('Pages', 'tainacan-interface'), + 'tainacan-items' => __('Items', 'tainacan-interface'), + 'tainacan-collections' => __('Collections', 'tainacan-interface'), + ); + return $search_options; + } +endif; // tainacan_get_search_options + +if ( ! function_exists( 'tainacan_sanitize_search_options' ) ) : + /** + * Handles sanitization for Tainacan Theme search options + * + * Create your own tainacan_sanitize_search_options() function to override + * in a child theme. + * + * @since Tainacan Theme + * + * @param string $option - a string with slugs to the search option + * @return string the selected search option. + */ + function tainacan_sanitize_search_options( $option ) { + $search_options = tainacan_get_search_options(); + + if ( ! array_key_exists( $option, $search_options) ) { + return 'global'; + } + + return $option; + } +endif; // tainacan_sanitize_search_options + + if ( ! function_exists( 'tainacan_get_footer_color_options' ) ) : /** * Retrieves an array of options for footer color on Tainacan Theme. diff --git a/src/searchform.php b/src/searchform.php index f97305a..38bf8b7 100644 --- a/src/searchform.php +++ b/src/searchform.php @@ -15,7 +15,7 @@ type="radio" value="global" name="archive" - checked="checked" + id="search-global"> @@ -26,6 +26,7 @@ type="radio" value="posts" name="archive" + id="search-on-posts"> @@ -38,6 +39,7 @@ type="radio" value="pages" name="archive" + id="search-on-pages"> @@ -50,6 +52,7 @@ type="radio" value="tainacan-items" name="archive" + id="search-on-items"> @@ -62,6 +65,7 @@ type="radio" value="tainacan-collections" name="archive" + id="search-on-collections">