Last active
March 22, 2018 16:09
-
-
Save beatwiz/060dc8dae715f46851a7592f680115fe to your computer and use it in GitHub Desktop.
[wordpress] Block all users except admin (and ajax requests) from dashboard / wp-login
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 USERS EXCEPT ADMIN FROM DASHBOARD / WP-LOGIN | |
add_action( 'init', 'blockusers_init' ); | |
function blockusers_init() { | |
if ( is_admin() && ! current_user_can( 'administrator' ) && | |
! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { | |
wp_redirect( home_url() ); | |
exit; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment