@@ -140,7 +140,7 @@ class Api {
140140 * @param string The plugin version.
141141 */
142142 public function __construct ( $ connect , $ version ) {
143- $ this ->credentials = $ connect ->get_credentials ();
143+ $ this ->credentials = $ connect ->get_credentials ();
144144 $ this ->plugin_version = $ version ;
145145 // Use CNAME.
146146 if ( ! empty ( $ this ->credentials ['cname ' ] ) ) {
@@ -171,8 +171,12 @@ public function url( $resource, $function = null, $endpoint = false ) {
171171 $ parts [] = $ this ->credentials ['cloud_name ' ];
172172 }
173173
174- $ parts [] = $ resource ;
175- $ parts [] = $ function ;
174+ if ( false === $ endpoint && 'image ' === $ resource ) {
175+ $ parts [] = 'images ' ;
176+ } else {
177+ $ parts [] = $ resource ;
178+ $ parts [] = $ function ;
179+ }
176180
177181 $ parts = array_filter ( $ parts );
178182 $ url = implode ( '/ ' , $ parts );
@@ -222,13 +226,12 @@ function ( $item ) use ( $transformation_index ) {
222226 * Generate a Cloudinary URL.
223227 *
224228 * @param string|null $public_id The Public ID to get a url for.
225- * @param array $args Additional args.
226- * @param array $size The WP Size array.
227- * @param bool $clean Flag to produce a non variable size url.
229+ * @param array $args Additional args.
230+ * @param array $size The WP Size array.
228231 *
229232 * @return string
230233 */
231- public function cloudinary_url ( $ public_id = null , $ args = array (), $ size = array (), $ clean = false ) {
234+ public function cloudinary_url ( $ public_id = null , $ args = array (), $ size = array () ) {
232235
233236 if ( null === $ public_id ) {
234237 return 'https:// ' . $ this ->url ( null , null );
@@ -405,7 +408,7 @@ public function upload( $attachment_id, $args, $headers = array() ) {
405408 $ url = $ this ->url ( $ resource , 'upload ' , true );
406409 $ args = $ this ->clean_args ( $ args );
407410 $ disable_https_fetch = get_transient ( '_cld_disable_http_upload ' );
408- $ file_url = wp_get_attachment_url ( $ attachment_id );
411+ $ file_url = wp_get_original_image_url ( $ attachment_id );
409412 $ media = get_plugin_instance ()->get_component ( 'media ' );
410413 if ( $ media && $ media ->is_cloudinary_url ( $ file_url ) ) {
411414 // If this is a Cloudinary URL, then we can use it to fetch from that location.
@@ -417,7 +420,7 @@ public function upload( $attachment_id, $args, $headers = array() ) {
417420 } else {
418421 // We should have the file in args at this point, but if the transient was set, it will be defaulting here.
419422 if ( empty ( $ args ['file ' ] ) ) {
420- $ args ['file ' ] = get_attached_file ( $ attachment_id );
423+ $ args ['file ' ] = wp_get_original_image_path ( $ attachment_id );
421424 }
422425 // Headers indicate chunked upload.
423426 if ( empty ( $ headers ) ) {
@@ -453,7 +456,7 @@ public function upload( $attachment_id, $args, $headers = array() ) {
453456 // Hook in flag to allow for non accessible URLS.
454457 if ( is_wp_error ( $ result ) ) {
455458 $ error = $ result ->get_error_message ();
456- $ code = $ result ->get_error_code ();
459+ $ code = $ result ->get_error_code ();
457460 /**
458461 * If there's an error and the file is a URL in the error message,
459462 * it's likely due to CURL or the location does not support URL file attachments.
0 commit comments