Skip to content

Commit 731a030

Browse files
committed
add try_remote param
1 parent 85d6392 commit 731a030

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class Api {
141141
* @param string The plugin version.
142142
*/
143143
public function __construct( $connect, $version ) {
144-
$this->credentials = $connect->get_credentials();
144+
$this->credentials = $connect->get_credentials();
145145
$this->plugin_version = $version;
146146
// Use CNAME.
147147
if ( ! empty( $this->credentials['cname'] ) ) {
@@ -231,9 +231,9 @@ function ( $item ) use ( $transformation_index ) {
231231
* Generate a Cloudinary URL.
232232
*
233233
* @param string|null $public_id The Public ID to get a url for.
234-
* @param array $args Additional args.
235-
* @param array $size The WP Size array.
236-
* @param bool $clean Flag to produce a non variable size url.
234+
* @param array $args Additional args.
235+
* @param array $size The WP Size array.
236+
* @param bool $clean Flag to produce a non variable size url.
237237
*
238238
* @return string
239239
*/
@@ -408,10 +408,11 @@ public function upload_large( $attachment_id, $args ) {
408408
* @param int $attachment_id Attachment ID to upload.
409409
* @param array $args Array of upload options.
410410
* @param array $headers Additional headers to use in upload.
411+
* @param bool $try_remote Flag to try_remote upload.
411412
*
412413
* @return array|\WP_Error
413414
*/
414-
public function upload( $attachment_id, $args, $headers = array() ) {
415+
public function upload( $attachment_id, $args, $headers = array(), $try_remote = true ) {
415416

416417
$resource = ! empty( $args['resource_type'] ) ? $args['resource_type'] : 'image';
417418
$resource = $this->convert_resource_type( $resource );
@@ -425,7 +426,7 @@ public function upload( $attachment_id, $args, $headers = array() ) {
425426
$disable_https_fetch = false;
426427
}
427428
// Check if we can try http file upload.
428-
if ( empty( $headers ) && empty( $disable_https_fetch ) ) {
429+
if ( empty( $headers ) && empty( $disable_https_fetch ) && true === $try_remote ) {
429430
$args['file'] = $file_url;
430431
} else {
431432
// We should have the file in args at this point, but if the transient was set, it will be defaulting here.
@@ -466,7 +467,7 @@ public function upload( $attachment_id, $args, $headers = array() ) {
466467
// Hook in flag to allow for non accessible URLS.
467468
if ( is_wp_error( $result ) ) {
468469
$error = $result->get_error_message();
469-
$code = $result->get_error_code();
470+
$code = $result->get_error_code();
470471
/**
471472
* If there's an error and the file is a URL in the error message,
472473
* it's likely due to CURL or the location does not support URL file attachments.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public function upload_asset( $attachment_id ) {
204204
$type = $this->sync->get_sync_type( $attachment_id );
205205
$options = $this->media->get_upload_options( $attachment_id );
206206
$public_id = $options['public_id'];
207-
$try_remote = 'cloud_name' === $type ? 'file' : false;
207+
$try_remote = 'cloud_name' === $type ? false : true;
208208

209209
// Add the suffix before uploading.
210210
if ( $this->media->get_public_id( $attachment_id ) === $public_id ) {
@@ -216,7 +216,7 @@ public function upload_asset( $attachment_id ) {
216216
}
217217

218218
// Run the upload Call.
219-
$result = $this->connect->api->upload( $attachment_id, $options, $try_remote );
219+
$result = $this->connect->api->upload( $attachment_id, $options, array(), $try_remote );
220220

221221
if ( ! is_wp_error( $result ) ) {
222222

0 commit comments

Comments
 (0)