Skip to content

Commit 9efaffa

Browse files
authored
Merge pull request #703 from cloudinary/fix/check-seo-url
`images` string might not be the first
2 parents dfc19ec + a81d3de commit 9efaffa

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

php/class-media.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,9 +649,11 @@ public function get_public_id_from_url( $url, $as_sync_key = false ) {
649649
$path = wp_parse_url( $url, PHP_URL_PATH );
650650
$parts = explode( '/', ltrim( $path, '/' ) );
651651

652+
$maybe_seo = array();
653+
652654
// Need to find the version part as anything after this is the public id.
653655
foreach ( $parts as $part ) {
654-
array_shift( $parts ); // Get rid of the first element.
656+
$maybe_seo[] = array_shift( $parts ); // Get rid of the first element.
655657
if ( 'v' === substr( $part, 0, 1 ) && is_numeric( substr( $part, 1 ) ) ) {
656658
break; // Stop removing elements.
657659
}
@@ -662,7 +664,7 @@ public function get_public_id_from_url( $url, $as_sync_key = false ) {
662664
$path_info = Utils::pathinfo( $file );
663665

664666
// Is SEO friendly URL.
665-
if ( 0 === strpos( $path, '/images/' ) ) {
667+
if ( in_array( 'images', $maybe_seo, true ) ) {
666668
$public_id = $path_info['dirname'];
667669
} else {
668670
$public_id = isset( $path_info['dirname'] ) && '.' !== $path_info['dirname'] ? $path_info['dirname'] . DIRECTORY_SEPARATOR . $path_info['filename'] : $path_info['filename'];

0 commit comments

Comments
 (0)