2

Hovering my mouse over a file name or a thumbnail brings up the Edit option, I want to know is there any hook to disable all edit links in Media library on Multisite enter image description here

  • 1
    What is your context for requirement? Should items be absolutely uneditable? Only for specific users or other conditions? – Rarst Jul 25 '13 at 14:14
3

There're several filters that you can utilize:

Custom column content

If you got a custom column that you added with the ``-filter, then you can use the

manage_{$post->post_type}_posts_custom_column

filter to alter the content. If you only want to target non-hierarchial post types then there's as well the manage_posts_custom_column and for hierarchical ones, there's manage_pages_custom_column. All three filters have two arguemnts: $column_name, $post->ID.

For the media library there's a special filter: manage_media_custom_column.

Removing actions

IIRC, there's the following filter to add or remove different actions:

apply_filters( 'bulk_actions-' . $this->screen->id, $this->_actions );

You should be able to obtain the screen ID from get_current_screen()->ID.

For the media library it's - again - a special case and you have to use the

apply_filters( 'media_row_actions', $actions, $post, $this->detached );

filter.

Make sure that you don't use $this-> inside your callback arguments as you're not in object context.

Removing the image link

So far there's no possibility to completely remove the <a href="" ... tag without a lot of effort. But you can (simply) set the link target to the current page with using the get_edit_post_link-filter.

Just re-target it to sprintf( '#post-%s', $post_id );:

add_filter( 'get_edit_post_link', 'wpse107783_remove_media_icon_link', 20, 2 );
function wpse107783_remove_media_icon_link( $url, $post_id )
{
    if ( 'upload' !== get_current_screen()->id )
        return $url;

    return sprintf( '#post-%s', $post_id );
}

Why not CSS or JS?

Still people could remove event listeners or CSS rules via their developer tools, which is something you might not want.

Redirect

A real lock out can only happen server side based on roles and capabilities.

add_action( 'template_redirect', 'wpse107783_redirect_media_edit' );
function wpse107783_redirect_media_edit()
{
    if (
        ! is_admin()
        OR 'attachment' !== get_current_screen()->id
    )
        return;

    exit( wp_redirect( admin_url() ) );
}

Note: I'm not sure if template_redirect is the right hook here. It might as well be admin_menu or init.

2

Add some CSS to admin_head to hide the image actions bar, and hide the edit button once clicking into the image:

This should do the trick:

function hide_image_edit_link() {
    echo "<style type=\"text/css\">
            table.media .row-actions {display:none;}
            .wp_attachment_image input[id^=\"imgedit-open-btn\"] {display:none;}
        </style>";
}
add_action('admin_head', 'hide_image_edit_link');
  • 1
    I can still edit files clicking on a file name or a thumbnail – Ghinnersmee Jul 25 '13 at 13:35
  • This wasn't clear from your question. Code updated, to also hide the button when clicking into the image, I presume you don't want to disable this entirely. – Matt.C Jul 25 '13 at 15:29

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.