Skip to content

Commit c815aa4

Browse files
committed
create a tag key method to keep consistant
1 parent 0eb238b commit c815aa4

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

php/class-media.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ public function get_transformation( $transformations, $type ) {
710710
public function get_transformations( $attachment_id, $transformations = array(), $overwrite_transformations = false ) {
711711
static $cache = array();
712712

713-
$key = wp_json_encode( func_get_args() );
713+
$key = $this->get_cache_key( func_get_args() );
714714
if ( isset( $cache[ $key ] ) ) {
715715
return $cache[ $key ];
716716
}
@@ -861,10 +861,7 @@ public function attachment_url( $url, $attachment_id ) {
861861
public function apply_default_transformations( array $transformations, $attachment_id ) {
862862
static $cache = array(), $freeform = array();
863863

864-
$taxonomy_overwrite = $this->global_transformations->is_taxonomy_overwrite();
865-
$args = func_get_args();
866-
$args[] = $taxonomy_overwrite;
867-
$key = wp_json_encode( $args );
864+
$key = $this->get_cache_key( func_get_args() );
868865
if ( isset( $cache[ $key ] ) ) {
869866
return $cache[ $key ];
870867
}
@@ -980,6 +977,19 @@ public function default_image_freeform_transformations( $default ) {
980977
return $default;
981978
}
982979

980+
/**
981+
* Get a cache key for static caching.
982+
*
983+
* @param array $args The arguments array to generate a key with.
984+
*
985+
* @return string
986+
*/
987+
protected function get_cache_key( $args ) {
988+
$args[] = $this->global_transformations->get_current_post();
989+
990+
return md5( wp_json_encode( $args ) );
991+
}
992+
983993
/**
984994
* Generate a Cloudinary URL based on attachment ID and required size.
985995
*
@@ -1000,7 +1010,7 @@ public function cloudinary_url( $attachment_id, $size = array(), $transformation
10001010
return null;
10011011
}
10021012
}
1003-
$key = wp_json_encode( func_get_args() );
1013+
$key = $this->get_cache_key( func_get_args() );
10041014
if ( isset( $cache[ $key ] ) ) {
10051015
return $cache[ $key ];
10061016
}

php/delivery/class-responsive-breakpoints.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected function setup_hooks() {
5757
public function add_features( $tag_element, $attachment_id, $original_tag ) {
5858

5959
if ( ! $this->media->is_cloudinary_url( $tag_element['atts']['src'] ) ) {
60-
$tag_element['atts']['src'] = $this->media->cloudinary_url( $attachment_id );
60+
$tag_element['atts']['src'] = $this->media->cloudinary_url( $attachment_id, array(), array(), array(), $tag_element['cld-overwrite'] );
6161
}
6262
$transformations = $this->media->get_transformations_from_string( $tag_element['atts']['src'] );
6363
$original_string = Api::generate_transformation_string( $transformations );

php/media/class-global-transformations.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,14 +575,14 @@ public function save_overwrite_transformations_featured_image( $post_id ) {
575575
*
576576
* @return WP_Post|null
577577
*/
578-
protected function get_current_post() {
578+
public function get_current_post() {
579579
/**
580580
* Filter the post ID.
581581
*
582582
* @hook cloudinary_current_post_id
583583
* @default null
584584
*
585-
* @return {WP_Post|null}
585+
* @return {WP_Post|null}
586586
*/
587587
$post_id = apply_filters( 'cloudinary_current_post_id', null );
588588

0 commit comments

Comments
 (0)