Skip to content

Commit 0998e57

Browse files
author
dugajean
authored
Merge pull request #53 from cloudinary/bug/catch-bad-cloudinary-id
Add check after cloudinary_id filter and see if what's filtered is ok
2 parents 78f736c + beff24e commit 0998e57

File tree

1 file changed

+10
-4
lines changed
  • cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php

1 file changed

+10
-4
lines changed

cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ public function cloudinary_url( $attachment_id, $size = array(), $transformation
571571
'version' => $this->get_post_meta( $attachment_id, Sync::META_KEYS['version'], true ),
572572
'resource_type' => $resource_type,
573573
);
574-
574+
575575
// Check size and correct if string or size.
576576
if ( is_string( $size ) || ( is_array( $size ) && 3 === count( $size ) ) ) {
577577
$intermediate = image_get_intermediate_size( $attachment_id, $size );
@@ -692,6 +692,11 @@ public function cloudinary_id( $attachment_id ) {
692692
* @return string|bool
693693
*/
694694
$cloudinary_id = apply_filters( 'cloudinary_id', $cloudinary_id, $attachment_id );
695+
696+
if ( empty( $cloudinary_id ) ) {
697+
return false;
698+
}
699+
695700
// Cache ID to prevent multiple lookups.
696701
if ( false !== $cloudinary_id ) {
697702
$this->cloudinary_ids[ $attachment_id ] = $cloudinary_id;
@@ -762,10 +767,11 @@ public function image_srcset( $sources, $size_array, $image_src, $image_meta, $a
762767
if ( false === $cloudinary_id ) {
763768
return $sources; // Return WordPress default sources.
764769
}
770+
765771
// Get transformations from URL.
766772
$transformations = $this->get_transformations_from_string( $image_src );
773+
767774
// Use Cloudinary breakpoints for same ratio.
768-
769775
if ( 'on' === $this->plugin->config['settings']['global_transformations']['enable_breakpoints'] && wp_image_matches_ratio( $image_meta['width'], $image_meta['height'], $size_array[0], $size_array[1] ) ) {
770776
$meta = $this->get_post_meta( $attachment_id, Sync::META_KEYS['breakpoints'], true );
771777
if ( ! empty( $meta ) ) {
@@ -801,11 +807,11 @@ function ( $item ) use ( $crop ) {
801807
);
802808
}
803809
krsort( $sources, SORT_NUMERIC );
804-
810+
805811
return $sources;
806812
}
807813
}
808-
814+
809815
// Add the main size as the largest srcset src.
810816
$crop = $this->get_crop_from_transformation( $transformations );
811817
if ( ! empty( $crop ) ) {

0 commit comments

Comments
 (0)