Skip to content

Commit 750607f

Browse files
committed
Set asset version based on parent
1 parent 3a06a47 commit 750607f

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

php/class-assets.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ public function update_asset_paths() {
440440

441441
// Check and update version if needed.
442442
if ( $this->media->get_post_meta( $asset_path->ID, Sync::META_KEYS['version'], true ) !== $version ) {
443+
$this->purge_parent( $asset_path->ID );
443444
$this->media->update_post_meta( $asset_path->ID, Sync::META_KEYS['version'], $version );
444445
}
445446
}

php/class-media.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Cloudinary;
99

10+
use Cloudinary\Assets;
1011
use Cloudinary\Component\Setup;
1112
use Cloudinary\Connect\Api;
1213
use Cloudinary\Media\Filter;
@@ -2963,9 +2964,17 @@ public function apply_srcset( $content, $attachment_id, $overwrite_transformatio
29632964
public function get_cloudinary_version( $attachment_id ) {
29642965
$version = (int) $this->get_post_meta( $attachment_id, Sync::META_KEYS['version'], true );
29652966

2967+
if ( empty( $version ) ) {
2968+
// This might be also an asset from the hidden post type (Assets::POST_TYPE_SLUG).
2969+
$attachment = get_post( $attachment_id );
2970+
2971+
if ( ! empty( $attachment ) && Assets::POST_TYPE_SLUG === $attachment->post_type && ! empty( $attachment->post_parent ) ) {
2972+
$version = (int) preg_replace( '/\D/', '', $this->get_post_meta( (int) $attachment->post_parent, Sync::META_KEYS['version'], true ) );
2973+
}
2974+
}
2975+
29662976
return $version ? $version : 1;
29672977
}
2968-
29692978
/**
29702979
* Upgrade media related settings, including global transformations etc.
29712980
*

0 commit comments

Comments
 (0)