Skip to content

Commit 428b197

Browse files
committed
swap image source for images and other assets
1 parent 7ff62e5 commit 428b197

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,13 @@ public function get_signature( $attachment_id, $cached = true ) {
286286
public function generate_public_id( $attachment_id ) {
287287

288288
$cld_folder = $this->managers['media']->get_cloudinary_folder();
289-
$file = wp_get_original_image_path( $attachment_id );
290-
$file_info = pathinfo( $file );
291-
$public_id = $cld_folder . $file_info['filename'];
289+
if ( wp_attachment_is_image( $attachment_id ) ) {
290+
$file = wp_get_original_image_path( $attachment_id );
291+
} else {
292+
$file = get_attached_file( $attachment_id );
293+
}
294+
$file_info = pathinfo( $file );
295+
$public_id = $cld_folder . $file_info['filename'];
292296

293297
return ltrim( $public_id, '/' );
294298
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,12 @@ public function upload( $attachment_id, $args, $headers = array(), $try_remote =
410410
$url = $this->url( $resource, 'upload', true );
411411
$args = $this->clean_args( $args );
412412
$disable_https_fetch = get_transient( '_cld_disable_http_upload' );
413-
$file_url = wp_get_original_image_url( $attachment_id );
414-
$media = get_plugin_instance()->get_component( 'media' );
413+
if ( wp_attachment_is_image( $attachment_id ) ) {
414+
$file_url = wp_get_original_image_url( $attachment_id );
415+
} else {
416+
$file_url = wp_get_attachment_url( $attachment_id );
417+
}
418+
$media = get_plugin_instance()->get_component( 'media' );
415419
if ( $media && $media->is_cloudinary_url( $file_url ) ) {
416420
// If this is a Cloudinary URL, then we can use it to fetch from that location.
417421
$disable_https_fetch = false;

0 commit comments

Comments
 (0)