Last active
March 5, 2016 07:00
-
-
Save Kudratullah/34f5174a00dd0002b0fa to your computer and use it in GitHub Desktop.
Restrict Non Admin User To Home Page of WordPress Site
This file contains hidden or 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 | |
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