Skip to content

Instantly share code, notes, and snippets.

@greenhornet79
Created February 6, 2015 21:14
Show Gist options
  • Save greenhornet79/947276fe0198046c8b57 to your computer and use it in GitHub Desktop.
Save greenhornet79/947276fe0198046c8b57 to your computer and use it in GitHub Desktop.
Hide WordPress admin from subscribers
// remove admin bar from free users
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
show_admin_bar(false);
}
}
// don't allow users to access WordPress admin
add_action('admin_init', 'no_mo_dashboard');
function no_mo_dashboard() {
if ( ! current_user_can( 'manage_options' ) && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
wp_redirect(home_url()); exit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment