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

Open Beginner friendly
#2,131 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
62/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
php, wordpress
Domain
backend

Research direction

The bug is in fix_srcset() in inc/class-domain-mapping.php, hooked on wp_calculate_image_srcset, which lacks the blog-ID check that mangle_url() already performs. Compare the two methods, then add an early return when current_mapping's blog ID differs from get_current_blog_id(). Check the filters in register_mapped_filters() for the same gap. Done when a switch_to_blog() render of another site's image gets its own srcset URLs and images on the mapped site keep the mapped domain.

Written by the indexing model from the issue text.

Description

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

Dominant language
PHP
Stars
219
Forks
88
Avg merge
1d 7h
Merged PRs (30d)
58

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Ultimate-Multisite/ultimate-multisite

All issues in Ultimate-Multisite/ultimate-multisite

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.