From 5082fdb7f5e14b8816330ff287471b01702a38c2 Mon Sep 17 00:00:00 2001 From: Gabriel de Tassigny Date: Fri, 13 Feb 2026 13:54:58 +0100 Subject: [PATCH 1/2] Verify blog id on multisite before asset parent deletion --- php/class-assets.php | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/php/class-assets.php b/php/class-assets.php index 6eed15c9..3fe08085 100644 --- a/php/class-assets.php +++ b/php/class-assets.php @@ -494,12 +494,20 @@ protected function activate_parents() { } } } + + $blog_id = get_current_blog_id(); + // Get the disabled items. foreach ( $this->asset_parents as $url => $parent ) { if ( isset( $this->active_parents[ $url ] ) ) { continue; } + // If the parent is from another site on a multisite instance, skip it. + if ( isset( $parent->blog_id ) && $parent->blog_id !== $blog_id ) { + continue; + } + if ( ! $this->is_post_cloudinary_asset( $parent->ID ) ) { continue; } @@ -575,7 +583,8 @@ public function create_asset_parent( $path, $version ) { if ( $parent_id ) { $this->media->update_post_meta( $parent_id, Sync::META_KEYS['version'], $version ); $this->media->update_post_meta( $parent_id, self::META_KEYS['excludes'], array() ); - $this->asset_parents[ $path ] = get_post( $parent_id ); + + $this->assign_asset_parent( get_post( $parent_id ) ); } return $parent_id; @@ -984,7 +993,7 @@ protected function init_asset_parents() { do { foreach ( $query->get_posts() as $post ) { - $this->asset_parents[ $post->post_title ] = $post; + $this->assign_asset_parent( $post ); } $args = $query->query_vars; ++$args['paged']; @@ -1773,4 +1782,19 @@ protected function add_external_settings() { return $params; } + + /** + * Assign a parent asset to the asset parents array. + * If this is a multisite installation, also assign the current blog ID to the post object for later checks. + * + * @param \WP_Post $post The post to assign. + * @return void + */ + protected function assign_asset_parent( $post ) { + if ( is_multisite() ) { + $post->blog_id = get_current_blog_id(); + } + + $this->asset_parents[ $post->post_title ] = $post; + } } From 25a1be1e97c4a49a26ee8d37db52899d32e3dd09 Mon Sep 17 00:00:00 2001 From: Gabriel de Tassigny Date: Mon, 16 Feb 2026 14:40:30 +0100 Subject: [PATCH 2/2] Rename method --- php/class-assets.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/php/class-assets.php b/php/class-assets.php index 3fe08085..ce4e1bee 100644 --- a/php/class-assets.php +++ b/php/class-assets.php @@ -584,7 +584,7 @@ public function create_asset_parent( $path, $version ) { $this->media->update_post_meta( $parent_id, Sync::META_KEYS['version'], $version ); $this->media->update_post_meta( $parent_id, self::META_KEYS['excludes'], array() ); - $this->assign_asset_parent( get_post( $parent_id ) ); + $this->add_asset_parent( get_post( $parent_id ) ); } return $parent_id; @@ -993,7 +993,7 @@ protected function init_asset_parents() { do { foreach ( $query->get_posts() as $post ) { - $this->assign_asset_parent( $post ); + $this->add_asset_parent( $post ); } $args = $query->query_vars; ++$args['paged']; @@ -1790,7 +1790,7 @@ protected function add_external_settings() { * @param \WP_Post $post The post to assign. * @return void */ - protected function assign_asset_parent( $post ) { + protected function add_asset_parent( $post ) { if ( is_multisite() ) { $post->blog_id = get_current_blog_id(); }