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!
You can put this in your
functions.php
: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.