Skip to content

Commit 5082fdb

Browse files
Verify blog id on multisite before asset parent deletion
1 parent 506feb9 commit 5082fdb

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

php/class-assets.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,12 +494,20 @@ protected function activate_parents() {
494494
}
495495
}
496496
}
497+
498+
$blog_id = get_current_blog_id();
499+
497500
// Get the disabled items.
498501
foreach ( $this->asset_parents as $url => $parent ) {
499502
if ( isset( $this->active_parents[ $url ] ) ) {
500503
continue;
501504
}
502505

506+
// If the parent is from another site on a multisite instance, skip it.
507+
if ( isset( $parent->blog_id ) && $parent->blog_id !== $blog_id ) {
508+
continue;
509+
}
510+
503511
if ( ! $this->is_post_cloudinary_asset( $parent->ID ) ) {
504512
continue;
505513
}
@@ -575,7 +583,8 @@ public function create_asset_parent( $path, $version ) {
575583
if ( $parent_id ) {
576584
$this->media->update_post_meta( $parent_id, Sync::META_KEYS['version'], $version );
577585
$this->media->update_post_meta( $parent_id, self::META_KEYS['excludes'], array() );
578-
$this->asset_parents[ $path ] = get_post( $parent_id );
586+
587+
$this->assign_asset_parent( get_post( $parent_id ) );
579588
}
580589

581590
return $parent_id;
@@ -984,7 +993,7 @@ protected function init_asset_parents() {
984993

985994
do {
986995
foreach ( $query->get_posts() as $post ) {
987-
$this->asset_parents[ $post->post_title ] = $post;
996+
$this->assign_asset_parent( $post );
988997
}
989998
$args = $query->query_vars;
990999
++$args['paged'];
@@ -1773,4 +1782,19 @@ protected function add_external_settings() {
17731782

17741783
return $params;
17751784
}
1785+
1786+
/**
1787+
* Assign a parent asset to the asset parents array.
1788+
* If this is a multisite installation, also assign the current blog ID to the post object for later checks.
1789+
*
1790+
* @param \WP_Post $post The post to assign.
1791+
* @return void
1792+
*/
1793+
protected function assign_asset_parent( $post ) {
1794+
if ( is_multisite() ) {
1795+
$post->blog_id = get_current_blog_id();
1796+
}
1797+
1798+
$this->asset_parents[ $post->post_title ] = $post;
1799+
}
17761800
}

0 commit comments

Comments
 (0)