Skip to content

Instantly share code, notes, and snippets.

@TangChr
Last active December 11, 2015 23:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TangChr/0ca44cc0c2c77da58186 to your computer and use it in GitHub Desktop.
Save TangChr/0ca44cc0c2c77da58186 to your computer and use it in GitHub Desktop.
PHP: Enable sessions ($_SESSION) in WordPress plugins and themes
<?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