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 3a697c70f..543e91caa 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 @@ -1021,7 +1021,7 @@ public function down_sync_asset() { if ( $format !== $file_info['extension'] ) { // Format transformation. $this->set_transformation( $transformations, 'fetch_format', $file_info['extension'] ); - $url = $file_info['dirname'] . '/' . $file_info['filename'] . '.' . $format; + $url = $file_info['dirname'] . '/' . $file_info['filename'] . '.' . $file_info['extension']; } // Try to find the Attachment ID in context meta data. $attachment_id = $this->get_id_from_sync_key( $sync_key ); diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/connect/class-api.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/connect/class-api.php index 75c0bbb27..203df4f00 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/connect/class-api.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/connect/class-api.php @@ -236,13 +236,19 @@ public function cloudinary_url( $public_id, $args = array(), $size = array(), $c $args['version'] = 'v1'; } + // Determine if we're dealing with a fetched + // ...or uploaded image and update the URL accordingly. + $asset_endpoint = filter_var( $public_id, FILTER_VALIDATE_URL ) ? 'fetch' : 'upload'; + $url_parts = array( 'https:/', - $this->url( $args['resource_type'], 'upload' ), + $this->url( $args['resource_type'], $asset_endpoint ), ); + if ( ! empty( $args['transformation'] ) ) { $url_parts[] = self::generate_transformation_string( $args['transformation'] ); } + // Add size. if ( ! empty( $size ) && is_array( $size ) ) { if ( true === $clean ) { @@ -252,7 +258,7 @@ public function cloudinary_url( $public_id, $args = array(), $size = array(), $c } $url_parts[] = $args['version']; - + $url_parts[] = $public_id; // Clear out empty parts.