Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Tsunamijaan/4eccebe6f721f5b9048b112eaeae7d08 to your computer and use it in GitHub Desktop.

Select an option

Save Tsunamijaan/4eccebe6f721f5b9048b112eaeae7d08 to your computer and use it in GitHub Desktop.
Restrict Admin Area To Only Admin Users
function restrict_admin()
{
if ( ! current_user_can( 'manage_options' ) ) {
wp_redirect( site_url() );
exit;
}
}
add_action( 'admin_init', 'restrict_admin', 1 );
Or
Only Allow Admins Into The Admin Area:
===================================================
function admin_login_redirect( $redirect_to, $request, $user )
{
global $user;
if( isset( $user->roles ) && is_array( $user->roles ) ) {
if( in_array( "administrator", $user->roles ) ) {
return $redirect_to;
} else {
return home_url();
}
}
else
{
return $redirect_to;
}
}
add_filter("login_redirect", "admin_login_redirect", 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment