Open bobbingwide opened 3 years ago
Answer: They are! But...
There's some strange magic going on. For https://sneak-peek.me/2021/04/28/do-i-need-to-define-image-sizes/
the source code shows the site ID as being 15, but when I view the post it's been changed to 3.
Why doesn't this happen for the gallery?
For images there's some fancy filtering that's changing the srcset
attributes.
<figure class="wp-block-image size-thumbnail"><img loading="lazy" width="150" height="150" src="https://sneak-peek.me/wp-content/uploads/sites/15/2021/04/Fuzzy-Duck-I-could-get-into-this-150x150.jpg" alt="" class="wp-image-80" srcset="https://sneak-peek.me/wp-content/uploads/sites/3/2021/04/Fuzzy-Duck-I-could-get-into-this-150x150.jpg 150w, https://sneak-peek.me/wp-content/uploads/sites/3/2021/04/Fuzzy-Duck-I-could-get-into-this-300x300.jpg 300w, https://sneak-peek.me/wp-content/uploads/sites/3/2021/04/Fuzzy-Duck-I-could-get-into-this-1024x1024.jpg 1024w, https://sneak-peek.me/wp-content/uploads/sites/3/2021/04/Fuzzy-Duck-I-could-get-into-this-768x768.jpg 768w, https://sneak-peek.me/wp-content/uploads/sites/3/2021/04/Fuzzy-Duck-I-could-get-into-this-1536x1536.jpg 1536w, https://sneak-peek.me/wp-content/uploads/sites/3/2021/04/Fuzzy-Duck-I-could-get-into-this.jpg 1936w" sizes="(max-width: 150px) 100vw, 150px" /><figcaption>Image size: Thumbnail</figcaption></figure>
It's wp_img_tag_add_srcset_and_sizes_attr()
that uses the attachment ID to find the image and gets the right details.
To fix this problem it'll be necessary to pass the original site ID to the target and then apply updates to the post_content.
wp-admin/admin-ajax.php
. get_current_blog_id
.The target site will have to apply the changes taking into account its own site ID, obtained the same way.
Mapping is as follows:
Value of site_id | Value of target's site ID | Processing |
---|---|---|
1 | 1 | This may not be Multi Site - doesn't matter though - there's nothing to change |
n | n | This is Multi Site - -doesn't matter though - there's nothing to change |
n | 1 | This may be Multi Site to single site. What now? |
1 | n | This may be single site to Multi Site. What now? |
n | m | perform the string replace |
I haven't yet encountered the What now? scenario. Maybe I'll set the value to null when it's not multisite.
Use better search replace after cloning everything.
Original thoughts
When I first created the Screenshots page in
s.b/wp55/thisis/
it was a top level page. I moved it to below About, so the new URL becames.b/wp55/thisis/about/screenshots
. But the images in the gallery were still hardcoded, so appeared broken.Alternative explanation
The above could have been a red herring.
Looking at the source URL of the image file I can see it contains the site ID.
I'm cloning between two unrelated WPMS installations.
s.b/wp55/thisis
(Site ID 15) being the sourcebobbingwide.com/sneak-peek.me
(Site ID 3) being the target.It looks like the Site ID needs to be mapped as well. Pseudo code, with these Site IDs instead of variables
Question: Why aren't images broken as well? Answer: They are! But the broken image does not appear in the same way unless it's a link.