Customize: Don't let hardcoded regex override customize_allowed_urls filter - #11459
Customize: Don't let hardcoded regex override customize_allowed_urls filter#11459abhi3315 wants to merge 2 commits into
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Replace the hardcoded wp-(admin|includes|content) regex in the preview and controls scripts with path prefixes derived from the URLs served by WordPress, so the Customizer preview works for sites installed in a subdirectory under wp-content. See #65030.
9c6eb3a to
af401a8
Compare
Build the URL replacements from home_url() instead of hardcoding example.org, so the tests pass when WP_TESTS_DOMAIN includes a port. See #65030.
Trac ticket: https://core.trac.wordpress.org/ticket/65030
Summary
The Customizer decides link previewability with a hardcoded
/\/wp-(admin|includes|content)(\/|$)/regex, which blocks the preview for sites whose home URL path contains/wp-content/, even when the URL is allowed viacustomize_allowed_urls. This PR exports the non-previewable path prefixes from PHP to JS instead, following the approach ofWP_URL_Pattern_Prefixer::get_default_contexts().WP_Customize_Manager::get_excluded_url_paths()derives prefixes fromadmin_url(),includes_url(),content_url(),plugins_url(), andwp_get_upload_dir(), exported asurl.excludedPathsin both settings payloads. URLs on another host (e.g. CDN-filtered uploads) and paths at or above the home path are skipped.wp.customize.utils.isExcludedPath()incustomize-base.jsis the single matcher used byisLinkPreviewable()and thepreviewUrlsetter. Prefixes are anchored to the start of the pathname, repeated slashes are collapsed, and it falls back to the old regex when no paths are supplied.wp-login.php/wp-signup.phpandadmin-ajax.phpchecks are unchanged (filename-based, subdirectory-safe).A site installed at
/wp-content/subsite/now exports/wp-content/subsite/wp-admin/etc., so its own home URL no longer collides with any excluded prefix.Behavior changes
Matching is now anchored to this install's real locations rather than
wp-admin/wp-contentappearing anywhere in a path. So: same-host paths of other installs (e.g./site2/wp-admin/from a subdirectory multisite main site) become previewable, front-end permalinks like/blog/wp-content/are no longer wrongly blocked, and relocated content directories are now correctly excluded. Filtered URL functions are trusted as-is (a renamed admin path excludes the renamed path, not the literal/wp-admin/).Tests
PHPUnit: default paths contract, the subdirectory repro, the guards, and export wiring (passes single-site and multisite). QUnit: new module covering the JS matcher.
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Fable 5
Used for: Analysis, implementation, and test writing. Final implementation reviewed and verified by me.