Skip to content

Inline Search: Return when the_title filter is called with the incorrect number of parameters #43511

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

Merged
merged 11 commits into from
May 27, 2025

Conversation

anaemnesis
Copy link
Contributor

@anaemnesis anaemnesis commented May 19, 2025

Fixes #p1747423124187819-slack-C02FMH4G8

Proposed changes:

This PR re-enables title highlighting for Inline Search if the active theme is not based on o2, which is being checked against for two reasons:

  1. Per the discussion above, o2 has its own the_title filter that doesn't pass the required number of parameters. o2 passes a post_title but not a post_id, which can lead to fatals. With checks for this in place...

  2. A post_id does eventually get passed, but post titles render with <mark> tags visible as part of the title.

Both of these need either a fix to o2 (to pass the correct number of parameters) or potential changes to escaping, to allow <mark> tags. Both should be addressed in future PRs.

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

N/A

Does this pull request change what data or activity we track or use?

N/A

Testing instructions:

  • Sandbox PfsEZG-r-p2
  • Using the bin/jetpack-downloader script (command below), check out this branch on your sandbox.
  • Ensure no fatals
  • Ensure titles are returned without <mark> tags on words that match your search term, e.g., billing
  • Ensure functionality continues to work for title and excerpt highlighting on your local environment. On your local environment, using a theme like TwentyTwentyFour, we'd expect to see:

CleanShot 2025-05-19 at 14 41 32

It's been reported that at least one theme calls the_title() filter with the incorrect number
of arguments, 1 instead of 2. This change should address that by returning early when handling
title highlighting.
@anaemnesis anaemnesis self-assigned this May 19, 2025
Copy link
Contributor

github-actions bot commented May 19, 2025

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the fix/early-return-when-improper-the_title-filter branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/early-return-when-improper-the_title-filter

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions github-actions bot added [Package] Search Contains core Search functionality for Jetpack and Search plugins [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] Search A plugin to add an instant search modal to your site to help visitors find content faster. [Status] In Progress labels May 19, 2025
Copy link
Contributor

github-actions bot commented May 19, 2025

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • 🔴 Add a "[Type]" label (Bug, Enhancement, Janitorial, Task).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: June 3, 2025
    • Code freeze: June 2, 2025

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Search plugin:

No scheduled milestone found for this plugin.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@github-actions github-actions bot added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label May 19, 2025
@anaemnesis anaemnesis added the Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR label May 19, 2025
@anaemnesis anaemnesis marked this pull request as ready for review May 19, 2025 09:28
Copy link

jp-launch-control bot commented May 19, 2025

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/search/src/inline-search/class-inline-search-highlighter.php 0/69 (0.00%) 0.00% 6 💔

Full summary · PHP report · JS report

Coverage check overridden by Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR .

o2's behaviour is a bit more involved than it at first seemed. For the moment let's skip o2 based themes.
@anaemnesis anaemnesis requested review from trakos and valterlorran May 19, 2025 13:42
Copy link
Contributor

@trakos trakos left a comment

Choose a reason for hiding this comment

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

Tested and works as described

Copy link
Contributor

@valterlorran valterlorran left a comment

Choose a reason for hiding this comment

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

LGTM! I tested it on PfsEZG-r-p2 and it looks good.

Comment on lines +81 to +85
$body_class = get_body_class();
if ( is_array( $body_class ) && in_array( 'o2', $body_class, true ) ) {
return $title;
}

Copy link
Contributor

@valterlorran valterlorran May 21, 2025

Choose a reason for hiding this comment

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

Nit: Since get_body_class() ultimately returns array_unique, we might be able to simplify this check.

		if ( in_array( 'o2', $body_class, true ) ) {
			return $title;
		}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a good point, and I've given it some thought. I'm going to keep it as is, just in case there's a something out there filtering body_class and not returning an array. I appreciate that this is probably overly defensive, but also this PR exists, so there we are. :)

@anaemnesis anaemnesis merged commit f1a29be into trunk May 27, 2025
68 checks passed
@anaemnesis anaemnesis deleted the fix/early-return-when-improper-the_title-filter branch May 27, 2025 08:59
@github-actions github-actions bot removed [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. [Status] In Progress labels May 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR [Package] Search Contains core Search functionality for Jetpack and Search plugins [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] Search A plugin to add an instant search modal to your site to help visitors find content faster.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants