Domain mapping fix_srcset applies the request's mapped domain to other sites' images after switch_to_blog

未关闭 适合新手
#2,131 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
62/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
php, wordpress
领域
backend

调研方向

问题出在 inc/class-domain-mapping.php 中的 fix_srcset(),它挂载在 wp_calculate_image_srcset 上,缺少 mangle_url() 已经执行的博客 ID 检查。请比较这两个方法,然后在 current_mapping 的博客 ID 与 get_current_blog_id() 不同时添加提前返回。同时检查 register_mapped_filters() 中的过滤器是否存在同样的缺口。当通过 switch_to_blog() 渲染其他站点的图片时能获得它们自己的 srcset URL,并且映射站点上的图片仍保持映射后的域名,即视为完成。

由索引模型根据 Issue 内容生成。

描述

bug origin:interactive status:available

Problem

Domain_Mapping::fix_srcset() (inc/class-domain-mapping.php, hooked on wp_calculate_image_srcset) rewrites every srcset URL with replace_url() using $this->current_mapping, the mapping of the request's host. Unlike mangle_url(), which returns early when $current_mapping->get_blog_id() !== get_current_blog_id(), fix_srcset() has no site check.

So when a request for mapped site A calls switch_to_blog(B) and renders B's images, B's srcset URLs get A's domain (https://site-a.example/app/uploads/sites/B/...), while src stays correct. On a production network (2026-11-21) this was cached in Elementor's _elementor_element_cache for four posts of one site. A CDN page-URL rewriter then replaced only the upload path, leaving A's host in front of the CDN URL (https://site-a.examplehttps://cdn.example/...), so the logo, banners and product images failed to load on every page of site B.

Fix

In fix_srcset(), return $sources unchanged unless $this->current_mapping->get_blog_id() === get_current_blog_id(), matching mangle_url(). Optionally, use the mapping for the current blog instead of returning early. Check the other filters registered in register_mapped_filters() for the same missing guard.

Files Scope
  • EDIT: inc/class-domain-mapping.php (fix_srcset(), around line 705)

Verification

  • On a multisite with a mapped domain for site A, request A's front end with code that runs switch_to_blog(B); echo wp_get_attachment_image($id_on_B, 'full'); restore_current_blog();. Before the fix, srcset URLs use A's domain; after it, they use B's own URLs.
  • Regression: images rendered on A itself still get A's mapped domain in srcset.

aidevops.sh v3.39.189 plugin for OpenCode

主要语言
PHP
星标
219
派生
88
平均合并
1 天 7 小时
30 天内合并 PR
58

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Ultimate-Multisite/ultimate-multisite 的其他 Issue

查看 Ultimate-Multisite/ultimate-multisite 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。