Created
December 19, 2016 02:43
-
-
Save matthew-macgregor/1412bfff848d28aea6258cc516d0973a to your computer and use it in GitHub Desktop.
Hide the admin panel from users without certain capabilities.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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