Skip to content

Instantly share code, notes, and snippets.

@rohit-ghoghari
Created December 21, 2020 09:37
Show Gist options
  • Save rohit-ghoghari/804035bab038fa74d4bf4239b186031f to your computer and use it in GitHub Desktop.
Save rohit-ghoghari/804035bab038fa74d4bf4239b186031f to your computer and use it in GitHub Desktop.
<?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