Skip to content

Instantly share code, notes, and snippets.

@amdrew
Last active April 6, 2017 15:07
Show Gist options
  • Save amdrew/1119f025ad896c05e2f5 to your computer and use it in GitHub Desktop.
Save amdrew/1119f025ad896c05e2f5 to your computer and use it in GitHub Desktop.
AffiliateWP - Custom logout redirect for Affiliates
<?php
/**
* AffiliateWP - Custom logout redirect for Affiliates
* By default, a user is sent to the wp-login.php?loggedout=true page
* Affiliates are logged out to the affiliate dashboard login screen
* Normal WP users are logged out and redirected to the site URL
*/
function affwp_custom_logout_redirect( $logout_url, $redirect ) {
if ( function_exists( 'affwp_is_affiliate' ) && affwp_is_affiliate() ) {
$redirect = affiliate_wp()->login->get_login_url();
} else {
$redirect = site_url();
}
$args = array( 'action' => 'logout' );
if ( ! empty( $redirect ) ) {
$args['redirect_to'] = urlencode( $redirect );
}
return add_query_arg( $args, $logout_url );
}
add_filter( 'logout_url', 'affwp_custom_logout_redirect', 10, 2 );
@ivica31
Copy link

ivica31 commented Dec 4, 2016

/** Or you could use something like this and paste into your functions.php preferably located in a child theme "/

add_action('wp_logout','auto_redirect_after_logout');

function auto_redirect_after_logout(){
wp_redirect( 'http://www.yoursite.com');
exit();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment