dfcadc5339
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
29 lines
777 B
PHP
29 lines
777 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace WPMultiCity;
|
|
|
|
final class RestUrlFilter
|
|
{
|
|
public static function register(): void
|
|
{
|
|
\add_filter('rest_url', [self::class, 'preserve_host']);
|
|
}
|
|
|
|
public static function preserve_host(string $url): string
|
|
{
|
|
$host = $_SERVER['HTTP_HOST'] ?? '';
|
|
if ($host === '') {
|
|
return $url;
|
|
}
|
|
$parsed = parse_url($url);
|
|
if ($parsed === false || empty($parsed['scheme'])) {
|
|
return $url;
|
|
}
|
|
$path = $parsed['path'] ?? '';
|
|
$query = isset($parsed['query']) ? '?' . $parsed['query'] : '';
|
|
$fragment = isset($parsed['fragment']) ? '#' . $parsed['fragment'] : '';
|
|
return 'https://' . $host . $path . $query . $fragment;
|
|
}
|
|
}
|