Skip to content

Commit c916459

Browse files
committed
restucture api to use original file and cleanup url format
1 parent 48bad30 commit c916459

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ 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 = get_attached_file( $attachment_id );
289+
$file = wp_get_original_image_path( $attachment_id );
290290
$file_info = pathinfo( $file );
291291
$public_id = $cld_folder . $file_info['filename'];
292292

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)