@@ -455,7 +455,7 @@ public function upload_large( $attachment_id, $args ) {
455455 if ( is_wp_error ( $ result ) ) {
456456 break ;
457457 }
458- $ index ++ ;
458+ ++ $ index ;
459459 }
460460 fclose ( $ src ); //phpcs:ignore
461461 unlink ( $ temp_file_name ); //phpcs:ignore
@@ -464,7 +464,6 @@ public function upload_large( $attachment_id, $args ) {
464464 }
465465
466466 return $ result ;
467-
468467 }
469468
470469 /**
@@ -505,7 +504,20 @@ public function upload( $attachment_id, $args, $headers = array(), $try_remote =
505504 $ args = $ this ->clean_args ( $ args );
506505 $ disable_https_fetch = get_transient ( '_cld_disable_http_upload ' );
507506
508- if ( function_exists ( 'wp_get_original_image_url ' ) && wp_attachment_is_image ( $ attachment_id ) ) {
507+ /**
508+ * Whether to use the original image URL.
509+ *
510+ * @hook cloudinary_use_original_image
511+ * @since 3.1.8
512+ * @default true
513+ *
514+ * @param $use_original {bool} The default value.
515+ * @param $attachment_id {int} The attachment ID.
516+ *
517+ * @return {bool}
518+ */
519+ $ use_original = apply_filters ( 'cloudinary_use_original_image ' , true , $ attachment_id );
520+ if ( $ use_original && function_exists ( 'wp_get_original_image_url ' ) && wp_attachment_is_image ( $ attachment_id ) ) {
509521 $ file_url = wp_get_original_image_url ( $ attachment_id );
510522 } else {
511523 $ file_url = wp_get_attachment_url ( $ attachment_id );
@@ -535,7 +547,7 @@ public function upload( $attachment_id, $args, $headers = array(), $try_remote =
535547 // We should have the file in args at this point, but if the transient was set, it will be defaulting here.
536548 if ( empty ( $ args ['file ' ] ) ) {
537549 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 ' ;
550+ $ get_path_func = $ use_original && function_exists ( 'wp_get_original_image_path ' ) ? 'wp_get_original_image_path ' : 'get_attached_file ' ;
539551 $ args ['file ' ] = call_user_func ( $ get_path_func , $ attachment_id );
540552 } else {
541553 $ args ['file ' ] = get_attached_file ( $ attachment_id );
@@ -898,7 +910,7 @@ public function get_public_id( $attachment_id, $args = array(), $original_public
898910 )
899911 ) {
900912
901- $ parts = explode ( '/ ' , $ public_id );
913+ $ parts = explode ( '/ ' , $ public_id );
902914 $ filename = end ( $ parts );
903915
904916 /**
@@ -1010,5 +1022,4 @@ private function call( $url, $args = array(), $method = 'get' ) {
10101022
10111023 return $ result ;
10121024 }
1013-
10141025}
0 commit comments