Enabling Sessions in WordPress 3.0

If you need to manually enable the session globally, use this in your functions.php (I included a line for manually setting a session variable as an example, not required):

add_action('init', 'session_manager');
function session_manager() {
    if (!session_id()) {
        session_start();
    }
    $_SESSION['foo'] = 'bar';
}

and if you wanted to manually clear the session on an event (like logging out):

add_action('wp_logout', 'session_logout');
function session_logout() {
        session_destroy();
}

Leave a Comment