diff --git a/README.md b/README.md index afd7493..4222d03 100644 --- a/README.md +++ b/README.md @@ -48,3 +48,9 @@ If you really like what we do or want to thank us for our quick work, feel free ## License Mercator Domain Replacements is licensed under the [GPLv3 or later](LICENSE.md). + +## Changelog + +### 1.0.2 + +* Fixed: replace by active current mapped domain only for current sub-site (not use the network domain) \ No newline at end of file diff --git a/mercator-domain-replacements.php b/mercator-domain-replacements.php index 27735d9..2d7ee45 100644 --- a/mercator-domain-replacements.php +++ b/mercator-domain-replacements.php @@ -1,7 +1,7 @@ domain . $current_network->path ); - $domain_mapped = mangle_url( untrailingslashit( $current_site->siteurl ), '', '', $current_site->id ); - if ( $domain_internal === $domain_mapped ) { - return; + $network_domain_internal = untrailingslashit( 'https://' . $current_network->domain . $current_network->path ); + $domain_internal = untrailingslashit( 'https://' . $current_site->domain . $current_site->path ); + $domain_mapped = mangle_url( untrailingslashit( $current_site->siteurl ), '', '', $current_site->id ); + + // Site domain URL + if ( $domain_internal !== $domain_mapped ) { + $this->domains[ $domain_internal ] = $domain_mapped; } - $this->domains[ $domain_internal ] = $domain_mapped; + // Network domain URL + if ( $network_domain_internal !== $domain_mapped ) { + $upload_mapped_url = wp_upload_dir()['baseurl']; + $upload_path = str_replace( $domain_mapped, '', $upload_mapped_url ); + $this->domains[ $network_domain_internal . $upload_path ] = $domain_mapped . $upload_path; + } } /** @@ -92,13 +100,13 @@ public function translate_network_url() { */ public function translate_sites_url() { $site_query = new \WP_Site_Query( - array( + [ 'fields' => 'ids', 'number' => 500, 'public' => '1', 'order' => 'ASC', 'orderby' => 'id', - ) + ] ); $sites = $site_query->get_sites(); @@ -123,7 +131,7 @@ public function translate_sites_url() { $domain_internal = untrailingslashit( $current_site->siteurl ); foreach ( $mappings as $mapping ) { - /** @var $mapping \Mercator\Mapping */ + /** @var \Mercator\Mapping $mapping */ if ( ! $mapping->is_active() ) { continue; } @@ -148,10 +156,10 @@ public function translate_sites_url() { * https://monsite.com > https://mondomain.com * https:\/\/monsite.com > https:\/\/mondomain.com localized in JS * - * @return string - * * @param string $buffer * + * @return string + * * @author Alexandre Sadowski */ public function replace_urls( $buffer ) { @@ -177,10 +185,10 @@ public function replace_urls( $buffer ) { /** * Add backslashes for JS * - * @return string|string[] - * * @param string $content * + * @return string + * * @author Alexandre Sadowski */ private function replace_slashes( $content ) { @@ -190,10 +198,10 @@ private function replace_slashes( $content ) { /** * Transform also URL with ://, without defined scheme * - * @return string|string[] - * * @param string $content * + * @return string + * * @author Alexandre Sadowski */ private function replace_scheme( $content ) {