Skip to content

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

Done

Description

@superdav42

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

Activity

  1. added
    bug
    on Nov 21, 2026
  2. self-assigned this
    on Nov 21, 2026
  3. added
    status:available
    origin:interactive
    on Nov 21, 2026
  4. removed their assignment
    on Nov 21, 2026
  5. superdav42 commented on Nov 25, 2026

    @superdav42
    CollaboratorAuthor

    DISPATCH_CLAIM nonce=22f73b391154c889bdad080f6aa42f8c runner=superdav42 ts=2026-11-25T18:52:54Z max_age_s=1800 version=3.39.189 opencode_version=1.18.31 lease_token=22f73b391154c889bdad080f6aa42f8c device=device-1783824528-2609248-26808 session=issue-2131 phase=prelaunch expires_at=1795632896

  6. superdav42 commented on Nov 25, 2026

    @superdav42
    CollaboratorAuthor

    DISPATCH_LEASE phase=prelaunch lease_token=22f73b391154c889bdad080f6aa42f8c device=device-1783824528-2609248-26808 session=issue-2131 expires_at=1795633242 ts=2026-11-25T18:53:12Z attempt_id=attempt:2b47d076-84b6-4264-a914-5ad2e03126e5

  7. locked as resolved and limited conversation to collaborators on Nov 25, 2026
  8. added
    status:queued
    and removed
    status:available
    on Nov 25, 2026
  9. superdav42 commented on Nov 25, 2026

    @superdav42
    CollaboratorAuthor

    DISPATCH_LEASE phase=prelaunch lease_token=22f73b391154c889bdad080f6aa42f8c device=device-1783824528-2609248-26808 session=issue-2131 expires_at=1795633243 ts=2026-11-25T18:53:49Z attempt_id=attempt:2b47d076-84b6-4264-a914-5ad2e03126e5

  10. added
    status:in-progress
    and removed
    status:queued
    on Nov 25, 2026
  11. superdav42 commented on Nov 25, 2026

    @superdav42
    CollaboratorAuthor

    Dispatching worker (deterministic).

  12. superdav42 commented on Nov 25, 2026

    @superdav42
    CollaboratorAuthor

    DISPATCH_LEASE phase=ready lease_token=22f73b391154c889bdad080f6aa42f8c device=device-1783824528-2609248-26808 session=issue-2131 expires_at=1795640043 ts=2026-11-25T18:54:03Z attempt_id=attempt:2b47d076-84b6-4264-a914-5ad2e03126e5


    aidevops.sh v3.39.189 automated scan.

  13. unlocked this conversation on Nov 25, 2026
  14. added
    status:in-review
    and removed
    status:in-progress
    on Nov 25, 2026
  15. superdav42 commented on Nov 25, 2026

    @superdav42
    CollaboratorAuthor

    CLAIM_RELEASED reason=worker_complete runner=superdav42 ts=2026-11-25T18:59:31Z aidevops_version=3.39.189 opencode_version=1.18.31 claim_id=7171531122 nonce=22f73b391154c889bdad080f6aa42f8c lease_token=22f73b391154c889bdad080f6aa42f8c device=device-1783824528-2609248-26808 session=issue-2131


    aidevops.sh v3.39.189 plugin for OpenCode v1.18.31

  16. superdav42 commented on Nov 25, 2026

    @superdav42
    CollaboratorAuthor

    Completion Summary

    • What: Prevent the request host's domain mapping from rewriting srcset URLs while rendering a different switched blog. Other mapped URL filters already route through mangle_url, which has target-site guards.
    • Issue: Domain mapping fix_srcset applies the request's mapped domain to other sites' images after switch_to_blog #2131
    • Files changed: inc/class-domain-mapping.php
    • Testing: vendor/bin/phpcs inc/class-domain-mapping.php; vendor/bin/phpstan analyse inc/class-domain-mapping.php --no-progress; php -l inc/class-domain-mapping.php; git diff --check origin/main...HEAD. Runtime multisite verification was self-assessed because the worktree has no WordPress dev install or WordPress test suite.
    • Key decisions: none

    aidevops.sh v3.39.189 plugin for OpenCode v1.19.5 with gpt-5.6-sol spent 3m and 70,126 tokens on this as a headless worker.


    Merged via PR #2153 to main.
    Merged by deterministic merge pass (pulse-wrapper.sh).

    Routing feedback

    • Route: standard; 1 attempt, 23 LLM requests, 0 capability escalations, 1 same-tier fallback.
    • Population: headless; 0 objective outcomes.
    • Usage: 1,351,619 tokens; $0.9081 estimated cost.
    • Recommendation: No routing change is recommended from this sample.
  17. added
    solved:worker
    and removed
    status:in-review
    on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugorigin:interactivesolved:workerstatus:done

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions