3

Is there an easy way to create an admin user that has read only permissions? That is, they can login and see everything an admin can, but they cannot change anything at all.

1 Answer 1

1

Is there an easy way...

AFAIK, no, not at all.

If using a single site installation, you'd need to carefully disable (not hide, disable) all possible user actions that modify things. And this has to be done screen by screen (Posts, Pages, Comments, Appearance, Plugins, etc).

For example, in the All Posts screen (/wp-admin/edit.php):

/**
 * Remove all row actions Edit|Quick Edit|Trash|View
 */
add_filter( 'post_row_actions', 'wpse_56560_remove_row_actions', 10, 2 );    
function wpse_56560_remove_row_actions( $actions, $post ) 
{
    global $current_user;
    if( 'pseudo-admin' == $current_user->user_login )
        return array();

    return $actions; 
}

/**
 * Remove the Trash link from All|Published|Trash
 */
add_filter( 'views_edit-post', 'wpse_74488_remove_trash_link' );   
function wpse_74488_remove_trash_link( $views ) 
{
    global $current_user;
    if( 'pseudo-admin' == $current_user->user_login )
        unset( $views['trash'] );

    return $views;
}

In the Post Edit screen (/wp-admin/post.php?post=ID&action=edit):

/**
 * Remove the Publish meta box
 */
add_action( 'do_meta_boxes', 'wpse33063_remove_meta_box' );
function wpse33063_remove_meta_box()
{
    global $current_user;
    if( 'pseudo-admin' == $current_user->user_login )
        remove_meta_box( 'submitdiv', 'post', 'side' );
}

In the previous examples, all function names contain the ID of the WPSE Question where they were taken from.

Also, refer to this Gist to see how to redirect users if they try to access a page using a direct URL.


If using a Multisite installation, @BrianFegter Answer to this Question: How can I open up my administrative panel to everyone?, has this nice suggestion:

I would use WP Multisite and allow users to register a test site. Woo Themes does this with their playground feature.

2
  • The problem with this is they can still edit the posts if they type in the correct link. Is it not possible to remove caps but keep the post type visible? If I make a custom post type and only give a user the read cap, it doesn't show up... Only when they have edit/delete caps as well.
    – Tom
    Commented Oct 21, 2020 at 19:52
  • I don't quite understand what you want to do with the caps, but to block users from direct access we have to redirect them in admin_head or another suitable hook (see Gist that I mentioned)
    – brasofilo
    Commented Oct 22, 2020 at 5:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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