Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull in https://github.com/10up/ElasticPress/pull/2941 and https://github.com/10up/ElasticPress/pull/3114 #182

Merged
merged 1 commit into from
Nov 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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