Skip to content

Instantly share code, notes, and snippets.

@amdrew
Created March 20, 2015 01:21
Show Gist options
  • Save amdrew/599f3a35495e38c4f681 to your computer and use it in GitHub Desktop.
Save amdrew/599f3a35495e38c4f681 to your computer and use it in GitHub Desktop.
/**
* AffiliateWP - login and redirect affiliates to affiliate area
* All other users are redirected to the site's homepage
*
* Works when user logs in via the page where the [affiliate_login] shortcode is used
* Works when affiliate logs in via wp-login.php page so they don't see the admin
*/
function affwp_custom_login_redirect( $user_login, $user ) {
$user_id = $user->ID;
// Redirect for affiliates
if ( function_exists( 'affwp_is_affiliate' ) && affwp_is_affiliate( $user_id ) ) {
$redirect = affiliate_wp()->login->get_login_url(); // affiliate dashboard
wp_redirect( $redirect ); exit;
}
}
add_action( 'wp_login', 'affwp_custom_login_redirect', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment