⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
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
29 changes: 28 additions & 1 deletion php/class-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,18 +494,37 @@ protected function activate_parents() {
}
}
}

// Get the disabled items.
foreach ( $this->asset_parents as $url => $parent ) {
if ( isset( $this->active_parents[ $url ] ) ) {
continue;
}

if ( ! $this->is_post_cloudinary_asset( $parent->ID ) ) {
continue;
}

$this->purge_parent( $parent->ID );
// Remove parent.
wp_delete_post( $parent->ID );
}
}

/**
* Check if a post is a Cloudinary asset.
*
* @param int $post_id The post ID to check.
*
* @return bool
*/
public function is_post_cloudinary_asset( $post_id ) {
if ( get_post_type( $post_id ) === self::POST_TYPE_SLUG ) {
return true;
}

return false;
}

/**
* Activate a parent asset path.
*
Expand Down Expand Up @@ -569,6 +588,10 @@ public function create_asset_parent( $path, $version ) {
* @param callable $callback The callback function to execute on each post.
*/
private function process_parent_assets( $parent_id, $callback ) {
if ( ! $this->is_post_cloudinary_asset( $parent_id ) ) {
return;
}

$query_args = array(
'post_type' => self::POST_TYPE_SLUG,
'posts_per_page' => 100,
Expand Down Expand Up @@ -626,6 +649,10 @@ public function purge_parent( $parent_id ) {
$this->process_parent_assets(
$parent_id,
function ( $post_id ) {
if ( ! $this->is_post_cloudinary_asset( $post_id ) ) {
return;
}

wp_delete_post( $post_id );
}
);
Expand Down