Hi there!
Its possible delete images in front-end.
I got this with non-admin users.
I use:
in HTML:
<a class="remImage" name="<?php echo $image->ID; ?>" href="#" onclick="delete_image(<?php echo $image->ID; ?>)"><?php _e('delete');?></a>
JQuery
function delete_image(id_image) {
var attID = id_image;
jQuery.ajax({
type: 'post',
url: '/wp-admin/admin-ajax.php',
data: {
action: 'delete_attachment',
att_ID: id_image,
_ajax_nonce: jQuery('#nonce').val(),
post_type: 'attachment'
},
success: function() {
console.log('#file-'+attID)
$('#file-'+attID).fadeOut();
window.location.reload();
}
});
};
in functions.php
add_action( 'wp_ajax_delete_attachment', 'delete_attachment' );
function delete_attachment( $post ) {
//echo $_POST['att_ID'];
$msg = 'Attachment ID [' . $_POST['att_ID'] . '] has been deleted!';
if( wp_delete_attachment( $_POST['att_ID'], true )) {
echo $msg;
}
die();
}