Skip to content

Commit

Permalink
Pull in 10up#2941 and 10up#3114
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccahum committed Nov 9, 2022
1 parent b44d015 commit d9d1493
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions includes/classes/Feature/Search/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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' ] );
}
}
Expand All @@ -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();

Expand All @@ -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'] ) . '>' );
Expand Down

0 comments on commit d9d1493

Please sign in to comment.