Skip to content

Instantly share code, notes, and snippets.

@beatwiz
Last active March 22, 2018 16:09
Show Gist options
  • Save beatwiz/060dc8dae715f46851a7592f680115fe to your computer and use it in GitHub Desktop.
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
<?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