Edit image / Delete image link

There is a function in WordPress that allows to display a “edit post” link if the user has sufficient rights.

<?php edit_post_link( __( 'Edit' ), '<small class="edit-link">', '</small>' ); ?>

Is there an equivalent for media files / attachments,

Read More

UPDATE
This sorts of work

$images = fdw_get_post_images('preview-onepost-thumbnail');
if ($images){
  $counter= 0;
 foreach ($images as $image){
      $src = $image['src'];
      $info = $image['info'];
 edit_post_link( __( 'Edit image' ), '<section><small class="edit-link">', '</small></section>', $info->ID ); ?>

But the user actually need to be able to Delete the image. That screen does not allow it.

Related posts

Leave a Reply

1 comment

  1. This isn’t 100% complete, but should be a good start for you.

    <a href="<?php echo wp_nonce_url( "/wp-admin/post.php?action=delete&amp;post=$post->ID", 'delete-attachment_' . $post->ID ) ?>"><?php _e( 'Delete Permanently' ) ?></a>
    

    A couple notes on what you’ll have left to do:

    • This will do no confirmation, so you’ll probably want to use JS to verify that it wasn’t clicked by mistake
    • This will redirect back to the current page, which will no longer exist. The URI may look something like, ?attachment_id=704&deleted=1. You’ll want to intercept front-end attachment requests where $_GET['deleted'] == '1' and handle that gracefully (e.g. redirect).