PluginProbe
ElasticPress / 5.3.5
ElasticPress v5.3.5
5.3.5 5.3.4 3.6.5 3.6.6 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.7.0 4.7.1 4.7.2 5.0.0 5.0.1 5.0.2 All 108 releases
← All changes | includes/classes/Feature/Search/Search.php +276 -186 4.4.15.3.5 View file →
@@ -7,11 +7,12 @@
7 7 */
8 8
9 9 namespace ElasticPress\Feature\Search;
10 10
11 -use ElasticPress\Feature as Feature;
12 -use ElasticPress\Indexables as Indexables;
13 -use ElasticPress\Utils as Utils;
11 +use ElasticPress\Feature;
12 +use ElasticPress\Features;
13 +use ElasticPress\Indexables;
14 +use ElasticPress\Utils;
14 15
15 16 /**
16 17 * Search feature class
17 18 */
@@ -50,14 +51,10 @@
50 51 */
51 52 public function __construct() {
52 53 $this->slug = 'search';
53 54
54 - $this->title = esc_html__( 'Post Search', 'elasticpress' );
55 + $this->group = 'core-search';
55 56
56 - $this->summary = __( 'Instantly find the content you’re looking for. The first time.', 'elasticpress' );
57 -
58 - $this->docs_url = __( 'https://elasticpress.zendesk.com/hc/en-us/articles/360050447492-Configuring-ElasticPress-via-the-Plugin-Dashboard#post-search', 'elasticpress' );
59 -
60 57 $this->requires_install_reindex = false;
61 58
62 59 $this->default_settings = [
63 60 'decaying_enabled' => '1',
@@ -72,8 +69,29 @@
72 69 parent::__construct();
73 70 }
74 71
75 72 /**
73 + * Sets i18n strings.
74 + *
75 + * @return void
76 + * @since 5.2.0
77 + */
78 + public function set_i18n_strings(): void {
79 + $this->title = esc_html__( 'Post Search', 'elasticpress' );
80 +
81 + $this->summary = '<p>' . __( 'Instantly find the content you’re looking for. The first time.', 'elasticpress' ) . '</p>' .
82 + '<p>' . __( 'Overcome higher-end performance and functional limits posed by the traditional WordPress structured (SQL) database to deliver superior keyword search, instantly. ElasticPress indexes custom fields, tags, and other metadata to improve search results. Fuzzy matching accounts for misspellings and verb tenses.', 'elasticpress' ) . '</p>';
83 +
84 + $this->docs_url = __( 'https://www.elasticpress.io/resources/articles/configuring-elasticpress-via-the-plugin-dashboard/#post-search', 'elasticpress' );
85 +
86 + $this->field_group_map = [
87 + 'highlight_group' => [
88 + 'label' => esc_html__( 'Highlighting Options', 'elasticpress' ),
89 + ],
90 + ];
91 + }
92 +
93 + /**
76 94 * We need to delay search setup up since it will fire after protected content and protected
77 95 * content filters into the search setup
78 96 *
79 97 * @since 2.2
@@ -78,10 +96,11 @@
78 96 *
79 97 * @since 2.2
80 98 */
81 99 public function setup() {
100 + Indexables::factory()->activate( 'post' );
101 +
82 102 add_action( 'init', [ $this, 'search_setup' ] );
83 - add_filter( 'ep_sanitize_feature_settings', [ $this, 'sanitize_highlighting_settings' ] );
84 103
85 104 // Set up weighting sub-module
86 105 $this->weighting = new Weighting();
87 106 $this->weighting->setup();
@@ -105,12 +124,17 @@
105 124 add_filter( 'ep_highlighting_tag', [ $this, 'get_highlighting_tag' ] );
106 125 add_action( 'ep_highlighting_pre_add_highlight', [ $this, 'allow_excerpt_html' ] );
107 126
108 127 add_action( 'init', [ $this, 'register_meta' ], 20 );
128 + add_filter( 'ep_prepare_meta_allowed_keys', [ $this, 'add_exclude_from_search' ] );
109 129 add_action( 'enqueue_block_editor_assets', [ $this, 'enqueue_block_editor_assets' ] );
110 - add_action( 'pre_get_posts', [ $this, 'exclude_posts_from_search' ] );
130 + add_filter( 'ep_post_filters', [ $this, 'exclude_posts_from_search' ], 10, 3 );
111 131 add_action( 'post_submitbox_misc_actions', [ $this, 'output_exclude_from_search_setting' ] );
112 - add_action( 'edit_post', [ $this, 'save_exclude_from_search_meta' ], 10, 2 );
132 + add_action( 'edit_post', [ $this, 'save_exclude_from_search_meta' ] );
133 + add_filter( 'ep_skip_query_integration', [ $this, 'skip_query_integration' ], 10, 2 );
134 +
135 + add_action( 'attachment_submitbox_misc_actions', [ $this, 'output_exclude_from_search_setting' ], 15 );
136 + add_action( 'edit_attachment', [ $this, 'save_exclude_from_search_meta' ] );
113 137 }
114 138
115 139
116 140 /**
@@ -118,15 +142,9 @@
118 142 */
119 143 public function enqueue_scripts() {
120 144 $settings = $this->get_settings();
121 145
122 - if ( ! $settings ) {
123 - $settings = [];
124 - }
125 -
126 - $settings = wp_parse_args( $settings, $this->default_settings );
127 -
128 - if ( true !== $settings['highlight_enabled'] ) {
146 + if ( '1' !== $settings['highlight_enabled'] ) {
129 147 return;
130 148 }
131 149
132 150 wp_enqueue_style(
@@ -159,15 +177,9 @@
159 177
160 178 // get current config
161 179 $settings = $this->get_settings();
162 180
163 - if ( ! $settings ) {
164 - $settings = [];
165 - }
166 -
167 - $settings = wp_parse_args( $settings, $this->default_settings );
168 -
169 - if ( true !== $settings['highlight_enabled'] ) {
181 + if ( '1' !== $settings['highlight_enabled'] ) {
170 182 return $formatted_args;
171 183 }
172 184
173 185 if ( empty( $args['s'] ) ) {
@@ -243,9 +255,18 @@
243 255 $formatted_args['highlight']['fields'][ $field ] = [
244 256 'pre_tags' => [ $opening_tag ],
245 257 'post_tags' => [ $closing_tag ],
246 258 'type' => 'plain',
247 - 'number_of_fragments' => 0,
259 + /**
260 + * Filter the maximum number of fragments highlighted for a searched field.
261 + *
262 + * @since 4.7.2
263 + * @hook ep_highlight_number_of_fragments
264 + * @param {int} $max_fragments Maximum number of fragments for field.
265 + * @param {string} $field Search field being setup.
266 + * @return {int} New maximum number of fragments to highlight for the searched field.
267 + */
268 + 'number_of_fragments' => apply_filters( 'ep_highlight_number_of_fragments', 0, $field ),
248 269 ];
249 270 }
250 271
251 272 return $formatted_args;
@@ -263,15 +284,9 @@
263 284 }
264 285
265 286 $settings = $this->get_settings();
266 287
267 - if ( ! $settings ) {
268 - $settings = [];
269 - }
270 -
271 - $settings = wp_parse_args( $settings, $this->default_settings );
272 -
273 - if ( ! empty( $settings['highlight_excerpt'] ) && true === $settings['highlight_excerpt'] ) {
288 + if ( ! empty( $settings['highlight_excerpt'] ) && '1' === $settings['highlight_excerpt'] ) {
274 289 remove_filter( 'get_the_excerpt', 'wp_trim_excerpt' );
275 290 add_filter( 'get_the_excerpt', [ $this, 'ep_highlight_excerpt' ], 10, 2 );
276 291 add_filter( 'ep_highlighting_fields', [ $this, 'ep_highlight_add_excerpt_field' ] );
277 292 }
@@ -286,22 +301,20 @@
286 301 *
287 302 * @return string $text the new excerpt
288 303 */
289 304 public function ep_highlight_excerpt( $text, $post ) {
290 -
291 305 $settings = $this->get_settings();
292 306
293 - if ( ! $settings ) {
294 - $settings = [];
295 - }
296 -
297 - $settings = wp_parse_args( $settings, $this->default_settings );
298 -
299 307 // reproduces wp_trim_excerpt filter, preserving the excerpt_more and excerpt_length filters
300 308 if ( '' === $text ) {
301 309 $text = get_the_content( '', false, $post );
310 +
311 + $text = strip_shortcodes( $text );
312 + $text = excerpt_remove_blocks( $text );
313 +
302 314 $text = apply_filters( 'the_content', $text );
303 315 $text = str_replace( '\]\]\>', ']]&gt;', $text );
316 +
304 317 $text = strip_tags( $text, '<' . esc_html( $settings['highlight_tag'] ) . '>' );
305 318
306 319 // use the defined length, if already applied...
307 320 $excerpt_length = apply_filters( 'excerpt_length', 55 );
@@ -307,11 +320,14 @@
307 320 $excerpt_length = apply_filters( 'excerpt_length', 55 );
308 321
309 322 // use defined excerpt_more filter if it is used
310 323 $excerpt_more = apply_filters( 'excerpt_more', $text );
311 -
312 324 $excerpt_more = $excerpt_more !== $text ? $excerpt_more : '[&hellip;]';
313 325
326 + /**
327 + * WordPress would handle this using `wp_trim_words` but that removes all tags,
328 + * including the one used to highlight the search term.
329 + */
314 330 $words = explode( ' ', $text, $excerpt_length + 1 );
315 331 if ( count( $words ) > $excerpt_length ) {
316 332 array_pop( $words );
317 333 array_push( $words, $excerpt_more );
@@ -348,26 +364,8 @@
348 364 return $tag;
349 365 }
350 366
351 367 /**
352 - * Sanitizes our highlighting settings.
353 - *
354 - * @param array $settings Array of current settings
355 - * @return mixed
356 - */
357 - public function sanitize_highlighting_settings( $settings ) {
358 - if ( ! empty( $settings['search']['highlight_excerpt'] ) ) {
359 - $settings['search']['highlight_excerpt'] = (bool) $settings['search']['highlight_excerpt'];
360 - }
361 -
362 - if ( ! empty( $settings['search']['highlight_enabled'] ) ) {
363 - $settings['search']['highlight_enabled'] = (bool) $settings['search']['highlight_enabled'];
364 - }
365 -
366 - return $settings;
367 - }
368 -
369 - /**
370 368 * Returns searchable post types for the current site
371 369 *
372 370 * @since 1.9
373 371 * @return mixed|void
@@ -426,21 +424,28 @@
426 424
427 425 /**
428 426 * Returns true/false if decaying is/isn't enabled
429 427 *
428 + * @param array $args WP_Query args
429 + *
430 430 * @return bool
431 431 */
432 - public function is_decaying_enabled() {
432 + public function is_decaying_enabled( $args = [] ) {
433 433 $settings = $this->get_settings();
434 434
435 - $settings = wp_parse_args(
436 - $settings,
437 - [
438 - 'decaying_enabled' => true,
439 - ]
440 - );
435 + $is_decaying_enabled = $settings['decaying_enabled'] && '0' !== $settings['decaying_enabled'];
441 436
442 - return (bool) $settings['decaying_enabled'];
437 + /**
438 + * Filter to modify decaying
439 + *
440 + * @hook ep_is_decaying_enabled
441 + * @since 4.6.0
442 + * @param {bool} $is_decaying_enabled Whether decay by date is enabled or not
443 + * @param {array} $settings Settings
444 + * @param {array} $args WP_Query args
445 + * @return {bool} Decaying
446 + */
447 + return apply_filters( 'ep_is_decaying_enabled', $is_decaying_enabled, $settings, $args );
443 448 }
444 449
445 450 /**
446 451 * Weight more recent content in searches
@@ -453,11 +458,13 @@
453 458 public function weight_recent( $formatted_args, $args ) {
454 459 if ( empty( $args['s'] ) ) {
455 460 return $formatted_args;
456 461 }
457 - if ( ! $this->is_decaying_enabled() ) {
462 +
463 + if ( ! $this->is_decaying_enabled( $args ) ) {
458 464 return $formatted_args;
459 465 }
466 +
460 467 /**
461 468 * Filter search date weighting scale
462 469 *
463 470 * @hook epwr_decay_function
@@ -466,8 +473,9 @@
466 473 * @param {array} $args WP_Query arguments
467 474 * @return {string} New decay function
468 475 */
469 476 $decay_function = apply_filters( 'epwr_decay_function', 'exp', $formatted_args, $args );
477 +
470 478 /**
471 479 * Filter search date weighting field
472 480 *
473 481 * @hook epwr_decay_field
@@ -560,20 +568,8 @@
560 568 return $formatted_args;
561 569 }
562 570
563 571 /**
564 - * Output feature box long text
565 - *
566 - * @since 3.0
567 - */
568 - public function output_feature_box_long() {
569 - ?>
570 - <p><?php esc_html_e( 'Overcome higher-end performance and functional limits posed by the traditional WordPress structured (SQL) database to deliver superior keyword search, instantly. ElasticPress indexes custom fields, tags, and other metadata to improve search results. Fuzzy matching accounts for misspellings and verb tenses.', 'elasticpress' ); ?></p>
571 -
572 - <?php
573 - }
574 -
575 - /**
576 572 * Enable integration on search queries
577 573 *
578 574 * @param bool $enabled Original enabled value
579 575 * @param WP_Query $query WP Query
@@ -609,69 +605,8 @@
609 605 return apply_filters( 'ep_integrate_search_queries', $enabled, $query );
610 606 }
611 607
612 608 /**
613 - * Display decaying settings on dashboard.
614 - *
615 - * @since 2.4
616 - */
617 - public function output_feature_box_settings() {
618 - $settings = $this->get_settings();
619 -
620 - if ( ! $settings ) {
621 - $settings = [];
622 - }
623 -
624 - $settings = wp_parse_args( $settings, $this->default_settings );
625 -
626 - ?>
627 - <div class="field">
628 - <div class="field-name status"><?php esc_html_e( 'Weight results by date', 'elasticpress' ); ?></div>
629 - <div class="input-wrap">
630 - <label><input name="settings[decaying_enabled]" type="radio" <?php checked( (bool) $settings['decaying_enabled'] ); ?> value="1"><?php esc_html_e( 'Enabled', 'elasticpress' ); ?></label><br>
631 - <label><input name="settings[decaying_enabled]" type="radio" <?php checked( ! (bool) $settings['decaying_enabled'] ); ?> value="0"><?php esc_html_e( 'Disabled', 'elasticpress' ); ?></label>
632 - </div>
633 - </div>
634 - <div class="field">
635 - <div class="field-name status"><?php esc_html_e( 'Highlighting status', 'elasticpress' ); ?></div>
636 - <div class="input-wrap">
637 - <label><input name="settings[highlight_enabled]" type="radio" <?php checked( (bool) $settings['highlight_enabled'] ); ?> value="1"><?php esc_html_e( 'Enabled', 'elasticpress' ); ?></label><br>
638 - <label><input name="settings[highlight_enabled]" type="radio" <?php checked( ! (bool) $settings['highlight_enabled'] ); ?> value="0"><?php esc_html_e( 'Disabled', 'elasticpress' ); ?></label>
639 - <p class="field-description"><?php esc_html_e( 'Wrap search terms in HTML tags in results for custom styling. The wrapping HTML tag comes with the "ep-highlight" class for easy styling.' ); ?></p>
640 - </div>
641 - </div>
642 - <div class="field">
643 - <label for="highlight-tag" class="field-name status"><?php echo esc_html_e( 'Highlight tag ', 'elasticpress' ); ?></label>
644 - <div class="input-wrap">
645 - <select id="highlight-tag" name="settings[highlight_tag]">
646 - <?php
647 - foreach ( self::$default_highlight_tags as $option ) :
648 - echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $settings['highlight_tag'] ) . '>' . esc_html( $option ) . '</option>';
649 - endforeach;
650 - ?>
651 - </select>
652 - </div>
653 - </div>
654 -
655 - <div class="field">
656 - <div class="field-name status"><?php esc_html_e( 'Excerpt highlighting', 'elasticpress' ); ?></div>
657 - <div class="input-wrap">
658 - <label><input name="settings[highlight_excerpt]" type="radio" <?php checked( (bool) $settings['highlight_excerpt'] ); ?> value="1"><?php esc_html_e( 'Enabled', 'elasticpress' ); ?></label><br>
659 - <label><input name="settings[highlight_excerpt]" type="radio" <?php checked( ! (bool) $settings['highlight_excerpt'] ); ?> value="0"><?php esc_html_e( 'Disabled', 'elasticpress' ); ?></label>
660 - <p class="field-description"><?php esc_html_e( 'By default, WordPress strips HTML from content excerpts. Enable when using the_excerpt() to display search results. ', 'elasticpress' ); ?></p>
661 - </div>
662 - </div>
663 -
664 - <?php if ( ! defined( 'EP_IS_NETWORK' ) || ! EP_IS_NETWORK ) : ?>
665 - <br class="clear">
666 - <p><a href="<?php echo esc_url( admin_url( 'admin.php?page=elasticpress-weighting' ) ); ?>"><?php esc_html_e( 'Advanced fields and weighting settings', 'elasticpress' ); ?></a></p>
667 - <p><a href="<?php echo esc_url( admin_url( 'admin.php?page=elasticpress-synonyms' ) ); ?>"><?php esc_html_e( 'Add synonyms to your post searches', 'elasticpress' ); ?></a></p>
668 - <?php endif; ?>
669 -
670 - <?php
671 - }
672 -
673 - /**
674 609 * Registers post meta for exclude from search feature.
675 610 */
676 611 public function register_meta() {
677 612 register_post_meta(
@@ -685,8 +620,20 @@
685 620 );
686 621 }
687 622
688 623 /**
624 + * Add ep_exclude_from_search to the allowed meta fields list.
625 + *
626 + * @since 5.0.0
627 + * @param array $keys List of allowed meta fields
628 + * @return array
629 + */
630 + public function add_exclude_from_search( $keys ) {
631 + $keys[] = 'ep_exclude_from_search';
632 + return $keys;
633 + }
634 +
635 + /**
689 636 * Enqueue block editor assets.
690 637 */
691 638 public function enqueue_block_editor_assets() {
692 639 global $post;
@@ -694,68 +641,68 @@
694 641 if ( ! $post instanceof \WP_Post ) {
695 642 return;
696 643 }
697 644
645 + if ( ! $post->post_type || ! post_type_supports( $post->post_type, 'custom-fields' ) ) {
646 + return;
647 + }
648 +
698 649 wp_enqueue_script(
699 650 'ep-search-editor',
700 - EP_URL . '/dist/js/search-editor-script.js',
651 + EP_URL . 'dist/js/search-editor-script.js',
701 652 Utils\get_asset_info( 'search-editor-script', 'dependencies' ),
702 653 Utils\get_asset_info( 'search-editor-script', 'version' ),
703 654 true
704 655 );
656 +
657 + wp_set_script_translations( 'ep-search-editor', 'elasticpress' );
705 658 }
706 659
707 660 /**
708 661 * Exclude posts based on ep_exclude_from_search post meta.
709 662 *
710 - * @param WP_Query $query WP Query
663 + * @param array $filters Filters to be applied to the query
664 + * @param array $args WP Query args
665 + * @param WP_Query $query WP Query object
711 666 */
712 - public function exclude_posts_from_search( $query ) {
713 - $bypass_exclusion_from_search = is_admin() || ! $query->is_search();
667 + public function exclude_posts_from_search( $filters, $args, $query ) {
668 + if ( ! empty( $query->get( 'ep_skip_search_exclusion' ) ) ) {
669 + return $filters;
670 + }
671 +
672 + $bypass_exclusion_from_search = ( is_admin() && ! wp_doing_ajax() ) || ! $query->is_search();
673 +
714 674 /**
715 675 * Filter whether the exclusion from the "exclude from search" checkbox should be applied
716 676 *
717 677 * @since 4.4.0
718 678 * @hook ep_bypass_exclusion_from_search
719 - * @param {bool} $bypass_exclusion_from_search True means all posts will be returned
720 - * @param {WP_Query} $query WP Query
679 + * @param {bool} $bypass_exclusion_from_search True means all posts will be returned
680 + * @param {WP_Query} $query WP Query
721 681 * @return {bool} New $bypass_exclusion_from_search value
722 682 */
723 - if ( apply_filters( 'ep_bypass_exclusion_from_search', $bypass_exclusion_from_search, $query ) ) {
724 - return;
683 + if ( apply_filters_deprecated(
684 + 'ep_bypass_exclusion_from_search',
685 + [ $bypass_exclusion_from_search, $query ],
686 + 'ElasticPress 5.3.0',
687 + 'WP_Query->ep_skip_search_exclusion argument'
688 + ) ) {
689 + return $filters;
725 690 }
726 691
727 - // Get any meta query that's being added before.
728 - $meta_query = (array) $query->get( 'meta_query' );
729 -
730 - $exclude_from_search_query = [
731 - 'relation' => 'or',
732 - [
733 - 'key' => 'ep_exclude_from_search',
734 - 'compare' => 'NOT EXISTS',
692 + $filters[] = [
693 + 'bool' => [
694 + 'must_not' => [
695 + [
696 + 'terms' => [
697 + 'meta.ep_exclude_from_search.raw' => [ '1' ],
698 + ],
699 + ],
700 + ],
735 701 ],
736 - [
737 - 'key' => 'ep_exclude_from_search',
738 - 'value' => '1',
739 - 'compare' => '!=',
740 - ],
741 702 ];
742 703
743 - /**
744 - * If the current meta query only has an `OR` clause, wrap it with an `AND`
745 - * so the criteria here is not made "optional".
746 - */
747 - if ( empty( $meta_query ) || empty( $meta_query['relation'] ) || 'and' === strtolower( $meta_query['relation'] ) ) {
748 - $meta_query[] = $exclude_from_search_query;
749 - } else {
750 - $meta_query = [
751 - 'relation' => 'and',
752 - $exclude_from_search_query,
753 - $meta_query,
754 - ];
755 - }
756 -
757 - $query->set( 'meta_query', $meta_query );
704 + return $filters;
758 705 }
759 706
760 707 /**
761 708 * Outputs the checkbox to exclude a post from search.
@@ -762,9 +709,8 @@
762 709 *
763 710 * @param WP_POST $post Post object.
764 711 */
765 712 public function output_exclude_from_search_setting( $post ) {
766 -
767 713 $searchable_post_types = $this->get_searchable_post_types();
768 714 if ( ! in_array( $post->post_type, $searchable_post_types, true ) ) {
769 715 return;
770 716 }
@@ -771,9 +717,15 @@
771 717 ?>
772 718 <div class="misc-pub-section">
773 719 <input id="ep_exclude_from_search" name="ep_exclude_from_search" type="checkbox" value="1" <?php checked( get_post_meta( get_the_ID(), 'ep_exclude_from_search', true ) ); ?>>
774 720 <label for="ep_exclude_from_search"><?php esc_html_e( 'Exclude from search results', 'elasticpress' ); ?></label>
775 - <p class="howto"><?php esc_html_e( 'Excludes this post from the results of your site\'s search form while ElasticPress is active.', 'elasticpress' ); ?></p>
721 + <p class="howto">
722 + <?php if ( 'attachment' === $post->post_type ) : ?>
723 + <?php esc_html_e( 'Excludes this media from the results of your site\'s search form while ElasticPress is active.', 'elasticpress' ); ?>
724 + <?php else : ?>
725 + <?php esc_html_e( 'Excludes this post from the results of your site\'s search form while ElasticPress is active.', 'elasticpress' ); ?>
726 + <?php endif; ?>
727 + </p>
776 728 <?php wp_nonce_field( 'save-exclude-from-search', 'ep-exclude-from-search-nonce' ); ?>
777 729 </div>
778 730 <?php
779 731 }
@@ -780,18 +732,16 @@
780 732
781 733 /**
782 734 * Saves exclude from search meta.
783 735 *
784 - * @param int $post_id The post ID.
785 - * @param WP_Post $post Post object.
736 + * @param int $post_id The post ID.
786 737 */
787 - public function save_exclude_from_search_meta( $post_id, $post ) {
788 -
738 + public function save_exclude_from_search_meta( $post_id ) {
789 739 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
790 740 return;
791 741 }
792 742
793 - if ( ! isset( $_POST['ep-exclude-from-search-nonce'] ) || ! wp_verify_nonce( $_POST['ep-exclude-from-search-nonce'], 'save-exclude-from-search' ) ) {
743 + if ( ! isset( $_POST['ep-exclude-from-search-nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['ep-exclude-from-search-nonce'] ), 'save-exclude-from-search' ) ) {
794 744 return;
795 745 }
796 746
797 747 if ( ! current_user_can( 'edit_post', $post_id ) ) {
@@ -797,9 +747,149 @@
797 747 if ( ! current_user_can( 'edit_post', $post_id ) ) {
798 748 return;
799 749 }
800 750
801 - $exclude_from_search = isset( $_POST['ep_exclude_from_search'] ) ? true : false;
751 + if ( isset( $_POST['ep_exclude_from_search'] ) ) {
752 + update_post_meta( $post_id, 'ep_exclude_from_search', true );
753 + } else {
754 + delete_post_meta( $post_id, 'ep_exclude_from_search' );
755 + }
756 + }
802 757
803 - update_post_meta( $post_id, 'ep_exclude_from_search', $exclude_from_search );
758 + /**
759 + * If WP_Query has unsupported orderby, skip ES query integration and use the WP query instead.
760 + *
761 + * @param bool $skip Whether to skip ES query integration
762 + * @param \WP_Query $query WP_Query object
763 + *
764 + * @since 4.5
765 + * @return bool
766 + */
767 + public function skip_query_integration( $skip, $query ) {
768 + if ( ! $query instanceof \WP_Query ) {
769 + return $skip;
770 + }
771 +
772 + $unsupported_orderby = [
773 + 'post__in',
774 + 'post_name__in',
775 + 'post_parent__in',
776 + 'parent',
777 + ];
778 +
779 + $orderby = is_string( $query->get( 'orderby' ) ) ? explode( ' ', $query->get( 'orderby' ) ) : $query->get( 'orderby', 'date' );
780 +
781 + $parse_orderby = array();
782 + foreach ( $orderby as $key => $value ) {
783 + $parse_orderby[] = is_string( $key ) ? $key : $value;
784 + }
785 +
786 + if ( array_intersect( $parse_orderby, $unsupported_orderby ) ) {
787 + return true;
788 + }
789 +
790 + return $skip;
791 + }
792 +
793 + /**
794 + * Set the `settings_schema` attribute
795 + *
796 + * @since 5.0.0
797 + */
798 + protected function set_settings_schema() {
799 + $this->settings_schema = [
800 + [
801 + 'default' => '1',
802 + 'key' => 'decaying_enabled',
803 + 'label' => __( 'Weighting by date', 'elasticpress' ),
804 + 'options' => [
805 + [
806 + 'label' => __( 'Don\'t weight results by date', 'elasticpress' ),
807 + 'value' => '0',
808 + ],
809 + [
810 + 'label' => __( 'Weight results by date', 'elasticpress' ),
811 + 'value' => '1',
812 + ],
813 + ],
814 + 'type' => 'radio',
815 + ],
816 + [
817 + 'default' => '0',
818 + 'help' => __( 'Enable to wrap search terms in HTML tags in results for custom styling. The wrapping HTML tag comes with the <code>ep-highlight</code> class for easy styling.', 'elasticpress' ),
819 + 'key' => 'highlight_enabled',
820 + 'label' => __( 'Highlight search terms', 'elasticpress' ),
821 + 'type' => 'checkbox',
822 + 'field_group_slug' => 'highlight_group',
823 + ],
824 + [
825 + 'default' => '0',
826 + 'help' => __( 'By default, WordPress strips HTML from content excerpts. Enable when using <code>the_excerpt()</code> to display search results.', 'elasticpress' ),
827 + 'key' => 'highlight_excerpt',
828 + 'label' => __( 'Highlight search terms in excerpts', 'elasticpress' ),
829 + 'type' => 'checkbox',
830 + 'field_group_slug' => 'highlight_group',
831 + ],
832 + [
833 + 'default' => 'mark',
834 + 'help' => __( 'Select the HTML tag used to highlight search terms.', 'elasticpress' ),
835 + 'key' => 'highlight_tag',
836 + 'label' => __( 'Highlight tag', 'elasticpress' ),
837 + 'options' => [
838 + [
839 + 'label' => 'mark',
840 + 'value' => 'mark',
841 + ],
842 + [
843 + 'label' => 'span',
844 + 'value' => 'span',
845 + ],
846 + [
847 + 'label' => 'strong',
848 + 'value' => 'strong',
849 + ],
850 + [
851 + 'label' => 'em',
852 + 'value' => 'em',
853 + ],
854 + [
855 + 'label' => 'i',
856 + 'value' => 'i',
857 + ],
858 + ],
859 + 'type' => 'select',
860 + 'requires_fields' => [
861 + 'relationship' => 'OR',
862 + 'conditions' => [
863 + 'highlight_enabled' => '1',
864 + 'highlight_excerpt' => '1',
865 + ],
866 + ],
867 + 'field_group_slug' => 'highlight_group',
868 + ],
869 + [
870 + 'default' => 'simple',
871 + 'key' => 'synonyms_editor_mode',
872 + 'type' => 'hidden',
873 + ],
874 + ];
875 +
876 + if ( ! defined( 'EP_IS_NETWORK' ) || ! EP_IS_NETWORK ) {
877 + $weighting_url = esc_url( admin_url( 'admin.php?page=elasticpress-weighting' ) );
878 + $synonyms_url = esc_url( admin_url( 'admin.php?page=elasticpress-synonyms' ) );
879 +
880 + $text = sprintf(
881 + '<p><a href="%1$s">%2$s</a></p><p><a href="%3$s">%4$s</a></p>',
882 + $weighting_url,
883 + __( 'Advanced fields and weighting settings', 'elasticpress' ),
884 + $synonyms_url,
885 + __( 'Add synonyms to your post searches', 'elasticpress' ),
886 + );
887 +
888 + $this->settings_schema[] = [
889 + 'key' => 'additional_links',
890 + 'label' => $text,
891 + 'type' => 'markup',
892 + ];
893 + }
804 894 }
805 895 }