0

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

function tasks_admin_sessions() {
    if(!session_id()) {
        session_start();
    }
}
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

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'].

2
  • I wouldn't ask if I hadn't tried Google, will try that, but it shouldn't make a difference, I think I am adding the init wrong but will double check with caps Commented Dec 18, 2016 at 3:50
  • Google again - [link]stackoverflow.com/questions/2297007/….
    – Tedinoz
    Commented Dec 18, 2016 at 12:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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