Adds option to set default search option #51

This commit is contained in:
mateuswetah 2021-07-06 16:53:45 -03:00
parent 460e429a5a
commit 366629ca1e
3 changed files with 75 additions and 2 deletions

View File

@ -333,6 +333,7 @@ nav {
label {
white-space: normal;
display: flex;
align-items: center;
input {
margin-right: 0.5rem;
}

View File

@ -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.

View File

@ -15,7 +15,7 @@
type="radio"
value="global"
name="archive"
checked="checked"
<?php if (get_theme_mod('tainacan_search_default_option', 'global') == 'global') echo 'checked="checked"'; ?>
id="search-global">
<?php echo esc_html( get_theme_mod('tainacan_search_global_label', __( 'Global', 'tainacan-interface' ) ) ); ?>
</label>
@ -26,6 +26,7 @@
type="radio"
value="posts"
name="archive"
<?php if (get_theme_mod('tainacan_search_default_option', 'global') == 'posts') echo 'checked="checked"'; ?>
id="search-on-posts">
<?php echo esc_html( get_theme_mod('tainacan_search_on_posts_label', __( 'Posts', 'tainacan-interface' ) ) ); ?>
</label>
@ -38,6 +39,7 @@
type="radio"
value="pages"
name="archive"
<?php if (get_theme_mod('tainacan_search_default_option', 'global') == 'pages') echo 'checked="checked"'; ?>
id="search-on-pages">
<?php echo esc_html( get_theme_mod('tainacan_search_on_pages_label', __( 'Pages', 'tainacan-interface' ) ) ); ?>
</label>
@ -50,6 +52,7 @@
type="radio"
value="tainacan-items"
name="archive"
<?php if (get_theme_mod('tainacan_search_default_option', 'global') == 'tainacan-items') echo 'checked="checked"'; ?>
id="search-on-items">
<?php echo esc_html( get_theme_mod('tainacan_search_on_items_label', __( 'Items', 'tainacan-interface' ) ) ); ?>
</label>
@ -62,6 +65,7 @@
type="radio"
value="tainacan-collections"
name="archive"
<?php if (get_theme_mod('tainacan_search_default_option', 'global') == 'tainacan-collections') echo 'checked="checked"'; ?>
id="search-on-collections">
<?php echo esc_html( get_theme_mod('tainacan_search_on_collections_label', __( 'Collections', 'tainacan-interface' ) ) ); ?>
</label>