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 +223 -153 4.5.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,13 +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 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' ] );
113 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' ] );
114 137 }
115 138
116 139
117 140 /**
@@ -119,15 +142,9 @@
119 142 */
120 143 public function enqueue_scripts() {
121 144 $settings = $this->get_settings();
122 145
123 - if ( ! $settings ) {
124 - $settings = [];
125 - }
126 -
127 - $settings = wp_parse_args( $settings, $this->default_settings );
128 -
129 - if ( true !== $settings['highlight_enabled'] ) {
146 + if ( '1' !== $settings['highlight_enabled'] ) {
130 147 return;
131 148 }
132 149
133 150 wp_enqueue_style(
@@ -160,15 +177,9 @@
160 177
161 178 // get current config
162 179 $settings = $this->get_settings();
163 180
164 - if ( ! $settings ) {
165 - $settings = [];
166 - }
167 -
168 - $settings = wp_parse_args( $settings, $this->default_settings );
169 -
170 - if ( true !== $settings['highlight_enabled'] ) {
181 + if ( '1' !== $settings['highlight_enabled'] ) {
171 182 return $formatted_args;
172 183 }
173 184
174 185 if ( empty( $args['s'] ) ) {
@@ -244,9 +255,18 @@
244 255 $formatted_args['highlight']['fields'][ $field ] = [
245 256 'pre_tags' => [ $opening_tag ],
246 257 'post_tags' => [ $closing_tag ],
247 258 'type' => 'plain',
248 - '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 ),
249 269 ];
250 270 }
251 271
252 272 return $formatted_args;
@@ -264,15 +284,9 @@
264 284 }
265 285
266 286 $settings = $this->get_settings();
267 287
268 - if ( ! $settings ) {
269 - $settings = [];
270 - }
271 -
272 - $settings = wp_parse_args( $settings, $this->default_settings );
273 -
274 - if ( ! empty( $settings['highlight_excerpt'] ) && true === $settings['highlight_excerpt'] ) {
288 + if ( ! empty( $settings['highlight_excerpt'] ) && '1' === $settings['highlight_excerpt'] ) {
275 289 remove_filter( 'get_the_excerpt', 'wp_trim_excerpt' );
276 290 add_filter( 'get_the_excerpt', [ $this, 'ep_highlight_excerpt' ], 10, 2 );
277 291 add_filter( 'ep_highlighting_fields', [ $this, 'ep_highlight_add_excerpt_field' ] );
278 292 }
@@ -287,22 +301,20 @@
287 301 *
288 302 * @return string $text the new excerpt
289 303 */
290 304 public function ep_highlight_excerpt( $text, $post ) {
291 -
292 305 $settings = $this->get_settings();
293 306
294 - if ( ! $settings ) {
295 - $settings = [];
296 - }
297 -
298 - $settings = wp_parse_args( $settings, $this->default_settings );
299 -
300 307 // reproduces wp_trim_excerpt filter, preserving the excerpt_more and excerpt_length filters
301 308 if ( '' === $text ) {
302 309 $text = get_the_content( '', false, $post );
310 +
311 + $text = strip_shortcodes( $text );
312 + $text = excerpt_remove_blocks( $text );
313 +
303 314 $text = apply_filters( 'the_content', $text );
304 315 $text = str_replace( '\]\]\>', ']]&gt;', $text );
316 +
305 317 $text = strip_tags( $text, '<' . esc_html( $settings['highlight_tag'] ) . '>' );
306 318
307 319 // use the defined length, if already applied...
308 320 $excerpt_length = apply_filters( 'excerpt_length', 55 );
@@ -308,11 +320,14 @@
308 320 $excerpt_length = apply_filters( 'excerpt_length', 55 );
309 321
310 322 // use defined excerpt_more filter if it is used
311 323 $excerpt_more = apply_filters( 'excerpt_more', $text );
312 -
313 324 $excerpt_more = $excerpt_more !== $text ? $excerpt_more : '[&hellip;]';
314 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 + */
315 330 $words = explode( ' ', $text, $excerpt_length + 1 );
316 331 if ( count( $words ) > $excerpt_length ) {
317 332 array_pop( $words );
318 333 array_push( $words, $excerpt_more );
@@ -349,26 +364,8 @@
349 364 return $tag;
350 365 }
351 366
352 367 /**
353 - * Sanitizes our highlighting settings.
354 - *
355 - * @param array $settings Array of current settings
356 - * @return mixed
357 - */
358 - public function sanitize_highlighting_settings( $settings ) {
359 - if ( ! empty( $settings['search']['highlight_excerpt'] ) ) {
360 - $settings['search']['highlight_excerpt'] = (bool) $settings['search']['highlight_excerpt'];
361 - }
362 -
363 - if ( ! empty( $settings['search']['highlight_enabled'] ) ) {
364 - $settings['search']['highlight_enabled'] = (bool) $settings['search']['highlight_enabled'];
365 - }
366 -
367 - return $settings;
368 - }
369 -
370 - /**
371 368 * Returns searchable post types for the current site
372 369 *
373 370 * @since 1.9
374 371 * @return mixed|void
@@ -427,21 +424,28 @@
427 424
428 425 /**
429 426 * Returns true/false if decaying is/isn't enabled
430 427 *
428 + * @param array $args WP_Query args
429 + *
431 430 * @return bool
432 431 */
433 - public function is_decaying_enabled() {
432 + public function is_decaying_enabled( $args = [] ) {
434 433 $settings = $this->get_settings();
435 434
436 - $settings = wp_parse_args(
437 - $settings,
438 - [
439 - 'decaying_enabled' => true,
440 - ]
441 - );
435 + $is_decaying_enabled = $settings['decaying_enabled'] && '0' !== $settings['decaying_enabled'];
442 436
443 - 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 );
444 448 }
445 449
446 450 /**
447 451 * Weight more recent content in searches
@@ -454,11 +458,13 @@
454 458 public function weight_recent( $formatted_args, $args ) {
455 459 if ( empty( $args['s'] ) ) {
456 460 return $formatted_args;
457 461 }
458 - if ( ! $this->is_decaying_enabled() ) {
462 +
463 + if ( ! $this->is_decaying_enabled( $args ) ) {
459 464 return $formatted_args;
460 465 }
466 +
461 467 /**
462 468 * Filter search date weighting scale
463 469 *
464 470 * @hook epwr_decay_function
@@ -467,8 +473,9 @@
467 473 * @param {array} $args WP_Query arguments
468 474 * @return {string} New decay function
469 475 */
470 476 $decay_function = apply_filters( 'epwr_decay_function', 'exp', $formatted_args, $args );
477 +
471 478 /**
472 479 * Filter search date weighting field
473 480 *
474 481 * @hook epwr_decay_field
@@ -561,20 +568,8 @@
561 568 return $formatted_args;
562 569 }
563 570
564 571 /**
565 - * Output feature box long text
566 - *
567 - * @since 3.0
568 - */
569 - public function output_feature_box_long() {
570 - ?>
571 - <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>
572 -
573 - <?php
574 - }
575 -
576 - /**
577 572 * Enable integration on search queries
578 573 *
579 574 * @param bool $enabled Original enabled value
580 575 * @param WP_Query $query WP Query
@@ -610,69 +605,8 @@
610 605 return apply_filters( 'ep_integrate_search_queries', $enabled, $query );
611 606 }
612 607
613 608 /**
614 - * Display decaying settings on dashboard.
615 - *
616 - * @since 2.4
617 - */
618 - public function output_feature_box_settings() {
619 - $settings = $this->get_settings();
620 -
621 - if ( ! $settings ) {
622 - $settings = [];
623 - }
624 -
625 - $settings = wp_parse_args( $settings, $this->default_settings );
626 -
627 - ?>
628 - <div class="field">
629 - <div class="field-name status"><?php esc_html_e( 'Weight results by date', 'elasticpress' ); ?></div>
630 - <div class="input-wrap">
631 - <label><input name="settings[decaying_enabled]" type="radio" <?php checked( (bool) $settings['decaying_enabled'] ); ?> value="1"><?php esc_html_e( 'Enabled', 'elasticpress' ); ?></label><br>
632 - <label><input name="settings[decaying_enabled]" type="radio" <?php checked( ! (bool) $settings['decaying_enabled'] ); ?> value="0"><?php esc_html_e( 'Disabled', 'elasticpress' ); ?></label>
633 - </div>
634 - </div>
635 - <div class="field">
636 - <div class="field-name status"><?php esc_html_e( 'Highlighting status', 'elasticpress' ); ?></div>
637 - <div class="input-wrap">
638 - <label><input name="settings[highlight_enabled]" type="radio" <?php checked( (bool) $settings['highlight_enabled'] ); ?> value="1"><?php esc_html_e( 'Enabled', 'elasticpress' ); ?></label><br>
639 - <label><input name="settings[highlight_enabled]" type="radio" <?php checked( ! (bool) $settings['highlight_enabled'] ); ?> value="0"><?php esc_html_e( 'Disabled', 'elasticpress' ); ?></label>
640 - <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>
641 - </div>
642 - </div>
643 - <div class="field">
644 - <label for="highlight-tag" class="field-name status"><?php echo esc_html_e( 'Highlight tag ', 'elasticpress' ); ?></label>
645 - <div class="input-wrap">
646 - <select id="highlight-tag" name="settings[highlight_tag]">
647 - <?php
648 - foreach ( self::$default_highlight_tags as $option ) :
649 - echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $settings['highlight_tag'] ) . '>' . esc_html( $option ) . '</option>';
650 - endforeach;
651 - ?>
652 - </select>
653 - </div>
654 - </div>
655 -
656 - <div class="field">
657 - <div class="field-name status"><?php esc_html_e( 'Excerpt highlighting', 'elasticpress' ); ?></div>
658 - <div class="input-wrap">
659 - <label><input name="settings[highlight_excerpt]" type="radio" <?php checked( (bool) $settings['highlight_excerpt'] ); ?> value="1"><?php esc_html_e( 'Enabled', 'elasticpress' ); ?></label><br>
660 - <label><input name="settings[highlight_excerpt]" type="radio" <?php checked( ! (bool) $settings['highlight_excerpt'] ); ?> value="0"><?php esc_html_e( 'Disabled', 'elasticpress' ); ?></label>
661 - <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>
662 - </div>
663 - </div>
664 -
665 - <?php if ( ! defined( 'EP_IS_NETWORK' ) || ! EP_IS_NETWORK ) : ?>
666 - <br class="clear">
667 - <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>
668 - <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>
669 - <?php endif; ?>
670 -
671 - <?php
672 - }
673 -
674 - /**
675 609 * Registers post meta for exclude from search feature.
676 610 */
677 611 public function register_meta() {
678 612 register_post_meta(
@@ -686,8 +620,20 @@
686 620 );
687 621 }
688 622
689 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 + /**
690 636 * Enqueue block editor assets.
691 637 */
692 638 public function enqueue_block_editor_assets() {
693 639 global $post;
@@ -695,15 +641,21 @@
695 641 if ( ! $post instanceof \WP_Post ) {
696 642 return;
697 643 }
698 644
645 + if ( ! $post->post_type || ! post_type_supports( $post->post_type, 'custom-fields' ) ) {
646 + return;
647 + }
648 +
699 649 wp_enqueue_script(
700 650 'ep-search-editor',
701 - EP_URL . '/dist/js/search-editor-script.js',
651 + EP_URL . 'dist/js/search-editor-script.js',
702 652 Utils\get_asset_info( 'search-editor-script', 'dependencies' ),
703 653 Utils\get_asset_info( 'search-editor-script', 'version' ),
704 654 true
705 655 );
656 +
657 + wp_set_script_translations( 'ep-search-editor', 'elasticpress' );
706 658 }
707 659
708 660 /**
709 661 * Exclude posts based on ep_exclude_from_search post meta.
@@ -712,9 +664,14 @@
712 664 * @param array $args WP Query args
713 665 * @param WP_Query $query WP Query object
714 666 */
715 667 public function exclude_posts_from_search( $filters, $args, $query ) {
716 - $bypass_exclusion_from_search = is_admin() || ! $query->is_search();
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 +
717 674 /**
718 675 * Filter whether the exclusion from the "exclude from search" checkbox should be applied
719 676 *
720 677 * @since 4.4.0
@@ -722,9 +679,14 @@
722 679 * @param {bool} $bypass_exclusion_from_search True means all posts will be returned
723 680 * @param {WP_Query} $query WP Query
724 681 * @return {bool} New $bypass_exclusion_from_search value
725 682 */
726 - if ( apply_filters( 'ep_bypass_exclusion_from_search', $bypass_exclusion_from_search, $query ) ) {
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 + ) ) {
727 689 return $filters;
728 690 }
729 691
730 692 $filters[] = [
@@ -747,9 +709,8 @@
747 709 *
748 710 * @param WP_POST $post Post object.
749 711 */
750 712 public function output_exclude_from_search_setting( $post ) {
751 -
752 713 $searchable_post_types = $this->get_searchable_post_types();
753 714 if ( ! in_array( $post->post_type, $searchable_post_types, true ) ) {
754 715 return;
755 716 }
@@ -756,9 +717,15 @@
756 717 ?>
757 718 <div class="misc-pub-section">
758 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 ) ); ?>>
759 720 <label for="ep_exclude_from_search"><?php esc_html_e( 'Exclude from search results', 'elasticpress' ); ?></label>
760 - <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>
761 728 <?php wp_nonce_field( 'save-exclude-from-search', 'ep-exclude-from-search-nonce' ); ?>
762 729 </div>
763 730 <?php
764 731 }
@@ -765,18 +732,16 @@
765 732
766 733 /**
767 734 * Saves exclude from search meta.
768 735 *
769 - * @param int $post_id The post ID.
770 - * @param WP_Post $post Post object.
736 + * @param int $post_id The post ID.
771 737 */
772 - public function save_exclude_from_search_meta( $post_id, $post ) {
773 -
738 + public function save_exclude_from_search_meta( $post_id ) {
774 739 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
775 740 return;
776 741 }
777 742
778 - 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' ) ) {
779 744 return;
780 745 }
781 746
782 747 if ( ! current_user_can( 'edit_post', $post_id ) ) {
@@ -782,11 +747,13 @@
782 747 if ( ! current_user_can( 'edit_post', $post_id ) ) {
783 748 return;
784 749 }
785 750
786 - $exclude_from_search = isset( $_POST['ep_exclude_from_search'] ) ? true : false;
787 -
788 - update_post_meta( $post_id, 'ep_exclude_from_search', $exclude_from_search );
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 + }
789 756 }
790 757
791 758 /**
792 759 * If WP_Query has unsupported orderby, skip ES query integration and use the WP query instead.
@@ -820,6 +787,109 @@
820 787 return true;
821 788 }
822 789
823 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 + }
824 894 }
825 895 }