Last active
December 11, 2015 23:05
-
-
Save TangChr/0ca44cc0c2c77da58186 to your computer and use it in GitHub Desktop.
PHP: Enable sessions ($_SESSION) in WordPress plugins and themes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Session Activator | |
Description: Enable the use of sessions ($_SESSION) in plugins and themes. | |
Version: 1.0.0 | |
Author: Christian Tang | |
Author URI: http://christiantang.dk | |
*/ | |
add_action('init', 'session_activator_start', 1); | |
add_action('wp_logout', 'session_activator_end'); | |
add_action('wp_login', 'session_activator_end'); | |
function session_activator_start() { | |
if(!session_id()) { | |
session_start(); | |
} | |
} | |
function session_activator_end() { | |
session_destroy(); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment