Skip to content

GH#769: Fix domain mapping option_home filter, rewrite flush after duplication, and SSL scheme hardening#771

Closed
superdav42 wants to merge 1 commit intomainfrom
bugfix/gh769-domain-mapping-fixes
Closed

GH#769: Fix domain mapping option_home filter, rewrite flush after duplication, and SSL scheme hardening#771
superdav42 wants to merge 1 commit intomainfrom
bugfix/gh769-domain-mapping-fixes

Conversation

@superdav42
Copy link
Copy Markdown
Collaborator

@superdav42 superdav42 commented Apr 9, 2026

Summary

Fixes three related domain mapping bugs causing 404 errors on custom post types, broken Elementor preview, and mixed content issues on subsites with mapped domains.

Bug 1: Missing option_home filter (CRITICAL)

register_filters() in inc/class-domain-mapping.php added option_siteurl but not option_home. This meant get_option('home') returned the raw subdomain URL instead of the mapped domain, breaking:

  • CPT permalink resolution → 404
  • Elementor iframe preview → cross-origin block
  • Admin AJAX → mixed content (http vs https)
  • Media library "Load More" → AJAX fails

Fix: Added add_filter('option_home', [$this, 'mangle_url'], 20) after the existing option_siteurl filter at line 493.

Bug 2: No flush_rewrite_rules() after wu_duplicate_site

When UM duplicates a template site, rewrite_rules is copied verbatim. If the template's rules were generated with a different CPT slug, all cloned subsites keep stale rules causing 404s.

Fix: Added flush_rewrite_rules_for_new_site() method in Elementor_Compat hooked on wu_duplicate_site at priority 20 (after regenerate_css). Uses the same switch_to_blog/restore_current_blog pattern as the existing regenerate_css method.

Bug 3: fix_new_site_url_scheme() race condition

On LiteSpeed + Cloudflare setups, get_home_url() can return http:// during site creation before SSL redirect kicks in, causing subsites to be created with http:// siteurl/home.

Fix: Added fallback in fix_new_site_url_scheme() to check FORCE_SSL_ADMIN constant or is_ssl() when get_home_url() returns http://.

Files Changed

  • EDIT: inc/class-domain-mapping.php:493 — add option_home filter
  • EDIT: inc/compat/class-elementor-compat.php:34,67 — add flush_rewrite_rules_for_new_site hook and method
  • EDIT: inc/compat/class-general-compat.php:489 — harden SSL scheme detection

Runtime Testing

Risk level: Medium — domain mapping filters and site initialization hooks.

Self-assessed: Changes follow existing patterns exactly (option_siteurloption_home, regenerate_cssflush_rewrite_rules_for_new_site, existing SSL check → hardened with fallback). No new logic paths introduced. The flush_rewrite_rules(true) call is the standard WordPress approach for this scenario.

No runtime environment available for integration testing. The reporter confirmed the same fixes work in their production mu-plugin workaround.

Resolves #769


aidevops.sh v3.6.167 plugin for OpenCode v1.3.16 with claude-sonnet-4-6 spent 2m and 6,725 tokens on this as a headless worker.

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Improved domain mapping to consistently handle home URL option alongside existing URL mappings.
    • Fixed rewrite rules persisting after duplicating sites in Elementor environments, ensuring proper URL functionality post-duplication.
    • Enhanced HTTPS detection to properly account for SSL configurations and secure admin requirements.

…dening

Fixes three related domain mapping bugs reported in GH#769:

1. Add missing option_home filter in Domain_Mapping::register_filters() so
   get_option('home') returns the mapped domain URL instead of the raw
   subdomain. Fixes broken CPT permalinks, Elementor iframe preview, and
   admin AJAX on sites with custom domain mapping.

2. Add flush_rewrite_rules_for_new_site() hook on wu_duplicate_site (priority
   20) in Elementor_Compat. Clears stale rewrite rules copied verbatim from
   the template site, preventing 404s on CPT URLs after site duplication.

3. Harden fix_new_site_url_scheme() to fall back to FORCE_SSL_ADMIN or
   is_ssl() when get_home_url() returns http:// during site creation (race
   condition on LiteSpeed/Cloudflare setups). Prevents subsites being created
   with http:// siteurl/home on HTTPS networks.

Fixes #769
@superdav42
Copy link
Copy Markdown
Collaborator Author

Completion Summary

  • What: Fixed three domain mapping bugs: missing option_home filter, no rewrite flush after site duplication, and SSL scheme race condition in fix_new_site_url_scheme()
  • Issue: Domain mapping: missing option_home filter + no rewrite flush after site duplication #769
  • Files changed: inc/class-domain-mapping.php, inc/compat/class-elementor-compat.php, inc/compat/class-general-compat.php
  • Testing: Self-assessed; changes follow existing patterns exactly; reporter confirmed same fixes work in their production mu-plugin workaround
  • Key decisions: Placed flush_rewrite_rules hook in Elementor_Compat (priority 20) rather than a new file since it already hooks wu_duplicate_site for regenerate_css; used FORCE_SSL_ADMIN || is_ssl() as fallback rather than hardcoding https to preserve non-SSL installs

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 9, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

Addresses three domain mapping and site duplication bugs: adds missing option_home filter registration for URL mangling, implements rewrite rules flushing after site duplication via a new Elementor compatibility hook, and enhances URL scheme detection with fallback HTTPS enforcement based on SSL status or admin settings.

Changes

Cohort / File(s) Summary
Domain Mapping Filter
inc/class-domain-mapping.php
Registered URL-mangling callback for option_home option filter to ensure consistent domain replacement for get_option('home') calls.
Site Duplication Rewrite Rules
inc/compat/class-elementor-compat.php
Added flush_rewrite_rules_for_new_site() method and hooked it to wu_duplicate_site (priority 20) to clear stale rewrite rules copied during site duplication.
URL Scheme Detection
inc/compat/class-general-compat.php
Enhanced fix_new_site_url_scheme() with fallback HTTPS detection: conditionally forces HTTPS scheme when FORCE_SSL_ADMIN is enabled or is_ssl() detects current request is over SSL.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Three bugs we've caught with whiskers twitching—
Domain filters, rewrites, schemes all switching!
Home URLs now mangle just right,
Fresh sites flush rules, HTTPS in sight,
Hopping forward, no more 404s in the night! 🌐

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes all three main changes in the PR: domain mapping option_home filter fix, rewrite flush after duplication, and SSL scheme hardening.
Linked Issues check ✅ Passed The PR fully addresses all three coding objectives from issue #769: adds option_home filter to Domain_Mapping, implements wu_duplicate_site hook with rewrite flush in Elementor_Compat, and hardens SSL scheme detection in fix_new_site_url_scheme().
Out of Scope Changes check ✅ Passed All changes are directly scoped to the three bugs identified in issue #769; no extraneous modifications to unrelated functionality are present in the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugfix/gh769-domain-mapping-fixes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 9, 2026

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@superdav42
Copy link
Copy Markdown
Collaborator Author

Closing as duplicate of #770.

PR #770 was submitted by the issue reporter (kenedytorcatt) before this worker was dispatched, covers the same fixes, and has all CI checks passing. Merging #770 instead.


aidevops.sh v3.6.167 plugin for OpenCode v1.3.16 with claude-sonnet-4-6 spent 17m and 4,947 tokens on this as a headless worker. Overall, 3m since this issue was created.

@superdav42 superdav42 closed this Apr 9, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 9, 2026

Performance Test Results

Performance test results for a912f51 are in 🛎️!

Note: the numbers in parentheses show the difference to the previous (baseline) test run. Differences below 2% or 0.5 in absolute values are not shown.

URL: /

Run DB Queries Memory Before Template Template WP Total LCP TTFB LCP - TTFB
0 41 37.83 MB 841.00 ms (-20.00 ms / -2% ) 149.00 ms (-3.50 ms / -2% ) 1060.00 ms 2032.00 ms 1951.85 ms 87.75 ms (+6.10 ms / +7% )
1 56 49.02 MB 926.50 ms 138.50 ms 1064.50 ms 2060.00 ms 1978.00 ms 77.20 ms (-1.70 ms / -2% )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Domain mapping: missing option_home filter + no rewrite flush after site duplication

1 participant