Skip to content

Instantly share code, notes, and snippets.

@mikeselander
Created July 2, 2014 23:25
Show Gist options
  • Save mikeselander/80ed5b81804c55bae347 to your computer and use it in GitHub Desktop.
Save mikeselander/80ed5b81804c55bae347 to your computer and use it in GitHub Desktop.
Remove admin bar & keep end users out of the WordPress backend
/**
* Remove admin bar & admin access for non-managers & non-admins
* @access public
* @since 0.1.0
*/
add_action('admin_init', 'no_mo_dashboard');
add_action('after_setup_theme', 'remove_admin_bar');
function no_mo_dashboard() {
if ( ! current_user_can( 'edit_others_posts' ) && '/wp-admin/admin-ajax.php' != $_SERVER['PHP_SELF'] ) {
wp_redirect( site_url() ); exit;
}
}
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
show_admin_bar(false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment