Replies: 0
I’m adding a bit of simple code to record a user’s referrer on a site. Unfortunately, the session variable is not passing through to registration.
The user goes to site.com?ref=999 (where 999 is the referring member’s user ID).
In my included php file, I have the following:
// Add action to kick off a session and detect ref id
add_action('init','was_start_session');
// Add action to store ref id after registration
add_action('user_register', 'was_record_referrer', 10, 1);
// Function to record referrer ID in session
function was_start_session() {
// Check for an active session: if there is none, start one.
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
// Check for referrer and store in session.
// If there is no referrer, assign to "user zero".
$_SESSION['ref'] = (isset($_GET['ref'])) ? $_GET['ref'] : 0;
}
// Record referrer's user id in new user meta
function was_record_referrer($user_id) {
update_user_meta($user_id, '_user_referrer', $_SESSION['ref']);
}
I added an echo command after setting the session ‘ref’ variable and it shows the right value (999). I added the same echo to the bottom function and it invariably shows zero. WordPress is dropping the variable between their arrival on the site and registering.
Any ideas why?