Created
May 30, 2016 11:52
-
-
Save ricardobrg/9a3b18b4329de069ffb24e756b68ab45 to your computer and use it in GitHub Desktop.
Simple WordPress login redirect. Can be used as a mu-plugin or in functions.php
This file contains 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 | |
function brg_login_redirect( $redirect_to, $request, $user ) { | |
global $user; | |
//if there's a user with defined roles | |
if ( isset( $user->roles ) && is_array( $user->roles ) ) { | |
//check if it's admin | |
if ( in_array( 'administrator', $user->roles ) ) { | |
//admins can go anywhere | |
return $redirect_to; | |
} else { | |
//non-admins go to home | |
return home_url(); | |
} | |
//there's no user roles to check | |
} else { | |
//go home | |
return home_url(); | |
} | |
} | |
add_filter( 'login_redirect', 'brg_login_redirect', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment