Skip to content

Instantly share code, notes, and snippets.

@azanebrain
Created December 11, 2013 05:43
Show Gist options
  • Save azanebrain/7905601 to your computer and use it in GitHub Desktop.
Save azanebrain/7905601 to your computer and use it in GitHub Desktop.
Don't allow subscribers to view the admin panels or the admin bar
/**
* Disable admin bar on the frontend of your website
* for subscribers.
*/
function themeblvd_disable_admin_bar() {
if( ! current_user_can('edit_posts') )
add_filter('show_admin_bar', '__return_false');
}
add_action( 'after_setup_theme', 'themeblvd_disable_admin_bar' );
/**
* Redirect back to homepage and not allow access to
* WP admin for Subscribers.
*/
function themeblvd_redirect_admin(){
if ( ! current_user_can( 'edit_posts' ) ){
wp_redirect( site_url() );
exit;
}
}
add_action( 'admin_init', 'themeblvd_redirect_admin' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment