Created
March 7, 2017 07:53
-
-
Save kakoma/8e1525d8fe32aff61486ca706d45e1f7 to your computer and use it in GitHub Desktop.
For those who would like to redirect KSD customers to a special URL on login
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 | |
//Based on https://codex.wordpress.org/Plugin_API/Filter_Reference/login_redirect | |
/** | |
* Redirect KSD customer after successful login. | |
* | |
* @param string $redirect_to URL to redirect to. | |
* @param string $request URL the user is coming from. | |
* @param object $user Logged user's data. | |
* @return string | |
*/ | |
function ksd_customer_login_redirect( $redirect_to, $request, $user ) { | |
if ( isset( $user->roles ) && is_array( $user->roles ) ) { | |
//check for KSD customers | |
if ( in_array( 'ksd_customer', $user->roles ) ) { | |
//change home_url() to wherever you want to redirect KSD customers to | |
return home_url(); | |
} else { | |
// redirect the rest to the default place | |
return $redirect_to; | |
} | |
} else { | |
return $redirect_to; | |
} | |
} | |
add_filter( 'login_redirect', 'ksd_customer_login_redirect', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment