Restrict Admin and Toolbar Access

Restrict access to backend based on user role:

function wpse23007_redirect(){
if( is_admin() && !defined('DOING_AJAX') && ( current_user_can('subscriber') || current_user_can('intranet-user') ) ){
wp_redirect(home_url());
exit;
}
}
add_action('init','wpse23007_redirect');

Hide admin toolbar based on user role:

function cc_wpse_278096_disable_admin_bar() {
if (current_user_can('administrator') || current_user_can('contributor') || current_user_can('editor') ) {
// user can view admin bar
show_admin_bar(true); // this line isn't essentially needed by default...
} else {
// hide admin bar
show_admin_bar(false);
}
}
add_action('after_setup_theme', 'cc_wpse_278096_disable_admin_bar');

Source.

Leave a Reply

katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.