Tiled Gallery: add jetpack_skip_photon_domain filter to keep origin image URLs#50422
Tiled Gallery: add jetpack_skip_photon_domain filter to keep origin image URLs#50422enejb wants to merge 1 commit into
Conversation
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryCoverage changed in 5 files.
Full summary · PHP report · JS report If appropriate, add one of these labels to override the failing coverage check:
Covered by non-unit tests
|
Proposed changes
The Tiled Gallery always rewrites its image URLs onto the Photon domain (
i0.wp.com), because the tiled layout needs images fetched at exactw/h/cropdimensions and Photon is the on-demand resizer that can produce them. On platforms that already have a Photon-equivalent image service built in (notably WordPress VIP), the origin host understands the same?w=&h=&crop=&resize=query args, so routing throughi0.wp.comis redundant/undesirable.This adds a new opt-in filter,
jetpack_skip_photon_domain(boolean, defaultfalse). When it returnstrue, tiled galleries keep the origin image domain and simply append the same resizing query args, instead of sending URLs through Photon.Reading guide — the change touches every path that builds tiled-gallery image URLs:
modules/tiled-gallery/tiled-gallery/tiled-gallery-item.php: theimg_srcbuild now branches on the filter. Default =Image_CDN_Core::cdn_url()(Photon); opted-out =add_query_arg( $img_args, $orig_file )(origin + same args). The filter is documented here (canonical docblock).modules/tiled-gallery/tiled-gallery.php: the fallback that force-runsImage_CDN::filter_the_content()when the Image CDN module is off is now skipped when opting out, so origin URLs aren't re-photonized.extensions/blocks/tiled-gallery/tiled-gallery.php: exposes the flag to the editor JS, and adds adephotonize_url()helper so pre-existing block content with baked-ini0.wp.comURLs is rewritten back to origin (both the mainsrcand thesrcset). The Photon-onlysslarg is dropped on origin URLs.class.jetpack-gutenberg.php: addsskip_photon_domaintoJetpack_Editor_Initial_State.jetpackso the block's save-time JS can read it.extensions/blocks/tiled-gallery/utils/index.js: newskipPhotonDomain()reader; when true,photonizedImgProps()reuses the existingphotonWpcomImage()helper (which already keeps the origin host + appends args — the same behavior VIP already gets).Deprecated block versions (
deprecated/v2,v6) are intentionally left untouched — theirsaveoutput must byte-match already-saved content or blocks fail validation.Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
Enable the filter (e.g. a mu-plugin):
[gallery ids="…" type="rectangular"]. With the filter off, view source:<img src>ishttps://i0.wp.com/…?w=&h=. With it on: thesrcis the origin host with?w=&h=&crop=1, and noi0.wp.comremains. (Note:Image_CDN_Core::cdn_url()photonizes even when the Image CDN module is off, so the "off" state showsi0.wp.comregardless of module state.)i0.wp.comURLs, filter on → server render rewritessrc/srcsetto origin.i0.wp.com(no change to default behavior).Verified on a Jurassic Ninja site across all of the above.