Created
September 30, 2020 17:09
-
-
Save corypina/070311d84fe1a26edf97d44d7898ec20 to your computer and use it in GitHub Desktop.
Prevent Subscribers from accessing wp-admin
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 | |
// If users have multiple roles, refactor line 7 to check for required | |
// roles instead of rejecting Subscribers | |
add_action( 'init', function () { | |
if ( is_admin() | |
&& in_array( 'subscriber', (array) $user->roles ) | |
&& ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) | |
) { wp_redirect( '/' ); exit; } | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment