Skip to content

Instantly share code, notes, and snippets.

@matthew-macgregor
Created December 19, 2016 02:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthew-macgregor/1412bfff848d28aea6258cc516d0973a to your computer and use it in GitHub Desktop.
Save matthew-macgregor/1412bfff848d28aea6258cc516d0973a to your computer and use it in GitHub Desktop.
Hide the admin panel from users without certain capabilities.
<?php
/**
* 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 ( ! defined('DOING_AJAX') && ! 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