START SESSION ON INIT
1 2 3 4 5 6 |
add_action('init', 'pluginStartSession', 1); function pluginStartSession() { if(!session_id()) { session_start(); } } |
NEW SESSION ON LOGIN / LOGOUT
1 2 3 4 5 6 |
add_action('wp_logout', 'pluginEndSession'); add_action('wp_login', 'pluginEndSession'); function pluginEndSession() { session_destroy (); } |
Now go ahead and use $_SESSION freely in your plugin. Here a nice additional class to encrypt session data.