Comments screen in backend, how to disable Quick Edit | Edit | History | Spam | for non admins

The question:

I’m trying to adjust the comments screen for non admins to my project.
Right now I’d like to disable

Quick Edit | Edit | History | Spam

under any comment left for any post created by the user.

Thanks!

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

This is done filtering the *_row_actions.
For the Comments screen (/wp-admin/edit-comments.php) this is the hook:

add_filter( 'comment_row_actions', 'comments_row_wpse_92313', 15, 2 );

function comments_row_wpse_92313( $actions, $comment )
{
    if( !current_user_can( 'delete_plugins' ) )
        unset( $actions['quickedit'], $actions['edit'], $actions['spam'] );

    return $actions;
}

I cannot see a History option, maybe it’s included by some plugin (?). It’s a matter of adding it to the unset list.
These are the default actions in the core files:

$actions = array(
    'approve' => '', 
    'unapprove' => '',
    'reply' => '',
    'quickedit' => '',
    'edit' => '',
    'spam' => '', 
    'unspam' => '',
    'trash' => '', 
    'untrash' => '', 
    'delete' => ''
);


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment