Created
February 12, 2015 20:28
-
-
Save cgrymala/a203590f8cbf9b16c4e5 to your computer and use it in GitHub Desktop.
Keep Subscribers Out of the WP Admin Area
This file contains 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 | |
add_action( 'admin_init', 'hide_backend_from_user' ); | |
/** | |
* Hide the backend from specific user levels | |
* @uses VFH_User_Controls::$options['login_redirect_to'] to determine where the user should be redirected | |
* @uses VFH_User_Controls::$user_levels to see if the user needs to be redirected | |
*/ | |
function hide_backend_from_user( $level='edit_posts' ) { | |
/** | |
* Attempt not to short-circuit AJAX requests | |
*/ | |
if ( function_exists( 'doing_ajax' ) && doing_ajax() ) { | |
return; | |
} | |
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { | |
return; | |
} | |
if ( ! is_user_logged_in() ) | |
return; | |
if ( ! current_user_can( $level ) ) { | |
wp_safe_redirect( home_url() ); | |
exit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment