Using delete_attachment to prevent an attachment not working
I'm having an issue where the attachment is being deleted despite me returning false
function action_maybe_delete( $id ) {
echo "Let's not delete Attachment id: " . $id ;
// prevent the attachment from actually being deleted
if( 1 == 1 ) { // made up condition
return false;
}
};
// add the action
add_action( 'delete_attachment', 'action_maybe_delete', 10, 1 );
When i run code similar to the above from the media library, it calls admin_ajax.php it echos the mesage Let's not delete Attachmend id: 123
in the http response, but it still deletes the file entry the media library.
Shouldn't it NOT delete the file?
My end goal is to run some statements that remove the file from my Amazon S3 container and if that fails, NOT delete the local file ( but rather tell user that the process failed )... or something like that.
Topic attachments hooks Wordpress
Category Web