From 428b19716a95aa6b0856441642631a9263bb360b Mon Sep 17 00:00:00 2001 From: David Cramer Date: Wed, 30 Sep 2020 16:10:34 +0200 Subject: [PATCH] swap image source for images and other assets --- .../php/class-sync.php | 10 +++++++--- .../php/connect/class-api.php | 8 ++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-sync.php b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-sync.php index badb76417..79668630b 100644 --- a/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-sync.php +++ b/cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/class-sync.php @@ -286,9 +286,13 @@ public function get_signature( $attachment_id, $cached = true ) { public function generate_public_id( $attachment_id ) { $cld_folder = $this->managers['media']->get_cloudinary_folder(); - $file = wp_get_original_image_path( $attachment_id ); - $file_info = pathinfo( $file ); - $public_id = $cld_folder . $file_info['filename']; + if ( wp_attachment_is_image( $attachment_id ) ) { + $file = wp_get_original_image_path( $attachment_id ); + } else { + $file = get_attached_file( $attachment_id ); + } + $file_info = pathinfo( $file ); + $public_id = $cld_folder . $file_info['filename']; return ltrim( $public_id, '/' ); } 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 e44826427..cd115b0f4 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 @@ -410,8 +410,12 @@ public function upload( $attachment_id, $args, $headers = array(), $try_remote = $url = $this->url( $resource, 'upload', true ); $args = $this->clean_args( $args ); $disable_https_fetch = get_transient( '_cld_disable_http_upload' ); - $file_url = wp_get_original_image_url( $attachment_id ); - $media = get_plugin_instance()->get_component( 'media' ); + if ( wp_attachment_is_image( $attachment_id ) ) { + $file_url = wp_get_original_image_url( $attachment_id ); + } else { + $file_url = wp_get_attachment_url( $attachment_id ); + } + $media = get_plugin_instance()->get_component( 'media' ); if ( $media && $media->is_cloudinary_url( $file_url ) ) { // If this is a Cloudinary URL, then we can use it to fetch from that location. $disable_https_fetch = false;