1

I'm using the following code to display the WP Editor on the front end page:

$content = '';
$editor_id = 'mycustomeditor';
wp_editor( $content, $editor_id );

When a user clicks on an image in the Media Library I would like to take away the ability to Permanently delete the image.

I unset some options for the Media Uploader already with the following code:

function member_media_view_strings( $strings ) {
    unset( $string['uploadImagesTitle'] );
    unset( $strings['createGalleryTitle'] );

    return $strings;
}
add_filter( 'media_view_strings', 'member_media_view_strings', 99 );

I know there is a warnDelete string but nothing that actually removes that link. Is there a simple way to do this?

  • Are your users anonymous or registered in your WP install? – Rarst Jan 13 '15 at 21:49
  • @Rarst to upload photos they would need to be a registered user and would have a username in the DB – user1048676 Jan 13 '15 at 22:00
2

That link is hard-coded in /wp-includes/media-template.php ~ln 526. Since it can't be removed via apply_filters, you could probably use a small js script like $('a.delete-attachment').remove(); to remove the link.

  • This doesn't work because the element isn't added to the DOM yet when the code runs for the remove so it doesn't remove it. I tried to do the following: $('a.delete-attachment').click(function (e){ alert('it is clicked'); e.preventDefault(); }); which doesn't work either. This is because my JS file isn't loaded from the admin section and is only enqueued from my functions.php file. How can I have this loaded even in the admin section? – user1048676 Jan 14 '15 at 0:55
  • For some reason on the front end the editor was being weird and wouldn't let me click on the image. I was testing with the admin panel but that wasn't obviously my question – user1048676 Jan 14 '15 at 4:08
  • I was finally able to test this and the small script isn't working. I can still click on the link and it tries to delete the image. Since it looks like the media-template.php file adds this after the dom is loaded I tried to change my code to use on with jquery but the link is still clickable and tries to delete the image: $( 'a.delete-attachment' ).on( 'click', function(e) { e.preventDefault(); alert( 'it is in here' ); }); – user1048676 Jan 14 '15 at 17:04
0

I actually found this:
https://stackoverflow.com/questions/25894288/wordpress-remove-attachment-fields

I actually just added the following in my CSS file to basically remove the links at all times:

.media-sidebar .details .edit-attachment {
    display: none;
}
.media-sidebar .details .delete-attachment {
    display: none;
}

To actually show this within the admin section I actually show it by using the following code:

foreach( array( 'post.php', 'post-new.php' ) as $hook )
    add_action( "admin_print_styles-$hook", 'admin_styles_so_25894288');

function admin_styles_so_25894288() {
    global $typenow;
    if( 'post' !== $typenow )
        return;
    ?>
    <style>
        .media-sidebar .details .delete-attachment
        { 
            display: block; 
        }
        .media-sidebar .details .edit-attachment
        { 
            display: block; 
        }
    </style>
    <?php

}

This is tested in Wordpress 4.0.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.