Fixes global search and adds options to the customizer.

This commit is contained in:
mateuswetah 2020-08-13 16:41:38 -03:00
parent a195beb6e5
commit b224b3b0b4
9 changed files with 103 additions and 45 deletions

View File

@ -2,7 +2,7 @@ function onTainacanSearchSubmit($event) {
if (document['tainacan-search-form']) {
if (document['tainacan-search-form'].archive && defined ( 'TAINACAN_VERSION' )) {
if (document['tainacan-search-form'].archive && tainacan_plugin !== undefined) {
switch (document['tainacan-search-form'].archive.value) {
case 'tainacan-items':
document['tainacan-search-form'].action = tainacan_plugin.theme_items_list_url + (document['tainacan-search-form'].s ? '?search=' + document['tainacan-search-form'].s.value : '');
@ -10,6 +10,9 @@ function onTainacanSearchSubmit($event) {
case 'tainacan-collections':
document['tainacan-search-form'].action = tainacan_plugin.theme_collection_list_url + (document['tainacan-search-form'].s ? '?s=' + document['tainacan-search-form'].s.value : '');
break;
case 'everywhere':
document['tainacan-search-form'].action = '/' + (document['tainacan-search-form'].s ? '?everywhere=true&s=' + document['tainacan-search-form'].s.value : '');
break;
case 'posts':
default:
document['tainacan-search-form'].action = '/' + (document['tainacan-search-form'].s ? '?s=' + document['tainacan-search-form'].s.value : '');

View File

@ -303,7 +303,7 @@ nav{
background: white;
padding: 0rem;
align-items: center;
height: 2.75rem;
height: 2.5rem;
}
.form-control {
height: 100%;

View File

@ -191,9 +191,14 @@ add_action( 'admin_head', 'tainacan_customize_editor_css');
* @param object $query The main WordPress query.
*/
function tainacan_include_items_in_search_results( $query ) {
if ( $query->is_main_query() && $query->is_search() && ! is_admin()) {
if ( $_GET['everywhere'] && $query->is_main_query() && $query->is_search() && ! is_admin()) {
$collections_post_types = \Tainacan\Repositories\Repository::get_collections_db_identifiers();
$query->set( 'post_type', array_merge( ['post', 'tainacan-collection'], $collections_post_types ) );
$existing_post_types = $query->get( 'post_type' );
if ( !is_array($existing_post_types) )
$existing_post_types = [ $existing_post_types ];
$query->set( 'post_type', array_merge( $existing_post_types, ['post', 'tainacan-collection'], $collections_post_types ) );
}
}
add_action( 'pre_get_posts', 'tainacan_include_items_in_search_results' );

View File

@ -109,8 +109,8 @@ function tainacan_customize_register( $wp_customize ) {
/**
* Header settings
*/
$wp_customize->add_section('tainacan_header_settings', array(
'title' => __( 'Header settings', 'tainacan-interface' ),
$wp_customize->add_section('tainacan_header_search', array(
'title' => __( 'Header search', 'tainacan-interface' ),
'priority' => 61,
));
@ -124,23 +124,51 @@ function tainacan_customize_register( $wp_customize ) {
$wp_customize->add_control( 'tainacan_hide_search_input', array(
'type' => 'checkbox',
'settings' => 'tainacan_hide_search_input',
'section' => 'tainacan_header_settings',
'section' => 'tainacan_header_search',
'label' => __( 'Hide search icon and input', 'tainacan-interface' )
) );
// Includes tainacan itens on search results
$wp_customize->add_setting( 'tainacan_search_include_items', array(
// Option to search directly on repository items list
$wp_customize->add_setting( 'tainacan_search_on_items', array(
'type' => 'theme_mod',
'default' => false,
'capability' => 'edit_theme_options',
'sanitize_callback' => 'tainacan_callback_sanitize_checkbox',
) );
$wp_customize->add_control( 'tainacan_search_include_items', array(
$wp_customize->add_control( 'tainacan_search_on_items', array(
'type' => 'checkbox',
'settings' => 'tainacan_search_include_items',
'section' => 'tainacan_header_settings',
'label' => __( 'Include tainacan itens on the search results list', 'tainacan-interface' ),
'description' => __( 'Toggle to include tainacan itens on the search results list. By default it only lists WordPress Posts and Pages. The items will be displayed with the same appearence of posts, with their title, thumbnail and description.', 'tainacan-interface' )
'settings' => 'tainacan_search_on_items',
'section' => 'tainacan_header_search',
'label' => __( 'Display option to search on tainacan items repository list', 'tainacan-interface' )
) );
// Option to search directly on collections list
$wp_customize->add_setting( 'tainacan_search_on_collections', array(
'type' => 'theme_mod',
'default' => false,
'capability' => 'edit_theme_options',
'sanitize_callback' => 'tainacan_callback_sanitize_checkbox',
) );
$wp_customize->add_control( 'tainacan_search_on_collections', array(
'type' => 'checkbox',
'settings' => 'tainacan_search_on_collections',
'section' => 'tainacan_header_search',
'label' => __( 'Display option to search on tainacan collections list', 'tainacan-interface' )
) );
// Option to search globally posts, iem and collections
$wp_customize->add_setting( 'tainacan_search_global', array(
'type' => 'theme_mod',
'default' => false,
'capability' => 'edit_theme_options',
'sanitize_callback' => 'tainacan_callback_sanitize_checkbox',
) );
$wp_customize->add_control( 'tainacan_search_global', array(
'type' => 'checkbox',
'settings' => 'tainacan_search_global',
'section' => 'tainacan_header_search',
'label' => __( 'Display option to search globally on items, collections and posts', 'tainacan-interface' ),
'description'=> __( 'By searching via this mode, the list result will include posts, items and collecitions. You wil be able do distinguish them by a tag next to the title.', 'tainacan-interface' )
) );
/**

View File

@ -58,7 +58,8 @@ if ( ! function_exists( 'tainacan_enqueues' ) ) {
wp_register_script( 'tainacan_tainacanJS', get_template_directory_uri() . '/assets/js/js.js', '', TAINACAN_INTERFACE_VERSION, true );
wp_enqueue_script( 'tainacan_tainacanJS' );
wp_enqueue_script( 'tainacan_searchBarRedirect', get_template_directory_uri() . '/assets/js/search-bar-redirect.js', [] , TAINACAN_INTERFACE_VERSION, false );
wp_register_script( 'tainacan_searchBarRedirect', get_template_directory_uri() . '/assets/js/search-bar-redirect.js', '', TAINACAN_INTERFACE_VERSION, false );
wp_enqueue_script( 'tainacan_searchBarRedirect' );
wp_enqueue_script( 'tainacan_copyLink', get_template_directory_uri() . '/assets/js/copy-link.js', [] , TAINACAN_INTERFACE_VERSION, false );
wp_localize_script( 'tainacan_copyLink', 'tainacan_copyLinkVars', array(
'linkCopied' => __( 'Copied! Link sent to the transfer area.', 'tainacan-interface' )

View File

@ -7,7 +7,7 @@
</button>
</span>
</div>
<?php if ( defined ( 'TAINACAN_VERSION' ) ) : ?>
<?php if ( defined ( 'TAINACAN_VERSION' ) && (get_theme_mod('tainacan_search_on_items', false) || get_theme_mod('tainacan_search_on_collections', false) || get_theme_mod('tainacan_search_global', false) ) ) : ?>
<div class="search-controls">
<label for="search-on-posts">
@ -20,25 +20,39 @@
<?php _e( 'Site posts', 'tainacan-interface' ); ?>
</label>
<?php if ( get_theme_mod('tainacan_search_on_items', false) ) : ?>
<label for="search-on-items">
<input
type="radio"
value="tainacan-items"
name="archive"
formaction="/items"
id="search-on-items">
<?php _e( 'Archive items', 'tainacan-interface' ); ?>
</label>
<?php endif;
if ( get_theme_mod('tainacan_search_on_collections', false) ) : ?>
<label for="search-on-collections">
<input
type="radio"
value="tainacan-collections"
name="archive"
formaction="/collections"
id="search-on-collections">
<?php _e( 'Archive collections', 'tainacan-interface' ); ?>
</label>
<?php endif;
if ( get_theme_mod('tainacan_search_global', false) ) : ?>
<label for="search-everywhere">
<input
type="radio"
value="everywhere"
name="archive"
id="search-everywhere">
<?php _e( 'Everywhere', 'tainacan-interface' ); ?>
</label>
<?php endif; ?>
</div>
<?php endif; ?>
</form>

File diff suppressed because one or more lines are too long

View File

@ -1,10 +1,11 @@
<?php
if ( $_GET['everywhere'] ) {
$post_type = get_post_type();
$post_type_object = get_post_type_object($post_type);
$post_type_label = $post_type_object->labels->singular_name;
$post_type_archive_link = get_post_type_archive_link($post_type);
}
?>
<div class="row blog-post mb-4">
<?php if ( has_post_thumbnail() ) : ?>
<div class="col-xs-12 col-md-4 blog-thumbnail align-self-center text-center mb-4 mb-md-0">
@ -14,6 +15,7 @@
</div>
<?php endif; ?>
<div class="col-xs-12 blog-content <?php if ( has_post_thumbnail() ) :?>col-md-8 blog-flex<?php else : ?>col-md-12<?php endif; ?> align-self-center">
<?php if ( $_GET['everywhere'] ) : ?>
<div class="title-area">
<h3 class="mb-3">
<a href="<?php the_permalink(); ?>" class="font-weight-bold"><?php the_title(); ?></a>
@ -21,6 +23,11 @@
<h4><a href="<?php echo $post_type_archive_link ?>"><?php echo $post_type_label ?></a></h4>
</div>
<?php else: ?>
<h3 class="mb-3">
<a href="<?php the_permalink(); ?>" class="font-weight-bold"><?php the_title(); ?></a>
</h3>
<?php endif; ?>
<?php echo '<p class="text-black">' . wp_trim_words( get_the_excerpt(), 28, '...' ) . '</p>'; ?>
<?php tainacan_meta_date_author(); ?>

View File

@ -47,7 +47,7 @@
<div style="margin: 0 4.1666667%" class="pagination">
<a class="d-inline-flex align-items-center" href="<?php echo tainacan_get_source_item_list_url(); ?>">
<i class="tainacan-icon tainacan-icon-viewtable tainacan-icon-1-25em"></i>&nbsp;&nbsp;<span><?php echo __('Back to items list', 'tainacan') ?></span>
<i class="tainacan-icon tainacan-icon-viewtable tainacan-icon-1-25em"></i>&nbsp;&nbsp;<span><?php echo __('Back to items list', 'tainacan-interface') ?></span>
</a>
</div>