Skip to content

Commit

Permalink
Merge pull request #2022 from ThemeFuse/issue#27673
Browse files Browse the repository at this point in the history
Replaces the CDN domain in the image URL with the server's domain
  • Loading branch information
alecszaharia authored Dec 10, 2024
2 parents 262af92 + 662b4d2 commit 50c8580
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions editor/crop-cache-media.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,31 @@ private function getImgUrlByWpSize( $uid, $size ) {
$imgUrl = $this->getImgUrlByWpSize( $uid, 'full' );
}

return $imgUrl;
}
return $this->replaceCdnUrl($imgUrl);
}

/**
* Replaces the CDN domain in the image URL with the server's domain.
*
* @param string $imgUrl The original image URL.
* @return string The updated image URL with the server domain and without query parameters.
*/
private function replaceCdnUrl($imgUrl) {
$server_domain = site_url();

$parsed_url = parse_url($imgUrl);
$img_domain = $parsed_url['scheme'].'://'.$parsed_url['host'];

$path = isset($parsed_url['path']) ? $parsed_url['path'] : '';

if ($img_domain !== $server_domain) {
$imgUrl = str_replace($img_domain, $server_domain, $img_domain.$path);
} else {
$imgUrl = $img_domain.$path;
}

return $imgUrl;
}

/**
* @throws Exception
Expand All @@ -259,4 +282,4 @@ public function basename( $originalPath ) {
public function buildPath( ...$parts ) {
return implode( '/', $parts );
}
}
}

0 comments on commit 50c8580

Please sign in to comment.