@@ -505,7 +505,20 @@ public function upload( $attachment_id, $args, $headers = array(), $try_remote =
505505 $ args = $ this ->clean_args ( $ args );
506506 $ disable_https_fetch = get_transient ( '_cld_disable_http_upload ' );
507507
508- if ( function_exists ( 'wp_get_original_image_url ' ) && wp_attachment_is_image ( $ attachment_id ) ) {
508+ /**
509+ * Whether to use the original image URL.
510+ *
511+ * @hook cloudinary_use_original_image
512+ * @since 3.1.8
513+ * @default true
514+ *
515+ * @param $use_original {bool} The default value.
516+ * @param $attachment_id {int} The attachment ID.
517+ *
518+ * @return {bool}
519+ */
520+ $ use_original = apply_filters ( 'cloudinary_use_original_image ' , true , $ attachment_id );
521+ if ( $ use_original && function_exists ( 'wp_get_original_image_url ' ) && wp_attachment_is_image ( $ attachment_id ) ) {
509522 $ file_url = wp_get_original_image_url ( $ attachment_id );
510523 } else {
511524 $ file_url = wp_get_attachment_url ( $ attachment_id );
@@ -535,7 +548,7 @@ public function upload( $attachment_id, $args, $headers = array(), $try_remote =
535548 // We should have the file in args at this point, but if the transient was set, it will be defaulting here.
536549 if ( empty ( $ args ['file ' ] ) ) {
537550 if ( wp_attachment_is_image ( $ attachment_id ) ) {
538- $ get_path_func = function_exists ( 'wp_get_original_image_path ' ) ? 'wp_get_original_image_path ' : 'get_attached_file ' ;
551+ $ get_path_func = $ use_original && function_exists ( 'wp_get_original_image_path ' ) ? 'wp_get_original_image_path ' : 'get_attached_file ' ;
539552 $ args ['file ' ] = call_user_func ( $ get_path_func , $ attachment_id );
540553 } else {
541554 $ args ['file ' ] = get_attached_file ( $ attachment_id );
0 commit comments