Skip to content

Guard Instant Results facets against invalid taxonomy values - #4255

Merged
felipeelia merged 5 commits into
10up:developfrom
laraib15:fix/instant-results-taxonomy-guard
Feb 6, 2026
Merged

felipeelia merged 5 commits into
10up:developfrom
laraib15:fix/instant-results-taxonomy-guard

Conversation

@laraib15

@laraib15 laraib15 commented Jan 1, 2026

Copy link
Copy Markdown
Contributor

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:

@felipeelia felipeelia left a comment

Copy link
Copy Markdown
Member

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 thread includes/classes/Feature/InstantResults/InstantResults.php
@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
@felipeelia felipeelia self-assigned this Jan 21, 2026

@felipeelia felipeelia left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We're almost there, @laraib15! just this last detail and we should be done

Comment thread tests/php/features/TestInstantResults.php Outdated
@laraib15
laraib15 force-pushed the fix/instant-results-taxonomy-guard branch from ed7f62b to e80dd18 Compare January 30, 2026 14:43
@felipeelia
felipeelia merged commit 0852719 into 10up:develop Feb 6, 2026
20 of 35 checks passed
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