diff --git a/includes/classes/Indexable/Post/SyncManager.php b/includes/classes/Indexable/Post/SyncManager.php index f15c50fb37..c450719407 100644 --- a/includes/classes/Indexable/Post/SyncManager.php +++ b/includes/classes/Indexable/Post/SyncManager.php @@ -49,11 +49,6 @@ public function setup() { add_action( 'add_attachment', array( $this, 'action_sync_on_update' ), 999, 3 ); add_action( 'edit_attachment', array( $this, 'action_sync_on_update' ), 999, 3 ); add_action( 'delete_post', array( $this, 'action_delete_post' ) ); - add_action( 'delete_blog', array( $this, 'action_delete_blog_from_index' ) ); - add_action( 'make_delete_blog', array( $this, 'action_delete_blog_from_index' ) ); - add_action( 'make_spam_blog', array( $this, 'action_delete_blog_from_index' ) ); - add_action( 'archive_blog', array( $this, 'action_delete_blog_from_index' ) ); - add_action( 'deactivate_blog', array( $this, 'action_delete_blog_from_index' ) ); add_action( 'updated_post_meta', array( $this, 'action_queue_meta_sync' ), 10, 4 ); add_action( 'added_post_meta', array( $this, 'action_queue_meta_sync' ), 10, 4 ); add_action( 'deleted_post_meta', array( $this, 'action_queue_meta_sync' ), 10, 4 ); @@ -154,29 +149,6 @@ public function action_queue_meta_sync( $meta_id, $object_id, $meta_key, $meta_v } } - /** - * Remove blog from index when a site is deleted, archived, or deactivated - * - * @param int $blog_id WP Blog ID. - */ - public function action_delete_blog_from_index( $blog_id ) { - if ( $this->kill_sync() ) { - return; - } - - $indexable = Indexables::factory()->get( $this->indexable_slug ); - - /** - * Filter to whether to keep index on site deletion - * - * @hook ep_keep_index - * @param {bool} $keep True means don't delete index - * @return {boolean} New value - */ - if ( $indexable->index_exists( $blog_id ) && ! apply_filters( 'ep_keep_index', false ) ) { - $indexable->delete_index( $blog_id ); - } - } /** * Delete ES post when WP post is deleted diff --git a/includes/classes/SyncManager.php b/includes/classes/SyncManager.php index 35f6192c26..48f2b3336b 100644 --- a/includes/classes/SyncManager.php +++ b/includes/classes/SyncManager.php @@ -53,6 +53,15 @@ public function __construct( $indexable_slug ) { add_action( 'shutdown', [ $this, 'index_sync_queue' ] ); add_filter( 'wp_redirect', [ $this, 'index_sync_queue_on_redirect' ], 10, 1 ); + /** + * Actions for multisite + */ + add_action( 'delete_blog', array( $this, 'action_delete_blog_from_index' ) ); + add_action( 'make_delete_blog', array( $this, 'action_delete_blog_from_index' ) ); + add_action( 'make_spam_blog', array( $this, 'action_delete_blog_from_index' ) ); + add_action( 'archive_blog', array( $this, 'action_delete_blog_from_index' ) ); + add_action( 'deactivate_blog', array( $this, 'action_delete_blog_from_index' ) ); + // Implemented by children. $this->setup(); } @@ -223,6 +232,35 @@ public function kill_sync() { return apply_filters( 'ep_sync_indexable_kill', $is_importing, $this->indexable_slug ); } + /** + * Remove blog from index when a site is deleted, archived, or deactivated + * + * @param int $blog_id WP Blog ID. + */ + public function action_delete_blog_from_index( $blog_id ) { + if ( $this->kill_sync() ) { + return; + } + + $indexable = Indexables::factory()->get( $this->indexable_slug ); + + // Don't delete global indexes + if ( $indexable->global ) { + return; + } + + /** + * Filter to whether to keep index on site deletion + * + * @hook ep_keep_index + * @param {bool} $keep True means don't delete index + * @return {boolean} New value + */ + if ( $indexable->index_exists( $blog_id ) && ! apply_filters( 'ep_keep_index', false ) ) { + $indexable->delete_index( $blog_id ); + } + } + /** * Implementation should setup hooks/filters *