mrbm
Forum Replies Created
-
Hey I really appreciate the quick response! It’s so strange because it worked before.
For context, prior to the code example I am attempting side load a remote image. Perhaps you can suggest a better way to now handle this situation. Below is the code that was previously working, thanks!
// Download image and add it to Media Library
$upload = media_sideload_image( "https://someremoteurl.com/photo.jpg", get_the_id(), null, 'id' );
// Check for errors while downloading image
if ( is_wp_error( $upload ) ) {
wp_send_json_error( [ 'message' => $upload->get_error_message() ] );
}
// Get attachment ID and image URL
$attachment_id = is_wp_error( $upload ) ? 0 : $upload;
$image_url = get_attached_file( $attachment_id );
// Convert image to JPG and compress with quality of 80
$image_editor = wp_get_image_editor( $image_url );
if ( ! is_wp_error( $image_editor ) ) {
$image_editor->set_quality( 80 );
$saved = $image_editor->save( null, 'image/jpeg' );
if ( ! is_wp_error( $saved ) ) {
wp_delete_attachment( $attachment_id, true );
$attachment_id = wp_insert_attachment([
'post_mime_type' => 'image/jpeg',
'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $saved['path'] ) ),
'post_content' => '',
'post_status' => 'inherit',
], $saved['path']);
wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $saved['path'] ) );
}
}Noted, thanks for the update.
@papex can you post the website link you were using? would love to see your use case. I personally have had 0 issues, but always like to see what other people are doing. You posted 5 months ago so maybe issues were resolved.
<bump>
False alarm, was getting conflict or maybe cache wasn’t clearing properly as a result of autoptimize. Situation resolved! Thanks for the great plugin!
I can get a developer on Fiverr to build me this functionality using ChatGPT in a day or two, and have unlimited with no renewal fee.
How is that going?
@urshobhit @pastycrab I would love to see your R2 guide as well, or perhaps @dbisupport is familiar with how R2 is being used? Thanks!
I haven’t had any issues for many years…just curious so I am prepared, what was your set up and did you figure out why you were having trouble?
Also note, i tried removing the rank math code in favor of adding your suggested additional domain to filter with, but unfortunately that wont fix the rank math issue. Additional filtering is necessary for the rank math sitemap image urls to update. Thanks guys
Via trial and error, the correct answer is there should be no trailing slash.
Thanks for the great product!
Yes. So far I’ve ALMOST got it all locked down. But this fixed the problem. The last issue still can’t seem to get a handle on is the theme builder. For some reason when images are added to a theme builder, it shows in the visual builder perfectly, but the final render out shows the local paths. If you know of filter in divi i could apply my same domain map then filter….let me know…will also try adding your method that you suggested earlier
I should have paid more attention to your response as it would have been easier, but i didn’t think that was the issue. In hindsite that filter would have worked as well.
The replacement was only occurring on the mapped domain, not the network path. So I wrote a bit of code:
add_filter( 'rank_math/sitemap/urlimages', function( $images, $post_id ){ global $blog_id; $network_info = get_blog_details($blog_ID); $network_url = 'https://' . $network_info->domain . $network_info->path; $mapped_domain = $network_info->home . '/'; $newimages = array(); foreach ($images as $image) { if(str_contains($image['src'], 'https://') ) { $image['src'] = str_replace($network_url, $mapped_domain,$image['src']); $image['src'] = apply_filters( 'as3cf_filter_post_local_to_provider', $image['src']); array_push($newimages, $image); } } $images = $newimages; return $images; }, 99, 2);
I don’t think the domain mapping is it. Can you perhaps review your plugin’s compatibility with rankmath, they have a free version.
Can you possibly assist in how to get the your plugin to filter inside of:add_filter( 'rank_math/sitemap/urlimages', function( $images, $post_id ){ $newimages = array(); foreach ($images as $image) { if(str_contains($image['src'], 'https://') ) { $image['src'] = apply_filters( 'as3cf_filter_post_local_to_provider', $image['src']); $image['coolbro'] = 'cool bro'; array_push($newimages, $image); } } error_log("urlimages function.php: " . print_r($newimages, true), 0); $images = $newimages; return $images; }, 99, 2);
Remember to get that filter to work with divi you need to change the priority of the filter to 99 then it works like a champ. The only issue left is your filter not seeming to filter. When reviewing divi’s usage, they seem to filter thing via the class. I can’t get either to work, perhaps you can share some insight?Small follow up, the as3cf_filter_post_local_to_provider filter doesn’t seem to “filter” inside another filter.
Can you please guide me for how to convert a local url (or array containing local urls) into remote urls, possibly using:
global $as3cf;
Thanks!
Hello @dbisupport I reached out to rankmath and they mentioned that there is an issue with the Divi theme and filter. They said the solution to accessing the filters is to change the priority as you mentioned to 99. I did that and now can see the data. That said, I am still unable to see the filtering of as3cf_filter_post_local_to_provider work.
Perhaps you have a suggestion? Here is the filter in use:
add_filter( 'rank_math/sitemap/urlimages', function( $images, $post_id ){ $newimages = array(); foreach ($images as $image) { if(str_contains($image['src'], 'https://') ) { $image['src'] = apply_filters( 'as3cf_filter_post_local_to_provider', $image['src']); $image['coolbro'] = 'cool bro'; array_push($newimages, $image); } } error_log("urlimages function.php: " . print_r($newimages, true), 0); $images = $newimages; return $images; }, 99, 2);
It is still showing the local paths.
And another follow up, I am using the sunsetted wpmudev domain mapping plugin. With my modifications everything works pretty great. However is it possible that your plugin is looking to filter on the mapped domain rather than the multi-site subfolder url?
- This reply was modified 1 year, 6 months ago by mrbm.