Skip to content

fix: sync posts to Elasticsearch when Post Search is disabled#4325

Open
faisalahammad wants to merge 1 commit into
10up:developfrom
faisalahammad:fix/4158-post-sync-without-search
Open

fix: sync posts to Elasticsearch when Post Search is disabled#4325
faisalahammad wants to merge 1 commit into
10up:developfrom
faisalahammad:fix/4158-post-sync-without-search

Conversation

@faisalahammad

Copy link
Copy Markdown

Summary

Move the Post indexable activation out of the Post Search feature setup() so posts continue to sync to Elasticsearch even when the Post Search feature is disabled.

Previously, disabling Post Search prevented Post::setup() from being called, which meant the SyncManager was never instantiated and wp_insert_post / delete_post / meta / term hooks were never attached.

Fixes #4158

Changes

includes/classes/Features.php

Before:

do_action( 'ep_setup_features' );

foreach ( $this->registered_features as $feature ) {

After:

do_action( 'ep_setup_features' );

/**
 * Activate the post indexable regardless of whether the Post Search
 * feature is enabled, so posts continue to sync to Elasticsearch.
 */
Indexables::factory()->activate( 'post' );

foreach ( $this->registered_features as $feature ) {

Why: setup_features() runs on init priority 0 for every request. Activating the post indexable here ensures it is always set up, independent of whether the Search feature is active.

includes/classes/Feature/Search/Search.php

Before:

public function setup() {
    Indexables::factory()->activate( 'post' );

    add_action( 'init', [ $this, 'search_setup' ] );
    // ...
}

After:

public function setup() {
    add_action( 'init', [ $this, 'search_setup' ] );
    // ...
}

Why: The Search feature no longer needs to activate the post indexable. Its setup() still loads weighting, synonyms, and registers search_setup for query integration.

Testing

Test 1: Post sync with Post Search disabled

  1. Activate ElasticPress and connect to Elasticsearch.
  2. Go to ElasticPress → Features and disable Post Search.
  3. Edit any post and save.
  4. Verify the document in Elasticsearch reflects the updated content.

Result: works as expected.

Test 2: Post sync with Post Search enabled (regression)

  1. Enable Post Search.
  2. Edit and save a post.
  3. Verify the document in Elasticsearch updates.

Result: works as expected.

Test 3: Automated regression test
Added tests/php/indexables/TestPostSyncWithoutSearch.php with testPostSyncWithSearchDisabled() — disables the Search feature, creates a post, and asserts the sync hook fires and the document exists in Elasticsearch. Passes on single-site and multisite test suites.

Move the post indexable activation out of the Post Search feature
setup so posts continue to sync even when that feature is disabled.
Previously, disabling Post Search prevented the Post indexable's
SyncManager from being instantiated, so wp_insert_post / delete_post /
meta / term hooks were never attached.

Fixes 10up#4158
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: Post doesn't update in Elasticsearch when "Post Search" is disabled

1 participant