Skip to content

Instantly share code, notes, and snippets.

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 Kudratullah/34f5174a00dd0002b0fa to your computer and use it in GitHub Desktop.
Save Kudratullah/34f5174a00dd0002b0fa to your computer and use it in GitHub Desktop.
Restrict Non Admin User To Home Page of WordPress Site
<?php
if(!function_exists("redirect_non_admin_users")):
/**
* Redirect non-admin users to home page
*/
function redirect_non_admin_users() {
global $currentUser;
if ( is_admin() && ! current_user_can( 'manage_options' )
&& '/wp-admin/admin-ajax.php' != $_SERVER['PHP_SELF']
&& ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
wp_redirect( home_url() );
die();
}
}
add_action( 'admin_init', 'redirect_non_admin_users' );
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment