Domain mapping: apply primary mapped domain to home_url/site_url for other sites, not only the current request host
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 55/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- PHP
- Star
- 218
- Fork
- 88
- Merge trung bình
- 1 ngày 5 giờ
- Pull request đã merge (30 ngày)
- 94
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Ultimate-Multisite/ultimate-multisite
-
Track interactive PR #2086Có thể đã có người làm @superdav42 đã nhận 2 ngày trước. Đang mởorigin:interactive status:blocked
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 1/100
Ultimate-Multisite/ultimate-multisite#2090 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Track interactive PR #2087Có thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởorigin:worker source:conflict-feedback status:available
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 1/100
Ultimate-Multisite/ultimate-multisite#2089 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
no-auto-dispatch operator:superdav42 origin:worker priority:high status:available
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
Ultimate-Multisite/ultimate-multisite#2083 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Clearer default custom-domain DNS instructions and configurable DNS targetCó thể đã có người làm @superdav42 đã nhận 5 ngày trước. Đang mởenhancement origin:worker source:ci-feedback status:in-review
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
Ultimate-Multisite/ultimate-multisite#2067 · 14 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
fix: send payment_received receipt after manual payment confirmation and email verificationCó thể đã có người làm @superdav42 đã nhận 10 ngày trước. Đang mởbug origin:worker source:ci-feedback status:available tier:standard
Ultimate-Multisite/ultimate-multisite#2055 · 13 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của Ultimate-Multisite/ultimate-multisite
Issue tương tự
-
claude
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
sprain/sprainocchio#26 ·
-
sync-en
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày
-
sync-en
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 83/100
GSA/digital-gov-drupal#569 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
feature-request-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Codeinwp/wp-menu-icons#360 ·