Trying to access sessions in the WP admin and access a variable from it.

function tasks_admin_sessions() {
    if(!session_id()) {
add_action( 'admin_init', 'tasks_admin_sessions', 1 );

$nonce = $_session['wp_nonce']
$completed_url = admin_url( "post.php?post=$post_id&action=trash&_wpnonce=$nonce" );

but I get:

Notice: Undefined variable: _session

What am I missing in my code to get the session variables?

1 Answer 1


Google is your friend. How to use session_start in Wordpress? and How to use session in wordpress in plugin development

It looks like your mistake is that you didn't capitalise "Session" when you declare the variable.

Instead of $_session['wp_nonce'], try $_SESSION['wp_nonce'].


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.