Hi @ramshengale,
Thanks for providing further information. Currently, there’s no way to schedule/delay the removal of files.
Could you please confirm if the update attachment metadata was triggered after the files were processed/modified? It’s possible that the files weren’t removed since that function wasn’t triggered again.
WP Offload Media uses the wp_update_attachment_metadata
filter to recognize that something has changed in the Media Library item’s makeup, and uses this as the trigger to offload any files that haven’t been already.
More info here – https://deliciousbrains.com/wp-offload-media/doc/developer-guide/#automatic-offload-hooks
Otherwise, we suggest trying to delay the offload until you’re done modifying/processing the file.
We previously ran into an issue wherein a customer was using a plugin called TinyPNG. Our plugin offloaded the file before the optimization was finished which caused some issues. It may be similar to what you’re encountering right now.
A colleague of mine created a snippet for TinyPNG to fix this wherein it delays the offload until TinyPNG finishes its optimization. You may be able to edit that to accommodate your own code:
function pre_update_attachment_metadata( $abort, $data, $post_id, $old_as3cf_item ) {
// prevent offload on upload. default value of $abort is false
$tinypng = get_post_meta( $post_id, 'tiny_compress_images', true ); // TinyPNG creates this metadata for the attachment
if ( ! $tinypng ) {
// TinyPNG hasn't finished compressing this yet, abort for now. This will be called again once TinyPNG finishes and this will be bypassed then
return true; // abort
}
// if we're here, then TinyPNG has finished optimizing images, images will be offloaded now
return $abort;
}
add_filter( 'as3cf_pre_update_attachment_metadata', 'pre_update_attachment_metadata', 10, 4 );
You can add this to your custom theme’s functions.php file or in a custom plugin.
Since that will delay the offload, the removal of the files will also be delayed which may be able to fix the issue you’re having.
We look forward to hearing back!