| @@ -7,8 +7,9 @@ | ||
| 7 | 7 | |
| 8 | 8 | namespace WPE\FaustWP\Replacement; |
| 9 | 9 | |
| 10 | 10 | use function WPE\FaustWP\Settings\faustwp_get_setting; |
| 11 | +use function WPE\FaustWP\Replacement\has_file_extension; | |
| 11 | 12 | |
| 12 | 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 13 | 14 | exit; |
| 14 | 15 | } |
| @@ -40,18 +41,33 @@ | ||
| 40 | 41 | |
| 41 | 42 | return $response; |
| 42 | 43 | } |
| 43 | 44 | |
| 45 | +/** | |
| 46 | + * Replaces the WordPress Site URL with the replacement domain | |
| 47 | + * in 'url' and 'href' fields, skipping over values with file extensions. | |
| 48 | + * | |
| 49 | + * @param array $data The response data. | |
| 50 | + */ | |
| 44 | 51 | function url_replace_recursive( &$data ) { |
| 45 | 52 | foreach ( $data as $key => &$value ) { |
| 46 | - if ( $key === 'generalSettings' ) { | |
| 53 | + // Exclude generalSettings from URL replacement. | |
| 54 | + if ( 'generalSettings' === $key ) { | |
| 47 | 55 | continue; |
| 48 | 56 | } |
| 49 | 57 | |
| 50 | - if ( ( 'url' === $key || 'href' === $key ) && is_string( $value ) ) { | |
| 58 | + if ( | |
| 59 | + ( 'url' === $key || 'href' === $key ) && | |
| 60 | + is_string( $value ) && | |
| 61 | + ! has_file_extension( $value ) | |
| 62 | + ) { | |
| 51 | 63 | $replacement = faustwp_get_setting( 'frontend_uri', '/' ); |
| 52 | 64 | $value = str_replace( site_url(), $replacement, $value ); |
| 53 | - } else if ( is_array( $value ) ) { | |
| 65 | + } elseif ( ( 'path' === $key && is_multisite() ) && is_string( $value ) ) { | |
| 66 | + $site = get_site(); | |
| 67 | + $subdirectory = untrailingslashit( $site->path ); | |
| 68 | + $value = str_replace( $subdirectory, '', $value ); | |
| 69 | + } elseif ( is_array( $value ) ) { | |
| 54 | 70 | url_replace_recursive( $value ); |
| 55 | 71 | } |
| 56 | 72 | } |
| 57 | 73 | } |