• Resolved Raza Khadim

    (@razakhadim)


    I have linked a page; this image was deleted about 24 hours ago from WordPress. All images are hosted on R2.
    Whenever a post is deleted and emptied from trash, I run this

    add_action( 'before_delete_post', 'delete_all_attached_media' );

    function delete_all_attached_media( $post_id ) {

    if( get_post_type($post_id) == "listing" ) {
    $attachments = get_attached_media( '', $post_id );

    foreach ($attachments as $attachment) {
    wp_delete_attachment( $attachment->ID, true );
    }
    }
    }

    The images from Media Library are deleted fine but I have noticed that they are not being deleted from R2. All my images offloaded.

    I am attaching a screenshot of my settings as well (if the image does not load: check it here: https://postimg.cc/fVRHj74K)

    The image that has been deleted from Media Library but still exists on R2: https://assets.localgofer.co.nz/2026/05/localgofer_co_nz_20260522_141734_5551.jpg

    Will appreciate any help.

    Thanks

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Plugin Author Masoud Golchin

    (@masoudin)

    Hello @razakhadim

    Thank you for reaching out.

    I have tested the code you provided, but I was unable to replicate the issue. In my tests, images were successfully deleted from R2 after the post was removed.

    I suspect there may be a conflict with your theme or another plugin. Could you please enable the debug.log in your WordPress installation and try again to see if any errors are recorded? Additionally, it would be helpful to perform a plugin and theme conflict test by disabling them one by one to isolate the cause.

Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.