Skip to content
Merged
Show file tree
Hide file tree
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
19 changes: 16 additions & 3 deletions php/class-media.php
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ public function get_transformation( $transformations, $type ) {
public function get_transformations( $attachment_id, $transformations = array(), $overwrite_transformations = false ) {
static $cache = array();

$key = wp_json_encode( func_get_args() );
$key = $this->get_cache_key( func_get_args() );
if ( isset( $cache[ $key ] ) ) {
return $cache[ $key ];
}
Expand Down Expand Up @@ -861,7 +861,7 @@ public function attachment_url( $url, $attachment_id ) {
public function apply_default_transformations( array $transformations, $attachment_id ) {
static $cache = array(), $freeform = array();

$key = wp_json_encode( func_get_args() );
$key = $this->get_cache_key( func_get_args() );
if ( isset( $cache[ $key ] ) ) {
return $cache[ $key ];
}
Expand Down Expand Up @@ -977,6 +977,19 @@ public function default_image_freeform_transformations( $default ) {
return $default;
}

/**
* Get a cache key for static caching.
*
* @param array $args The arguments array to generate a key with.
*
* @return string
*/
protected function get_cache_key( $args ) {
$args[] = $this->global_transformations->get_current_post();

return md5( wp_json_encode( $args ) );
}

/**
* Generate a Cloudinary URL based on attachment ID and required size.
*
Expand All @@ -997,7 +1010,7 @@ public function cloudinary_url( $attachment_id, $size = array(), $transformation
return null;
}
}
$key = wp_json_encode( func_get_args() );
$key = $this->get_cache_key( func_get_args() );
if ( isset( $cache[ $key ] ) ) {
return $cache[ $key ];
}
Expand Down
2 changes: 1 addition & 1 deletion php/delivery/class-lazy-load.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function add_features( $tag_element, $attachment_id, $original_tag ) {
}
$src = $tag_element['atts']['src'];
if ( ! $this->media->is_cloudinary_url( $src ) ) {
$src = $this->media->cloudinary_url( $attachment_id );
$src = $this->media->cloudinary_url( $attachment_id, array(), array(), array(), $tag_element['cld-overwrite'] );
}
$tag_element['atts']['data-src'] = $src;
$transformations = $this->media->get_transformations_from_string( $src );
Expand Down
2 changes: 1 addition & 1 deletion php/delivery/class-responsive-breakpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected function setup_hooks() {
public function add_features( $tag_element, $attachment_id, $original_tag ) {

if ( ! $this->media->is_cloudinary_url( $tag_element['atts']['src'] ) ) {
$tag_element['atts']['src'] = $this->media->cloudinary_url( $attachment_id );
$tag_element['atts']['src'] = $this->media->cloudinary_url( $attachment_id, array(), array(), array(), $tag_element['cld-overwrite'] );
}
$transformations = $this->media->get_transformations_from_string( $tag_element['atts']['src'] );
$original_string = Api::generate_transformation_string( $transformations );
Expand Down
4 changes: 2 additions & 2 deletions php/media/class-global-transformations.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,14 +575,14 @@ public function save_overwrite_transformations_featured_image( $post_id ) {
*
* @return WP_Post|null
*/
protected function get_current_post() {
public function get_current_post() {
/**
* Filter the post ID.
*
* @hook cloudinary_current_post_id
* @default null
*
* @return {WP_Post|null}
* @return {WP_Post|null}
*/
$post_id = apply_filters( 'cloudinary_current_post_id', null );

Expand Down