i have a WordPress affiliate site, i need to add a link for affiliates to be able to register downline while logged in, but since the WordPress registration form cannot be accessed by logged in users, I am trying to create a function to log the user out on click of button and redirect to the signup page using the affiliate referral link. so far i have this code
add_action('check_admin_referer', 'logout_without_confirm', 10, 2);
function logout_without_confirm($action, $result)
{
$user = wp_get_current_user();
if ($action == "log-out" && !isset($_GET['_wpnonce'])) {
$redirect_to = isset($_REQUEST['redirect_to']) ? $_REQUEST['redirect_to'] : '/join-now/?ref=echo".$user->user_login."';
$location = str_replace('&', '&', wp_logout_url($redirect_to));
header("Location: $location");
die;
}
}
when i click the button, it logs out but i am unable to get the user id in the URL. please i will appreciate some help
I expect that when I click on the add affiliate button, it logs the current user out and redirect to the affiliates referral link so his id is captured as the referrer.