From beff24e7d2ef74dc08ca3bebc7f430f989bf34bd Mon Sep 17 00:00:00 2001 From: Dukagjin Surdulli Date: Thu, 2 Apr 2020 18:11:12 -0400 Subject: [PATCH] Add check after cloudinary_id filter and see if what's filtered is appropriate --- .../php/class-media.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php index 3c654d76c..da9be2c3b 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-media.php @@ -571,7 +571,7 @@ public function cloudinary_url( $attachment_id, $size = array(), $transformation 'version' => $this->get_post_meta( $attachment_id, Sync::META_KEYS['version'], true ), 'resource_type' => $resource_type, ); - + // Check size and correct if string or size. if ( is_string( $size ) || ( is_array( $size ) && 3 === count( $size ) ) ) { $intermediate = image_get_intermediate_size( $attachment_id, $size ); @@ -692,6 +692,11 @@ public function cloudinary_id( $attachment_id ) { * @return string|bool */ $cloudinary_id = apply_filters( 'cloudinary_id', $cloudinary_id, $attachment_id ); + + if ( empty( $cloudinary_id ) ) { + return false; + } + // Cache ID to prevent multiple lookups. if ( false !== $cloudinary_id ) { $this->cloudinary_ids[ $attachment_id ] = $cloudinary_id; @@ -762,10 +767,11 @@ public function image_srcset( $sources, $size_array, $image_src, $image_meta, $a if ( false === $cloudinary_id ) { return $sources; // Return WordPress default sources. } + // Get transformations from URL. $transformations = $this->get_transformations_from_string( $image_src ); + // Use Cloudinary breakpoints for same ratio. - 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] ) ) { $meta = $this->get_post_meta( $attachment_id, Sync::META_KEYS['breakpoints'], true ); if ( ! empty( $meta ) ) { @@ -801,11 +807,11 @@ function ( $item ) use ( $crop ) { ); } krsort( $sources, SORT_NUMERIC ); - + return $sources; } } - + // Add the main size as the largest srcset src. $crop = $this->get_crop_from_transformation( $transformations ); if ( ! empty( $crop ) ) {