Skip to content

Commit 1043075

Browse files
authored
Merge pull request #403 from cloudinary/fix/cloudinary-only-storage-transformations
Fix cloudinary only storage transformations
2 parents e8037dc + d699519 commit 1043075

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

php/class-media.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,31 @@ public function is_cloudinary_url( $url ) {
13701370
return $test_parts['host'] === $cld_url;
13711371
}
13721372

1373+
/**
1374+
* Check if a url is pointing to Cloudinary sync folder.
1375+
*
1376+
* @param string $url The tested URL.
1377+
*
1378+
* @return bool
1379+
*/
1380+
public function is_cloudinary_sync_folder( $url ) {
1381+
$path = wp_parse_url( $url, PHP_URL_PATH );
1382+
$parts = explode( '/', $path );
1383+
1384+
// Remove public id and file name.
1385+
array_splice( $parts, -2 );
1386+
1387+
foreach ( $parts as $part ) {
1388+
array_shift( $parts );
1389+
if ( 'v' === $part[0] && is_numeric( substr( $part, 1 ) ) ) {
1390+
break;
1391+
}
1392+
}
1393+
1394+
// Check for the Cloudinary folder.
1395+
return implode( '/', $parts ) === $this->get_cloudinary_folder( false );
1396+
}
1397+
13731398
/**
13741399
* Add media tab template.
13751400
*/

php/media/class-filter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,8 @@ public function filter_out_local( $content, $tags = 'img' ) {
318318
$url = $this->get_url_from_tag( $asset );
319319
$attachment_id = $this->get_id_from_tag( $asset );
320320

321-
// Check if this is not already a cloudinary url.
322-
if ( $this->media->is_cloudinary_url( $url ) ) {
321+
// Check if this is not already a cloudinary url and if is not in the sync folder, for Cloudinary only storage cases.
322+
if ( $this->media->is_cloudinary_url( $url ) && ! $this->media->is_cloudinary_sync_folder( $url ) ) {
323323
// Is a content based ID. If has a cloudinary ID, it's from an older plugin version.
324324
// Check if has an ID, and push update to reset.
325325
if ( ! empty( $attachment_id ) && ! $this->media->plugin->components['sync']->is_synced( $attachment_id ) ) {

0 commit comments

Comments
 (0)