diff --git a/includes/classes/Feature/Search/Search.php b/includes/classes/Feature/Search/Search.php index 47ebbe9a26..c2ebd5aee6 100644 --- a/includes/classes/Feature/Search/Search.php +++ b/includes/classes/Feature/Search/Search.php @@ -252,11 +252,7 @@ public function add_search_highlight_tags( $formatted_args, $args ) { * for the selected tag to be displayed in it. */ public function allow_excerpt_html() { - if ( is_admin() ) { - return; - } - - if ( empty( $_GET['s'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification + if ( ! Utils\is_integrated_request( 'highlighting', [ 'public' ] ) ) { return; } @@ -270,7 +266,7 @@ public function allow_excerpt_html() { if ( ! empty( $settings['highlight_excerpt'] ) && true === $settings['highlight_excerpt'] ) { remove_filter( 'get_the_excerpt', 'wp_trim_excerpt' ); - add_filter( 'get_the_excerpt', [ $this, 'ep_highlight_excerpt' ] ); + add_filter( 'get_the_excerpt', [ $this, 'ep_highlight_excerpt' ], 10, 2 ); add_filter( 'ep_highlighting_fields', [ $this, 'ep_highlight_add_excerpt_field' ] ); } } @@ -279,10 +275,12 @@ public function allow_excerpt_html() { * Called by allow_excerpt_html * logic for the excerpt filter allowing the currently selected tag. * - * @param string $text - excerpt string - * @return string $text - the new excerpt + * @param string $text excerpt string + * @param WP_Post $post Post Object + * + * @return string $text the new excerpt */ - public function ep_highlight_excerpt( $text ) { + public function ep_highlight_excerpt( $text, $post ) { $settings = $this->get_settings(); @@ -294,7 +292,7 @@ public function ep_highlight_excerpt( $text ) { // reproduces wp_trim_excerpt filter, preserving the excerpt_more and excerpt_length filters if ( '' === $text ) { - $text = get_the_content( '' ); + $text = get_the_content( '', false, $post ); $text = apply_filters( 'the_content', $text ); $text = str_replace( '\]\]\>', ']]>', $text ); $text = strip_tags( $text, '<' . esc_html( $settings['highlight_tag'] ) . '>' );