From 205d32c088fbbd01105bfd959dadd72f678709ad Mon Sep 17 00:00:00 2001 From: Siddharth Thevaril Date: Mon, 23 Feb 2026 14:43:06 +0530 Subject: [PATCH 1/2] Fix meta indexing when Post Search feature is disabled --- includes/classes/Indexable/Post/Post.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/includes/classes/Indexable/Post/Post.php b/includes/classes/Indexable/Post/Post.php index e45126fe4..dadbab758 100644 --- a/includes/classes/Indexable/Post/Post.php +++ b/includes/classes/Indexable/Post/Post.php @@ -12,6 +12,7 @@ use WP_User; use ElasticPress\Elasticsearch; use ElasticPress\Indexable; +use ElasticPress\Feature\Search\Weighting; if ( ! defined( 'ABSPATH' ) ) { // @codeCoverageIgnoreStart @@ -852,8 +853,10 @@ public function is_meta_allowed( $meta_key, $post ) { public function filter_allowed_metas( $metas, $post ) { $filtered_metas = []; - $search = \ElasticPress\Features::factory()->get_registered_feature( 'search' ); - if ( $search && ! empty( $search->weighting ) && 'manual' === $search->weighting->get_meta_mode() ) { + $search = \ElasticPress\Features::factory()->get_registered_feature( 'search' ); + $weighting = ( $search && ! empty( $search->weighting ) ) ? $search->weighting : new Weighting(); + + if ( 'manual' === $weighting->get_meta_mode() ) { $filtered_metas = $this->filter_allowed_metas_manual( $metas, $post ); } else { $filtered_metas = $this->filter_allowed_metas_auto( $metas, $post ); @@ -2552,8 +2555,10 @@ protected function filter_allowed_metas_manual( $metas, $post ) { return $filtered_metas; } - $weighting = $search_feature->weighting->get_weighting_configuration_with_defaults(); - $is_searchable = in_array( $search_feature, $search_feature->get_searchable_post_types(), true ); + $weighting_obj = ( $search_feature && ! empty( $search_feature->weighting ) ) ? $search_feature->weighting : new \ElasticPress\Feature\Search\Weighting(); + $weighting = $weighting_obj->get_weighting_configuration_with_defaults(); + $is_searchable = $search_feature && in_array( $post->post_type, $search_feature->get_searchable_post_types(), true ); + if ( empty( $weighting[ $post->post_type ] ) && $is_searchable ) { return $filtered_metas; } From bc97018270c809ada6ca4b3da58e242984281289 Mon Sep 17 00:00:00 2001 From: Siddharth Thevaril Date: Wed, 29 Apr 2026 20:20:53 +0530 Subject: [PATCH 2/2] add unit test --- tests/php/indexables/TestPost.php | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/php/indexables/TestPost.php b/tests/php/indexables/TestPost.php index 42a3ec0de..4cb8e4111 100644 --- a/tests/php/indexables/TestPost.php +++ b/tests/php/indexables/TestPost.php @@ -4040,6 +4040,40 @@ public function testPrepareMetaManual() { ); } + /** + * Test that filter_allowed_metas keeps manual mode when the Search + * feature is disabled (its `weighting` property is unavailable). + * + * @since 5.4.0 + * @group post + */ + public function testPrepareMetaWithSearchDisabled() { + if ( $this->is_network_activate() ) { + $this->markTestSkipped(); + } + + $search = ElasticPress\Features::factory()->get_registered_feature( 'search' ); + $original_weighting = $search->weighting; + $search->weighting = null; + + $post_id = $this->ep_factory->post->create( + [ + 'meta_input' => [ + 'test_key1' => 'allowed value', + 'not_allowed_key1' => 'disallowed value', + ], + ] + ); + + $post = get_post( $post_id ); + $prepared_meta = ElasticPress\Indexables::factory()->get( 'post' )->prepare_meta( $post ); + + $this->assertArrayHasKey( 'test_key1', $prepared_meta ); + $this->assertArrayNotHasKey( 'not_allowed_key1', $prepared_meta ); + + $search->weighting = $original_weighting; + } + /** * Helper method for filtering private meta keys *