Skip to content

Instantly share code, notes, and snippets.

@WebEndevSnippets
Created February 17, 2013 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WebEndevSnippets/4971725 to your computer and use it in GitHub Desktop.
Save WebEndevSnippets/4971725 to your computer and use it in GitHub Desktop.
WordPress: Restrict Access to WP Admin to Administrators Only
add_action( 'admin_init', 'webendev_restrict_admin_with_redirect', 1 );
/**
* Restrict Access to WP Admin to Administrators Only
*
*/
function webendev_restrict_admin_with_redirect() {
if ( ! current_user_can( 'manage_options' ) && $_SERVER['PHP_SELF'] != '/wp-admin/admin-ajax.php' ) {
wp_redirect( site_url() ); exit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment