Skip to content

Instantly share code, notes, and snippets.

@kakoma
Created March 7, 2017 07:53
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 kakoma/8e1525d8fe32aff61486ca706d45e1f7 to your computer and use it in GitHub Desktop.
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
<?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