Created
December 21, 2020 09:37
-
-
Save rohit-ghoghari/804035bab038fa74d4bf4239b186031f to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Block wp-admin access for non-admins | |
*/ | |
function block_wp_admin_access_callback() { | |
if ( is_admin() && ! current_user_can( 'administrator' ) && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { | |
wp_safe_redirect( home_url() ); | |
exit; | |
} | |
} | |
add_action( 'admin_init', 'block_wp_admin_access_callback' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment