Created
August 31, 2020 10:25
-
-
Save wpflames/4c04adc82b84e1908f89cf2eb0949784 to your computer and use it in GitHub Desktop.
Disallow access to WordPress admin area for specific users
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
| //=================================================== | |
| // DISALLOW ACCESS TO WPADMIN AREA FOR SPECIFIC USERS | |
| //=================================================== | |
| function wps6543_no_admin_access() | |
| { | |
| if ( | |
| ! is_admin() | |
| || ( | |
| is_user_logged_in() | |
| && isset( $GLOBALS['pagenow'] ) AND 'wp-login.php' === $GLOBALS['pagenow'] | |
| ) | |
| ) { | |
| return; | |
| } | |
| $redirect = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : home_url( '/' ); | |
| if ( | |
| current_user_can( 'CAPABILITY_NAME_HERE' ) | |
| OR current_user_can( 'CAPABILITY_NAME_HERE' ) | |
| ) | |
| exit( wp_redirect( $redirect ) ); | |
| } | |
| add_action( 'admin_init', 'wps6543_no_admin_access', 100 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment