Repository navigation
Export: Replace local site URLs with dynamic URLs - #900
Open
TremiDkhar wants to merge 2 commits into
Open
TremiDkhar wants to merge 2 commits into
TremiDkhar wants to merge 2 commits into
Conversation
Templates and patterns saved in the Site Editor keep absolute URLs of the site they were edited on, which break once the theme is installed on another domain. On export, URLs of the current site are now replaced with PHP that rebuilds them at runtime: - Theme files: get_template_directory_uri(), or get_stylesheet_directory_uri() for a child theme's own files. - Other site URLs: home_url() or site_url(), whichever base matches. Covers HTML attributes and block comment JSON, including JSON-escaped URLs. A link written by text localization as esc_url( '...' ) is converted too; other PHP strings are left untouched so translatable text stays extractable. Lookalike hosts, other ports and sibling subdirectory paths are not converted. Enabled by default through a new localizeUrls export option; pass 'localizeUrls' => false to disable.
Cover CBT_Theme_URLs::make_template_urls_local() and the localizeUrls export option: site and theme URLs in HTML and block comment JSON, child themes, home_url() vs site_url() bases, URLs that must not be converted, esc_url() literals from text localization, and the template and pattern export pipelines.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
On export, URLs of the current site in templates, template parts and patterns are replaced with PHP that rebuilds them at runtime, so the theme works on any domain.
get_template_directory_uri(), orget_stylesheet_directory_uri()for a child theme's own files.home_url()orsite_url(), whichever base matches.It covers HTML attributes and block comment JSON, and is not tied to any block. Inside "Localize text" output, only link targets (
esc_url( '…' )) are converted, so translatable strings stay intact. On by default; pass'localizeUrls' => falseto disable.Testing
patterns/<slug>.phpuseshome_url()/get_template_directory_uri()and contains no local URLs.Fixes #805