1

Update: This snippet below removes the menu also for my admin account:

function remove_menu_items() {

    global $menu;
    global $user_ID; 

    if( $user_ID ) :

        /* Dashboard only acccess */
        if( current_user_can( 'Dashboardvisitors' ) ) :

            $restricted = array(
                __('Posts'),
                __('Media'),
                __('Pages'),
                __('Links'),
                __('Appearance'),
                __('Tools'),
                __('Users'),
                __('Settings'),
                __('Comments'),
                __('Plugins')
            );

        endif;

    endif;  

    end ( $menu );

    while ( prev( $menu ) ) :
        $value = explode( ' ', $menu[key($menu)][0] );
        if( in_array( $value[0] != NULL?$value[0]:"" , $restricted ) ) :
            unset( $menu[key($menu)] );
        endif;
    endwhile;

}
add_action('admin_menu', 'remove_menu_items');

How can I give a user access to the dashboard only?

More specifically, I want them to be able to see the wordpress stats widget and the google analytics widget. That's it.

I've created a new user with the role dashboardvisitors using the plugin USER ROLE EDITOR.

Now level 0 plus read access doesn't cut it. The dashboard is just empty.

Adding edit dashboard doesn't change anything. Still nothing there (but I don't want them to be able to edit the dashboard anyways).

How can I make this happen? It's very important, so thanks a lot!

1 Answer 1

1

You can put this in your functions.php :

function remove_menu_items() {

    global $menu;
    global $user_ID; 

    if( $user_ID ) :

        /* Dashboard only acccess */
        if( current_user_can( 'dashboardvisitors' ) ) :

                $restricted = array(
                    __('Posts'),
                    __('Pages'),
                    __('Links'), 
                    [etc...]
            );

        endif;

    endif;  

    end ( $menu );

    while ( prev( $menu ) ) :
        $value = explode( ' ', $menu[key($menu)][0] );
        if( in_array( $value[0] != NULL?$value[0]:"" , $restricted ) ) :
            unset( $menu[key($menu)] );
        endif;
    endwhile;

}
add_action('admin_menu', 'remove_menu_items');

What it does is that for each user of the role 'dashboardvisitors' going to the WP admin, it removes the menu items listed in the restricted array. If you list all the admin sections except the dashboard in that array you should have a dashboard only admin.

1
  • Thanks @mike23, where can I find a list of all the arrays that I can/should remove?
    – Simon
    Commented Jun 24, 2011 at 14:35

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.