Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions php/class-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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->add_asset_parent( get_post( $parent_id ) );
}

return $parent_id;
Expand Down Expand Up @@ -984,7 +993,7 @@ protected function init_asset_parents() {

do {
foreach ( $query->get_posts() as $post ) {
$this->asset_parents[ $post->post_title ] = $post;
$this->add_asset_parent( $post );
}
$args = $query->query_vars;
++$args['paged'];
Expand Down Expand Up @@ -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 add_asset_parent( $post ) {
if ( is_multisite() ) {
$post->blog_id = get_current_blog_id();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 thought: Stamping blog_id as a dynamic property on WP_Post only works because WP core annotated WP_Post with #[AllowDynamicProperties] (WP 6.4+). On sites running PHP 8.2+ with older WordPress, this triggers deprecation warnings. Which is odd combo anyway.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! It's probably fine if it's just a deprecation warning given the odd combination of WP & PHP version like you said, it's quite unlikely to happen.

}

$this->asset_parents[ $post->post_title ] = $post;
}
}
Loading