Add tunnel URL rewrite mu-plugin for ngrok support#2960
Draft
Add tunnel URL rewrite mu-plugin for ngrok support#2960
Conversation
Use home_url/site_url filters instead of option_siteurl/option_home, since the option filters are bypassed when WordPress Playground defines these as PHP constants.
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.
Related issues
Proposed Changes
When users tunnel a Studio site via ngrok (or cloudflared, localtunnel, etc.), WordPress redirects all requests back to the configured local site URL. This happens because WordPress's
siteurl/homeoptions are stored as the local domain, and WordPress core'sredirect_canonical()forces all requests to match. Users currently have to manually update WordPress settings — tedious and easy to forget to revert.This PR adds a new
0-tunnel-url-rewrite.phpmu-plugin that dynamically rewrites WordPress URLs when it detects a forwarded request (via theX-Forwarded-Hostheader), requiring zero configuration from the user.The mu-plugin:
X-Forwarded-Hostheader (set by ngrok, cloudflared, and Studio's own proxyxfwd: true)siteurlandhomeusingoption_homeandoption_siteurlfilters — no database changescontent_url,plugins_url,script_loader_src,style_loader_src,rest_url,upload_dir) so all resources load through the tunnelwp_safe_redirectcalls work correctlyThe mu-plugin is always-on but only activates when
X-Forwarded-Hostis present. Normal local browsing is completely unaffected. This is a Proof of Concept — the approach is intentionally minimal (PHP mu-plugin only, no TypeScript/UI/IPC changes).Testing Instructions
npm run cli:buildmywpsite.local) in Studiongrok http http://localhost:<port> --host-header=mywpsite.localmywpsite.local— should work as before (mu-plugin inactive)npm test -- tools/common/lib/tests/mu-plugins.test.tsPre-merge Checklist