Skip to content

Commit 5900a08

Browse files
authored
Merge pull request #481 from cloudinary/fix/get-id_from-sync-key
Keep metas that allow getting the ID from given sync keys
2 parents 7af3814 + d101d2b commit 5900a08

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

php/class-delivery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public function process_featured_image( $html, $post_id, $attachment_id ) {
184184
$tag_element['atts']['class'][] = 'wp-image-' . $attachment_id;
185185
$tag_element['atts']['class'][] = 'wp-post-' . $post_id;
186186

187-
if ( true === (bool) $this->media->get_post_meta( $post_id, Global_Transformations::META_FEATURED_IMAGE_KEY, true ) ) {
187+
if ( true === (bool) get_post_meta( $post_id, Global_Transformations::META_FEATURED_IMAGE_KEY, true ) ) {
188188
$tag_element['atts']['class'][] = 'cld-overwrite';
189189
}
190190

php/class-media.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1508,6 +1508,12 @@ private function create_attachment( $asset, $public_id ) {
15081508
$this->update_post_meta( $attachment_id, Sync::META_KEYS['transformation'], $asset['transformations'] );
15091509
}
15101510

1511+
// Create a trackable key in post meta to allow getting the attachment id from URL with transformations.
1512+
update_post_meta( $attachment_id, '_' . md5( $sync_key ), true );
1513+
1514+
// Create a trackable key in post meta to allow getting the attachment id from URL.
1515+
update_post_meta( $attachment_id, '_' . md5( 'base_' . $public_id ), true );
1516+
15111517
// capture the delivery type.
15121518
$this->update_post_meta( $attachment_id, Sync::META_KEYS['delivery'], $asset['type'] );
15131519
// Capture the ALT Text.
@@ -2101,7 +2107,7 @@ public function get_upload_options( $attachment_id ) {
21012107
public function maybe_overwrite_featured_image( $attachment_id ) {
21022108
$overwrite = false;
21032109
if ( $this->doing_featured_image && $this->doing_featured_image === (int) $attachment_id ) {
2104-
$overwrite = (bool) $this->get_post_meta( get_the_ID(), Global_Transformations::META_FEATURED_IMAGE_KEY, true );
2110+
$overwrite = (bool) get_post_meta( get_the_ID(), Global_Transformations::META_FEATURED_IMAGE_KEY, true );
21052111
}
21062112

21072113
return $overwrite;

php/media/class-upgrade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ public function convert_cloudinary_version( $attachment_id ) {
142142
if ( ! empty( $transformations ) ) {
143143
$sync_key .= wp_json_encode( $transformations );
144144
}
145-
delete_post_meta( $attachment_id, '_' . md5( $sync_key ), true );
146-
delete_post_meta( $attachment_id, '_' . md5( 'base_' . $public_id ), true );
145+
update_post_meta( $attachment_id, '_' . md5( $sync_key ), true );
146+
update_post_meta( $attachment_id, '_' . md5( 'base_' . $public_id ), true );
147147
// Get a new uncached signature.
148148
$this->sync->get_signature( $attachment_id, true );
149149

php/sync/class-upload-sync.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,13 @@ function ( $is_synced, $post_id ) use ( $attachment_id ) {
282282
$this->media->update_post_meta( $attachment_id, Sync::META_KEYS['version'], $result['version'] );
283283
// Set the delivery type.
284284
$this->media->update_post_meta( $attachment_id, Sync::META_KEYS['delivery'], $result['type'] );
285+
286+
// Create a trackable key in post meta to allow getting the attachment id from URL with transformations.
287+
update_post_meta( $attachment_id, '_' . md5( $options['public_id'] ), true );
288+
289+
// Create a trackable key in post meta to allow getting the attachment id from URL.
290+
update_post_meta( $attachment_id, '_' . md5( 'base_' . $options['public_id'] ), true );
291+
285292
// Update signature for all that use the same method.
286293
$this->sync->sync_signature_by_type( $attachment_id, $type );
287294
// Update options and public_id as well (full sync).

0 commit comments

Comments
 (0)