Skip to content

fix: add missing option_home filter + flush rewrite rules on site duplication#770

Merged
superdav42 merged 3 commits intoUltimate-Multisite:mainfrom
kenedytorcatt:fix/domain-mapping-option-home-and-rewrite-flush
Apr 9, 2026
Merged

fix: add missing option_home filter + flush rewrite rules on site duplication#770
superdav42 merged 3 commits intoUltimate-Multisite:mainfrom
kenedytorcatt:fix/domain-mapping-option-home-and-rewrite-flush

Conversation

@kenedytorcatt
Copy link
Copy Markdown
Contributor

@kenedytorcatt kenedytorcatt commented Apr 9, 2026

Summary

Fixes two bugs that cause 404 errors on custom post types and broken Elementor preview on subsites with domain mapping.

Discovered on a production multisite with 200+ subsites — affected 8 sites simultaneously.

Changes

1. inc/class-domain-mapping.php — Add missing option_home filter

register_filters() adds option_siteurl but not option_home. This causes get_permalink() to return the original 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); to mirror the existing option_siteurl filter.

2. inc/compat/class-general-compat.php — Flush rewrite rules after site duplication

When UM duplicates a template site, the rewrite_rules option is copied verbatim. If CPT permalink slugs were changed after the template was created, all cloned sites keep stale rules and return 404 on those CPT URLs.

Fix: Added flush_rewrite_rules_on_new_site() method hooked to wu_duplicate_site at priority 20.

Related

Fixes #769

Testing

  1. Create a subsite from a template with Tutor LMS (or any CPT with a custom permalink slug)
  2. Map a custom domain to the subsite
  3. Publish a course/CPT post
  4. Visit the course URL on the mapped domain → should return 200 (was 404 before)
  5. Open Elementor editor on the subsite → preview should load (was broken before)

Summary by CodeRabbit

  • Bug Fixes
    • Domain mapping now properly extends to the Home option URL.
    • Rewrite rules are automatically regenerated when duplicating sites.

The register_filters() method filters option_siteurl but not option_home,
causing get_permalink() to return the original subdomain URL instead of
the mapped domain. This breaks CPT permalinks, Elementor preview, and
admin AJAX on sites with domain mapping.

Fixes Ultimate-Multisite#769
Cloned sites inherit the template's rewrite_rules option verbatim.
If CPT permalink slugs were changed after the template was created,
the cloned site returns 404 on those CPT URLs until the rules are
regenerated. This adds a flush_rewrite_rules(true) call on the
wu_duplicate_site hook.

Fixes Ultimate-Multisite#769
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a098f242-9a2d-47b2-b000-a1c7021b50e5

📥 Commits

Reviewing files that changed from the base of the PR and between cb70b76 and b54de87.

📒 Files selected for processing (2)
  • inc/class-domain-mapping.php
  • inc/compat/class-general-compat.php

📝 Walkthrough

Walkthrough

Two related bug fixes address domain mapping and site duplication issues. The first adds a missing option_home filter to ensure mapped domains affect the stored home URL. The second adds rewrite rule flushing after site duplication to prevent 404 errors from stale rules.

Changes

Cohort / File(s) Summary
Domain Mapping Filter Enhancement
inc/class-domain-mapping.php
Added option_home filter registration to extend domain mapping behavior, ensuring the stored home URL respects mapped domains alongside existing site_url, home_url, and option_siteurl filters.
Site Duplication Rewrite Rules
inc/compat/class-general-compat.php
Added flush_rewrite_rules_on_new_site() method and registered it on wu_duplicate_site action to regenerate rewrite rules after site duplication, preventing 404 errors from stale rule cache.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Hop, hop, hooray! These bugs won't stay!
A filter finds the home URL's way,
Rewrite rules flush when sites are spun,
No more 404s for anyone! ✨

🚥 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 accurately summarizes the main changes: adding the missing option_home filter and flushing rewrite rules on site duplication.
Linked Issues check ✅ Passed The PR fully addresses the two primary coding requirements from issue #769: registering the option_home filter in Domain_Mapping and flushing rewrite rules after site duplication.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the two bugs documented in issue #769; no unrelated modifications are present.
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 unit tests (beta)
  • Create PR with unit tests

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.

Copy link
Copy Markdown
Collaborator

@superdav42 superdav42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto-approved by pulse — collaborator PR (author: @kenedytorcatt). All pre-merge checks passed.

@superdav42 superdav42 merged commit fde1f97 into Ultimate-Multisite:main Apr 9, 2026
11 checks passed
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

2 participants