Domain mapping: apply primary mapped domain to home_url/site_url for other sites, not only the current request host
维护者通常 1 天内回复
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 55/100
调研方向
Start with register_mapped_filters() and mangle_url() in inc/class-domain-mapping.php, then read get_primary_mapped_domain() in inc/models/class-site.php and the relevant domain mapping tests under tests/. Verify the main site context returns the primary mapped domain for another site, an unmapped site stays unchanged, and admin on a non-primary host still works with force_admin_redirect = both; check cache behavior across repeated lookups.
由索引模型根据 Issue 内容生成。
描述
Summary
A site's primary mapped domain is only applied to home_url / site_url when the current request's host is a mapping of that same site. Everywhere else (main site, network admin, "My Sites", cross-site loops calling get_home_url($blog_id), cron, CLI) WordPress returns the raw stored home/siteurl option, i.e. the site's original network address. If that address is a domain the customer no longer wants, links built from another site send users to the old host, where admin, uploads and REST keep working on the old domain.
Observed in production (anonymised)
- Site N has
wp_blogs.domain = old.example.com, mapping Anew.example.net(active=1, primary_domain=1), mapping Bold.example.com(active=1, primary_domain=0).force_admin_redirect = both. - Front end on the old host correctly 301s to the primary (
Primary_Domain::redirect_to_primary_domain). - A network-wide SSO/plugin on the main site builds per-site links with
get_home_url($id)→ returnshttps://old.example.combecausemangle_url()bails when$site_iddiffers from the current request's mapping. - Editors follow those links, stay in wp-admin on the old host (no admin redirect under
both), and every upload gets an old-domain URL (43 attachments in a week). - Only fix was changing the site's network address itself, which defeats the purpose of a primary mapping.
Root cause
inc/class-domain-mapping.php:
register_mapped_filters()(~line 517) registers the URL filters only when$_SERVER['HTTP_HOST']matches a mapping, and stores that mapping ascurrent_mapping.replace_url()(~line 612) rewrites tocurrent_mapping->get_domain()— the request's mapping, not the site's primary mapping.mangle_url()(~line 682) returns the URL unchanged whencurrent_mapping->get_blog_id() !== $site_id, so other sites are never mapped.
Proposed change
- Register
home_url/site_url(with$blog_id/$site_idargs) filters whenever domain mapping is enabled, not only when the request host is mapped. - In
mangle_url(), when there is no current mapping or$site_idis a different site, resolve that site's primary mapping via the existing\WP_Ultimo\Models\Site::get_primary_mapped_domain()(inc/models/class-site.php:1334) and pass it toreplace_url($url, $mapping)(the second parameter already exists for this). Cache the per-site lookup (existingdomain_mappingsglobal cache group) so loops over many sites do not add a query per call. - Keep current behaviour for the current site on a mapped request host (respects
force_admin_redirect = both, so admin on an alternate mapped domain keeps working). - Do not change raw
option_home/option_siteurlreads for other sites unless needed; thehome_url/site_urlfilters coverget_home_url()/get_site_url()/get_admin_url().
Optional follow-up (separate PR is fine): when the request host is a non-primary mapping and force_admin_redirect = force_map, ensure admin redirects to the primary mapping rather than the request mapping.
Files Scope
inc/class-domain-mapping.phptests/WP_Ultimo/Domain_Mapping_Test.php
Reference only: inc/models/class-site.php (get_primary_mapped_domain()) and inc/domain-mapping/class-primary-domain.php (redirect behaviour to stay consistent).
Acceptance / verification
- From the main site context (
wp --url=<main-site> eval 'echo get_home_url(<N>);'), a site with an active primary mapping returns the primary mapped domain. - Network admin → Sites list and "My Sites" show the primary mapped domain.
- A site without mappings is unchanged.
- Visiting wp-admin on a non-primary mapped host with
force_admin_redirect = bothstill works and keeps that host (no regression). - No extra DB query per
get_home_url()call in a loop over sites after the first lookup (object cache hit). vendor/bin/phpcsclean on changed files; existing PHPUnit suite passes.
aidevops.sh v3.39.119 plugin for OpenCode
- 主要语言
- PHP
- 星标
- 218
- 派生
- 88
- 平均合并
- 1 天 5 小时
- 30 天内合并 PR
- 94
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
Ultimate-Multisite/ultimate-multisite 的其他 Issue
-
Track interactive PR #2086可能重新可做 关联的 PR 已关闭且未合并。 未关闭origin:worker source:conflict-feedback status:available
难度 4/5 3-5 天 新手友好度 1/100
Ultimate-Multisite/ultimate-multisite#2090 · 1 条评论 ·
维护者通常 1 天内回复
-
Track interactive PR #2087可能重新可做 关联的 PR 已关闭且未合并。 未关闭origin:worker source:conflict-feedback status:available
难度 4/5 3-5 天 新手友好度 1/100
Ultimate-Multisite/ultimate-multisite#2089 · 1 条评论 ·
维护者通常 1 天内回复
-
no-auto-dispatch operator:superdav42 origin:worker priority:high status:available
难度 4/5 3-5 天 新手友好度 35/100
Ultimate-Multisite/ultimate-multisite#2083 ·
维护者通常 1 天内回复
-
Clearer default custom-domain DNS instructions and configurable DNS target可能已有人在做 @superdav42 于 5 天前认领。 未关闭enhancement origin:worker source:ci-feedback status:in-review
难度 3/5 1-2 天 新手友好度 35/100
Ultimate-Multisite/ultimate-multisite#2067 · 14 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
fix: send payment_received receipt after manual payment confirmation and email verification可能已有人在做 @superdav42 于 10 天前认领。 未关闭bug origin:worker source:ci-feedback status:in-review tier:standard
Ultimate-Multisite/ultimate-multisite#2055 · 24 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 Ultimate-Multisite/ultimate-multisite 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
Automattic/blocks-engine#5003 ·
维护者通常 1 天内回复
-
from-cloud mythic tracked
难度 1/5 1 小时以内 新手友好度 86/100
MythicalLTD/FeatherPanel#459 · 1 条评论 ·
维护者通常 1 天内回复
-
[Bug]: PostgreSQL backend: Queue.remove() / Job.remove() never emit the QueueEvents "removed" event可能已有人在做 @1AbdullahButt 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 84/100
taskforcesh/bullmq#5085 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
shukiv/jabali-panel#2423 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 67/100