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

New Filter ep_highlight_number_of_fragments. #3600

Closed

Conversation

dgnorrod
Copy link
Contributor

@dgnorrod dgnorrod commented Aug 14, 2023

Add to ./includes/classes/Feature/Search/Search.php a new filter to set the maximum number of fragments to highlight.

Description of the Change

Added a filter that allows the dev to set the max number of fragments to highlight. This is just a convenience filter that relieves us from having to modify the formatted args directly. This maintains the current default setting of zero fragments.

Closes #3579

How to test the Change

Add this to a function:

// set number of fragments to 10 for post_content and post_excerpt fields (zero is the default)
add_filter( 'ep_highlight_number_of_fragments', function( $number_of_fragments, $field ) {
    if ( in_array( $field, [ 'post_content', 'post_excerpt' ] ) ) {
        $number_of_fragments = 10;
    }
    return $number_of_fragments;
} );

Check the query body "highlight" section for the "number_of_fragments" setting.

Changelog Entry

Added - New feature
Changed - Existing functionality
Deprecated - Soon-to-be removed feature
Removed - Feature
Fixed - Bug fix
Security - Vulnerability

Credits

Props @username, @username2, ...
Props @dgnorrod

Checklist:

  • [x ] I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

Add to ./includes/classes/Feature/Search/Search.php a new filter to set the maximum number of fragments to highlight.
Copy link
Member

@felipeelia felipeelia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind adding the documentation for the first parameter as well? Thanks!

includes/classes/Feature/Search/Search.php Outdated Show resolved Hide resolved
@dgnorrod
Copy link
Contributor Author

dgnorrod commented Sep 7, 2023 via email

@dgnorrod dgnorrod requested a review from felipeelia September 19, 2023 11:21
@felipeelia felipeelia added this to the 4.7.2 milestone Oct 3, 2023
@felipeelia
Copy link
Member

Closing in favor of #3681

@felipeelia felipeelia closed this Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Filter to set number of fragments
2 participants