Skip to content

Conversation

@laraib15
Copy link

@laraib15 laraib15 commented Jan 1, 2026

Description of the Change

This PR prevents a fatal error in Instant Results taxonomy facets when the ep_facet_include_taxonomies filter returns unexpected values (e.g., a taxonomy slug string such as internal_tags rather than a WP_Taxonomy object).

InstantResults::get_facets() currently assumes each filtered taxonomy entry is a WP_Taxonomy object and passes it directly to get_taxonomy_labels(). If a third-party integration appends a slug string, WordPress core fatals when it tries to treat a string as an object (e.g., Attempt to assign property "labels" on string in wp-includes/taxonomy.php).

This change adds a defensive guard in the taxonomy facets loop:

  • If the value is a string slug, normalize it via get_taxonomy( $slug )
  • If the value cannot be resolved to WP_Taxonomy, skip it

This prevents wp-admin lockouts while preserving existing behavior for correctly shaped data.

Closes #4254

How to test the Change

  1. Install and activate ElasticPress 5.3.2 and enable Instant Results.
  2. Add the reproduction filter from issue BUG: Fatal error in Instant Results facets when ep_facet_include_taxonomies contains a taxonomy slug string (e.g. internal_tags) #4254 (appends internal_tags as a string via ep_facet_include_taxonomies).
  3. Log in to wp-admin and visit:
    • /wp-admin/
    • /wp-admin/admin.php?page=elasticpress
  4. Confirm both pages load successfully and no fatal error occurs.

Verified on: WordPress 6.9; PHP 8.4.

Changelog Entry

Fixed - Prevent fatal error in Instant Results facets when ep_facet_include_taxonomies returns non-WP_Taxonomy values.

Credits

Props @laraib15

Checklist:

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.

@laraib15 thanks for the PR! Do you mind addressing my comment there so we can merge it in 5.3.3?

Comment on lines 632 to 634
if ( ! ( $taxonomy instanceof \WP_Taxonomy ) ) {
continue;
}
Copy link
Member

Choose a reason for hiding this comment

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

Instead of silently continuing here, let's add a _doing_it_wrong() call, so developers can know something is going wrong. You can follow what we do here.

It would be awesome if we could also add a unit test for this method (and this _doing_it_wrong call) to the tests/php/features/TestInstantResults.php file.

Copy link
Author

Choose a reason for hiding this comment

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

Hi! I’ve implemented the requested change.

Added a _doing_it_wrong() call when ep_facet_include_taxonomies returns an invalid taxonomy (includes the taxonomy slug in the message; version set to ElasticPress 5.3.2).

Added a unit test in tests/php/features/TestInstantResults.php

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, @laraib15! I have linters running now, but I can already say some indentations there will need to be fixed (you can see the misalignment when you check your code here on GitHub)

Also, the next version is actually 5.3.3 and not 5.3.2, as you added. Mind making those changes, please? (It is worth waiting for GitHub Actions to run, just in case there is something else.)

Copy link
Author

Choose a reason for hiding this comment

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

@felipeelia i have pushed the fixes. Please take a look when you get a chance.

@felipeelia felipeelia added this to the 5.4.1 milestone Jan 9, 2026
@laraib15 laraib15 requested a review from felipeelia January 16, 2026 15:10
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.

BUG: Fatal error in Instant Results facets when ep_facet_include_taxonomies contains a taxonomy slug string (e.g. internal_tags)

2 participants