Adds option to set default search option #51
This commit is contained in:
parent
460e429a5a
commit
366629ca1e
|
@ -333,6 +333,7 @@ nav {
|
||||||
label {
|
label {
|
||||||
white-space: normal;
|
white-space: normal;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
input {
|
input {
|
||||||
margin-right: 0.5rem;
|
margin-right: 0.5rem;
|
||||||
}
|
}
|
||||||
|
|
|
@ -285,6 +285,7 @@ function tainacan_customize_register( $wp_customize ) {
|
||||||
$wp_customize->add_control( 'tainacan_hide_search_input', array(
|
$wp_customize->add_control( 'tainacan_hide_search_input', array(
|
||||||
'type' => 'checkbox',
|
'type' => 'checkbox',
|
||||||
'settings' => 'tainacan_hide_search_input',
|
'settings' => 'tainacan_hide_search_input',
|
||||||
|
'priority' => '1',
|
||||||
'section' => 'tainacan_header_search',
|
'section' => 'tainacan_header_search',
|
||||||
'label' => __( 'Hide search icon and input', 'tainacan-interface' )
|
'label' => __( 'Hide search icon and input', 'tainacan-interface' )
|
||||||
) );
|
) );
|
||||||
|
@ -304,7 +305,27 @@ function tainacan_customize_register( $wp_customize ) {
|
||||||
'settings' => 'tainacan_search_global_label',
|
'settings' => 'tainacan_search_global_label',
|
||||||
'section' => 'tainacan_header_search',
|
'section' => 'tainacan_header_search',
|
||||||
'label' => __( 'Label for "Global" search option', 'tainacan-interface' ),
|
'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
|
// 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
|
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' ) ) :
|
if ( ! function_exists( 'tainacan_get_footer_color_options' ) ) :
|
||||||
/**
|
/**
|
||||||
* Retrieves an array of options for footer color on Tainacan Theme.
|
* Retrieves an array of options for footer color on Tainacan Theme.
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
type="radio"
|
type="radio"
|
||||||
value="global"
|
value="global"
|
||||||
name="archive"
|
name="archive"
|
||||||
checked="checked"
|
<?php if (get_theme_mod('tainacan_search_default_option', 'global') == 'global') echo 'checked="checked"'; ?>
|
||||||
id="search-global">
|
id="search-global">
|
||||||
<?php echo esc_html( get_theme_mod('tainacan_search_global_label', __( 'Global', 'tainacan-interface' ) ) ); ?>
|
<?php echo esc_html( get_theme_mod('tainacan_search_global_label', __( 'Global', 'tainacan-interface' ) ) ); ?>
|
||||||
</label>
|
</label>
|
||||||
|
@ -26,6 +26,7 @@
|
||||||
type="radio"
|
type="radio"
|
||||||
value="posts"
|
value="posts"
|
||||||
name="archive"
|
name="archive"
|
||||||
|
<?php if (get_theme_mod('tainacan_search_default_option', 'global') == 'posts') echo 'checked="checked"'; ?>
|
||||||
id="search-on-posts">
|
id="search-on-posts">
|
||||||
<?php echo esc_html( get_theme_mod('tainacan_search_on_posts_label', __( 'Posts', 'tainacan-interface' ) ) ); ?>
|
<?php echo esc_html( get_theme_mod('tainacan_search_on_posts_label', __( 'Posts', 'tainacan-interface' ) ) ); ?>
|
||||||
</label>
|
</label>
|
||||||
|
@ -38,6 +39,7 @@
|
||||||
type="radio"
|
type="radio"
|
||||||
value="pages"
|
value="pages"
|
||||||
name="archive"
|
name="archive"
|
||||||
|
<?php if (get_theme_mod('tainacan_search_default_option', 'global') == 'pages') echo 'checked="checked"'; ?>
|
||||||
id="search-on-pages">
|
id="search-on-pages">
|
||||||
<?php echo esc_html( get_theme_mod('tainacan_search_on_pages_label', __( 'Pages', 'tainacan-interface' ) ) ); ?>
|
<?php echo esc_html( get_theme_mod('tainacan_search_on_pages_label', __( 'Pages', 'tainacan-interface' ) ) ); ?>
|
||||||
</label>
|
</label>
|
||||||
|
@ -50,6 +52,7 @@
|
||||||
type="radio"
|
type="radio"
|
||||||
value="tainacan-items"
|
value="tainacan-items"
|
||||||
name="archive"
|
name="archive"
|
||||||
|
<?php if (get_theme_mod('tainacan_search_default_option', 'global') == 'tainacan-items') echo 'checked="checked"'; ?>
|
||||||
id="search-on-items">
|
id="search-on-items">
|
||||||
<?php echo esc_html( get_theme_mod('tainacan_search_on_items_label', __( 'Items', 'tainacan-interface' ) ) ); ?>
|
<?php echo esc_html( get_theme_mod('tainacan_search_on_items_label', __( 'Items', 'tainacan-interface' ) ) ); ?>
|
||||||
</label>
|
</label>
|
||||||
|
@ -62,6 +65,7 @@
|
||||||
type="radio"
|
type="radio"
|
||||||
value="tainacan-collections"
|
value="tainacan-collections"
|
||||||
name="archive"
|
name="archive"
|
||||||
|
<?php if (get_theme_mod('tainacan_search_default_option', 'global') == 'tainacan-collections') echo 'checked="checked"'; ?>
|
||||||
id="search-on-collections">
|
id="search-on-collections">
|
||||||
<?php echo esc_html( get_theme_mod('tainacan_search_on_collections_label', __( 'Collections', 'tainacan-interface' ) ) ); ?>
|
<?php echo esc_html( get_theme_mod('tainacan_search_on_collections_label', __( 'Collections', 'tainacan-interface' ) ) ); ?>
|
||||||
</label>
|
</label>
|
||||||
|
|
Loading…
Reference in New Issue