App for Cloudflare® Pro

App for Cloudflare® Pro 1.8.9

image url

wynnzhang

New member
The shop and category images, as well as gallery images, are still using the default WordPress image URLs instead of being replaced by the R2 URLs, resulting in broken image links on the pages. Is there a setting available to switch the URLs?
 
Are the images considered Media within WordPress? On the presentation side, if they are being presented by a third-party plugin or theme, it would need to make sure to use the standard WordPress hook for generating attachment URLs. It's the wp_get_attachment_url filter that does the backend processing for figuring out what the true URL is.

Themes/plugins should be using that normally (it's the standard way to do it in WordPress itself), if something isn't, you probably want to report it to the author because it's more or less a bug (or at least a severe oversight). Again, that filter isn't coming from us, it's the normal one that's supposed to be used for anything WordPress (including stock WordPress itself) since WordPress 2.1.
 
Probably makes the most sense to report it to them. Not about adding support for this plugin exactly, but for them to support the normal WordPress filter I linked to above. That’s the “proper” way for anything to handle image URLs.
 
Hi I have just repurchased the license again but from website I can not make the pro enabled. I have found a snippet code below this may working for any themes. I would like a try can you checck and enable the license

add_filter('wp_get_attachment_url', 'convert_to_r2_url', 10, 2);
add_filter('wp_calculate_image_srcset', 'convert_srcset_to_r2', 10, 5);

function convert_to_r2_url($url, $attachment_id) {
if (wp_attachment_is_image($attachment_id)) {
$r2_url = str_replace('your website url', 'r2 url', $url);
return $r2_url;
}
return $url;
}

function convert_srcset_to_r2($sources, $size_array, $image_src, $image_meta, $attachment_id) {
foreach ($sources as $size => $source) {
$sources[$size]['url'] = str_replace('your website url', 'r2 url', $source['url']);
}
return $sources;
}
 
It’s not going to work if your theme doesn’t support those filters. Those filters are already enabled in the plugin, so the issue isn’t the filters aren’t set, rather your theme isn’t using them.

Again, the code is already there using those filters… so you are just replicating what’s already there. You would need a theme that actually *uses* those filters.
 
so after this code, the existing image can not open anymore and the url changed to R2 url, I checked its ccorrect R2 url , just for existing image has not sent to r2 yet
 

Attachments

  • 21B9796C-9D85-4a30-83F3-ECE1C39C5F0D.png
    21B9796C-9D85-4a30-83F3-ECE1C39C5F0D.png
    36.3 KB · Views: 0
  • EDDA818C-7FAD-47f1-9A37-8B865E41723B.png
    EDDA818C-7FAD-47f1-9A37-8B865E41723B.png
    50.7 KB · Views: 0
I just tried this code all my site image gone and url changed to r2
I promise you those two filters are in the plugin. There are cases where the filters won't change the URL, but that has to do with the system not thinking the image itself is in R2... either R2 isn't enabled or the meta data for the image says it's not in R2. Can't tell you which logic is causing it to not change the URL, because I don't have access to your site. But the general logic is this:

Do you have the Pro version installed with a valid license? If it's valid, check if we are in a multisite setup or single site setup... if multisite, do we have a multisite bucket setup? If single site, is there a single site bucket setup? If a valid bucket is setup, the external data URL is set and the attachment metadata flag that tells us it's in R2 is set, then change the URL to reflect the domain set in external data URL.

so after this code, the existing image can not open anymore and the url changed to R2 url, I checked its ccorrect R2 url , just for existing image has not sent to r2 yet
The logic is shown above... the existing filter doesn't blindly change the URL when it's not appropriate (for example if the image isn't in R2 or a bucket isn't setup, or we don't know the external data URL).
 
do you have email I can send you the site login detial to have a look?
No, sorry... we don't get into users sites.

The license looks like renewed but not a new license, its a single site, I have updated to the new license number
Hmmm... it looks like the system let you purchase an annual extension, but there was no valid license to begin with. It's been fixed on our end to not allow that. I'll go ahead and refund it.
 
Back
Top