Changeset 2007451
- Timestamp:
- 01/07/2019 05:21:14 AM (7 years ago)
- Location:
- wp-session-manager
- Files:
-
- 8 edited
- 1 copied
-
tags/4.1.0 (copied) (copied from wp-session-manager/trunk)
-
tags/4.1.0/composer.json (modified) (1 diff)
-
tags/4.1.0/includes/DatabaseHandler.php (modified) (2 diffs)
-
tags/4.1.0/readme.txt (modified) (3 diffs)
-
tags/4.1.0/wp-session-manager.php (modified) (3 diffs)
-
trunk/composer.json (modified) (1 diff)
-
trunk/includes/DatabaseHandler.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (3 diffs)
-
trunk/wp-session-manager.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-session-manager/tags/4.1.0/composer.json
r2004699 r2007451 2 2 "name" : "ericmann/wp-session-manager", 3 3 "description" : "Prototype session management for WordPress.", 4 "version" : "4. 0.0",4 "version" : "4.1.0", 5 5 "type" : "wordpress-plugin", 6 6 "keywords" : ["session"], -
wp-session-manager/tags/4.1.0/includes/DatabaseHandler.php
r2004699 r2007451 253 253 * @param callable $next Next clean operation in the stack. 254 254 * 255 * @global \wpdb $wpdb256 *257 255 * @return mixed 258 256 */ 259 257 public function clean($maxlifetime, $next) 258 { 259 self::directClean(); 260 261 return $next($maxlifetime); 262 } 263 264 /** 265 * Update the database by removing any sessions that are no longer valid 266 * 267 * @global \wpdb $wpdb 268 */ 269 public static function directClean() 260 270 { 261 271 global $wpdb; … … 270 280 ); 271 281 } 272 273 return $next($maxlifetime);274 282 } 275 283 } -
wp-session-manager/tags/4.1.0/readme.txt
r2004699 r2007451 6 6 Tested up to: 5.0.2 7 7 Requires PHP: 7.1 8 Stable tag: 4. 0.08 Stable tag: 4.1.0 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 55 55 ` 56 56 57 = I get an error saying my PHP version is out of date. Why? = 58 59 PHP 5.6 was designated end-of-life and stopped receiving security patches in December 2018. PHP 7.0 was _also_ marked end-of-life in December 2018. The minimum version of PHP supported by WP Session Manager is now PHP 7.1. 60 61 If your server is running an older version of PHP, the session system _will not work!_ To avoid triggering a PHP error, the plugin will instead output this notice to upgrade and disable itself silently. You won't see a PHP error, but you also won't get session support. 62 63 Reach out to your hosting provider or system administrator to upgrade your server. 64 65 = I get an error saying another plugin is setting up a session. What can I do? = 66 67 WP Session Manager overrides PHP's default session implementation with its own custom handler. Unfortunately, we can't swap in a new handler if a session is already active. This plugin hooks into the `plugins_loaded` hook to set things up as early as possible, but if you have code in _another_ plugin (or your theme) that attempts to invoke `session_start()` before WP Session Manager loads, then the custom handler won't work at all. 68 69 Inspect your other plugins and try to find the one that's interfering. Then, reach out to the developer to explain the conflict and see if they have a fix. 70 57 71 == Screenshots == 58 72 … … 60 74 61 75 == Changelog == 76 77 = 4.1.0 = 78 * Fix: Add some defense to ensure end users are running the correct version of PHP before loading the system. 79 * Fix: Eliminate a race condition where another plugin or the theme created the session first. 80 * Fix: Schedule a cron to auto-delete expired sessions. 62 81 63 82 = 4.0.0 = -
wp-session-manager/tags/4.1.0/wp-session-manager.php
r2004699 r2007451 4 4 * Plugin URI: https://paypal.me/eam 5 5 * Description: Session management for WordPress. 6 * Version: 4. 0.06 * Version: 4.1.0 7 7 * Author: Eric Mann 8 8 * Author URI: https://eamann.com … … 12 12 */ 13 13 14 $wp_session_autoload = __DIR__ . '/vendor/autoload.php'; 15 if (file_exists($wp_session_autoload)) { 16 require_once $wp_session_autoload; 14 if (!defined('WP_SESSION_MINIMUM_PHP_VERSION')) { 15 define('WP_SESSION_MINIMUM_PHP_VERSION', '7.1.0'); 17 16 } 18 17 19 if (!class_exists('EAMann\Sessionz\Manager')) { 20 exit('WP Session Manager requires Composer autoloading, which is not configured'); 18 $wp_session_messages = [ 19 'bad_php_version' => sprintf( 20 __( 21 'WP Session Manager requires PHP %s or newer. Please contact your system administrator to upgrade!', 22 'wp-session-manager' 23 ), 24 WP_SESSION_MINIMUM_PHP_VERSION, 25 PHP_VERSION 26 ), 27 'multiple_sessions' => __( 28 'Another plugin is attempting to start a session with WordPress. WP Session Manager will not work!', 29 'wp-session-manager' 30 ) 31 ]; 32 33 /** 34 * Initialize the plugin, bootstrap autoloading, and register default hooks 35 */ 36 function wp_session_manager_initialize() 37 { 38 $wp_session_autoload = __DIR__ . '/vendor/autoload.php'; 39 if (file_exists($wp_session_autoload)) { 40 require_once $wp_session_autoload; 41 } 42 43 if (!class_exists('EAMann\Sessionz\Manager')) { 44 exit('WP Session Manager requires Composer autoloading, which is not configured'); 45 } 46 47 if (!isset($_SESSION)) { 48 // Queue up the session stack. 49 $wp_session_handler = EAMann\Sessionz\Manager::initialize(); 50 51 // Fall back to database storage where needed. 52 if (defined('WP_SESSION_USE_OPTIONS') && WP_SESSION_USE_OPTIONS) { 53 $wp_session_handler->addHandler(new \EAMann\WPSession\OptionsHandler()); 54 } else { 55 $wp_session_handler->addHandler(new \EAMann\WPSession\DatabaseHandler()); 56 57 /** 58 * The database handler can automatically clean up sessions as it goes. By default, 59 * we'll run the cleanup routine every hour to catch any stale sessions that PHP's 60 * garbage collector happens to miss. This timeout can be filtered to increase or 61 * decrease the frequency of the manual purge. 62 * 63 * @param string $timeout Interval with which to purge stale sessions 64 */ 65 $timeout = apply_filters('wp_session_gc_interval', 'hourly'); 66 67 if (!wp_next_scheduled('wp_session_database_gc')) { 68 wp_schedule_event(time(), $timeout, 'wp_session_database_gc'); 69 } 70 71 add_action('wp_session_database_gc', ['EAMann\WPSession\DatabaseHandler', 'directClean']); 72 } 73 74 // If we have an external object cache, let's use it! 75 if (wp_using_ext_object_cache()) { 76 $wp_session_handler->addHandler(new EAMann\WPSession\CacheHandler()); 77 } 78 79 // Decrypt the data surfacing from external storage. 80 if (defined('WP_SESSION_ENC_KEY') && WP_SESSION_ENC_KEY) { 81 $wp_session_handler->addHandler(new \EAMann\Sessionz\Handlers\EncryptionHandler(WP_SESSION_ENC_KEY)); 82 } 83 84 // Use an in-memory cache for the instance if we can. This will only help in rare cases. 85 $wp_session_handler->addHandler(new \EAMann\Sessionz\Handlers\MemoryHandler()); 86 87 $_SESSION['wp_session_manager'] = 'active'; 88 } 89 90 if (! isset($_SESSION['wp_session_manager']) || $_SESSION['wp_session_manager'] !== 'active') { 91 add_action('admin_notices', 'wp_session_manager_multiple_sessions_notice'); 92 return; 93 } 94 95 // Create the required table. 96 \EAMann\WPSession\DatabaseHandler::createTable(); 97 98 register_deactivation_hook(__FILE__, function () { 99 wp_clear_scheduled_hook('wp_session_database_gc'); 100 }); 21 101 } 22 102 23 // Queue up the session stack. 24 $wp_session_handler = EAMann\Sessionz\Manager::initialize(); 25 26 // Fall back to database storage where needed. 27 if (defined('WP_SESSION_USE_OPTIONS') && WP_SESSION_USE_OPTIONS) { 28 $wp_session_handler->addHandler(new \EAMann\WPSession\OptionsHandler()); 29 } else { 30 $wp_session_handler->addHandler(new \EAMann\WPSession\DatabaseHandler()); 103 /** 104 * Print an admin notice if too many plugins are manipulating sessions. 105 * 106 * @global array $wp_session_messages 107 */ 108 function wp_session_manager_multiple_sessions_notice() 109 { 110 global $wp_session_messages; 111 ?> 112 <div class="notice notice-error"> 113 <p><?php echo esc_html($wp_session_messages['multiple_sessions']); ?></p> 114 </div> 115 <?php 31 116 } 32 117 33 // If we have an external object cache, let's use it! 34 if (wp_using_ext_object_cache()) { 35 $wp_session_handler->addHandler(new EAMann\WPSession\CacheHandler()); 118 /** 119 * Print an admin notice if we're on a bad version of PHP. 120 * 121 * @global array $wp_session_messages 122 */ 123 function wp_session_manager_deactivated_notice() 124 { 125 global $wp_session_messages; 126 ?> 127 <div class="notice notice-error"> 128 <p><?php echo esc_html($wp_session_messages['bad_php_version']); ?></p> 129 </div> 130 <?php 36 131 } 37 38 // Decrypt the data surfacing from external storage.39 if (defined('WP_SESSION_ENC_KEY') && WP_SESSION_ENC_KEY) {40 $wp_session_handler->addHandler(new \EAMann\Sessionz\Handlers\EncryptionHandler(WP_SESSION_ENC_KEY));41 }42 43 // Use an in-memory cache for the instance if we can. This will only help in rare cases.44 $wp_session_handler->addHandler(new \EAMann\Sessionz\Handlers\MemoryHandler());45 46 // Create the required table.47 add_action('admin_init', ['EAMann\WPSession\DatabaseHandler', 'createTable']);48 add_action('wp_session_init', ['EAMann\WPSession\DatabaseHandler', 'createTable']);49 add_action('wp_install', ['EAMann\WPSession\DatabaseHandler', 'createTable']);50 register_activation_hook(__FILE__, ['EAMann\WPSession\DatabaseHandler', 'createTable']);51 132 52 133 /** … … 55 136 function wp_session_manager_start_session() 56 137 { 57 $bootstrap = \EAMann\WPSession\DatabaseHandler::createTable(); 58 59 if (! is_wp_error($bootstrap) && session_status() !== PHP_SESSION_ACTIVE) { 138 if (session_status() !== PHP_SESSION_ACTIVE) { 60 139 session_start(); 61 140 } 62 141 } 63 142 64 // Start up session management, if we're not in the CLI. 65 if (!defined('WP_CLI') || false === WP_CLI) { 66 add_action('plugins_loaded', 'wp_session_manager_start_session', 10, 0); 143 // WordPress won't enforce the minimum version of PHP for us, so we need to check. 144 if (version_compare(PHP_VERSION, WP_SESSION_MINIMUM_PHP_VERSION, '<')) { 145 add_action('admin_notices', 'wp_session_manager_deactivated_notice'); 146 } else { 147 add_action('plugins_loaded', 'wp_session_manager_initialize', 1, 0); 148 149 // Start up session management, if we're not in the CLI. 150 if (!defined('WP_CLI') || false === WP_CLI) { 151 add_action('plugins_loaded', 'wp_session_manager_start_session', 10, 0); 152 } 67 153 } -
wp-session-manager/trunk/composer.json
r2004699 r2007451 2 2 "name" : "ericmann/wp-session-manager", 3 3 "description" : "Prototype session management for WordPress.", 4 "version" : "4. 0.0",4 "version" : "4.1.0", 5 5 "type" : "wordpress-plugin", 6 6 "keywords" : ["session"], -
wp-session-manager/trunk/includes/DatabaseHandler.php
r2004699 r2007451 253 253 * @param callable $next Next clean operation in the stack. 254 254 * 255 * @global \wpdb $wpdb256 *257 255 * @return mixed 258 256 */ 259 257 public function clean($maxlifetime, $next) 258 { 259 self::directClean(); 260 261 return $next($maxlifetime); 262 } 263 264 /** 265 * Update the database by removing any sessions that are no longer valid 266 * 267 * @global \wpdb $wpdb 268 */ 269 public static function directClean() 260 270 { 261 271 global $wpdb; … … 270 280 ); 271 281 } 272 273 return $next($maxlifetime);274 282 } 275 283 } -
wp-session-manager/trunk/readme.txt
r2004699 r2007451 6 6 Tested up to: 5.0.2 7 7 Requires PHP: 7.1 8 Stable tag: 4. 0.08 Stable tag: 4.1.0 9 9 License: GPLv2 or later 10 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 55 55 ` 56 56 57 = I get an error saying my PHP version is out of date. Why? = 58 59 PHP 5.6 was designated end-of-life and stopped receiving security patches in December 2018. PHP 7.0 was _also_ marked end-of-life in December 2018. The minimum version of PHP supported by WP Session Manager is now PHP 7.1. 60 61 If your server is running an older version of PHP, the session system _will not work!_ To avoid triggering a PHP error, the plugin will instead output this notice to upgrade and disable itself silently. You won't see a PHP error, but you also won't get session support. 62 63 Reach out to your hosting provider or system administrator to upgrade your server. 64 65 = I get an error saying another plugin is setting up a session. What can I do? = 66 67 WP Session Manager overrides PHP's default session implementation with its own custom handler. Unfortunately, we can't swap in a new handler if a session is already active. This plugin hooks into the `plugins_loaded` hook to set things up as early as possible, but if you have code in _another_ plugin (or your theme) that attempts to invoke `session_start()` before WP Session Manager loads, then the custom handler won't work at all. 68 69 Inspect your other plugins and try to find the one that's interfering. Then, reach out to the developer to explain the conflict and see if they have a fix. 70 57 71 == Screenshots == 58 72 … … 60 74 61 75 == Changelog == 76 77 = 4.1.0 = 78 * Fix: Add some defense to ensure end users are running the correct version of PHP before loading the system. 79 * Fix: Eliminate a race condition where another plugin or the theme created the session first. 80 * Fix: Schedule a cron to auto-delete expired sessions. 62 81 63 82 = 4.0.0 = -
wp-session-manager/trunk/wp-session-manager.php
r2004699 r2007451 4 4 * Plugin URI: https://paypal.me/eam 5 5 * Description: Session management for WordPress. 6 * Version: 4. 0.06 * Version: 4.1.0 7 7 * Author: Eric Mann 8 8 * Author URI: https://eamann.com … … 12 12 */ 13 13 14 $wp_session_autoload = __DIR__ . '/vendor/autoload.php'; 15 if (file_exists($wp_session_autoload)) { 16 require_once $wp_session_autoload; 14 if (!defined('WP_SESSION_MINIMUM_PHP_VERSION')) { 15 define('WP_SESSION_MINIMUM_PHP_VERSION', '7.1.0'); 17 16 } 18 17 19 if (!class_exists('EAMann\Sessionz\Manager')) { 20 exit('WP Session Manager requires Composer autoloading, which is not configured'); 18 $wp_session_messages = [ 19 'bad_php_version' => sprintf( 20 __( 21 'WP Session Manager requires PHP %s or newer. Please contact your system administrator to upgrade!', 22 'wp-session-manager' 23 ), 24 WP_SESSION_MINIMUM_PHP_VERSION, 25 PHP_VERSION 26 ), 27 'multiple_sessions' => __( 28 'Another plugin is attempting to start a session with WordPress. WP Session Manager will not work!', 29 'wp-session-manager' 30 ) 31 ]; 32 33 /** 34 * Initialize the plugin, bootstrap autoloading, and register default hooks 35 */ 36 function wp_session_manager_initialize() 37 { 38 $wp_session_autoload = __DIR__ . '/vendor/autoload.php'; 39 if (file_exists($wp_session_autoload)) { 40 require_once $wp_session_autoload; 41 } 42 43 if (!class_exists('EAMann\Sessionz\Manager')) { 44 exit('WP Session Manager requires Composer autoloading, which is not configured'); 45 } 46 47 if (!isset($_SESSION)) { 48 // Queue up the session stack. 49 $wp_session_handler = EAMann\Sessionz\Manager::initialize(); 50 51 // Fall back to database storage where needed. 52 if (defined('WP_SESSION_USE_OPTIONS') && WP_SESSION_USE_OPTIONS) { 53 $wp_session_handler->addHandler(new \EAMann\WPSession\OptionsHandler()); 54 } else { 55 $wp_session_handler->addHandler(new \EAMann\WPSession\DatabaseHandler()); 56 57 /** 58 * The database handler can automatically clean up sessions as it goes. By default, 59 * we'll run the cleanup routine every hour to catch any stale sessions that PHP's 60 * garbage collector happens to miss. This timeout can be filtered to increase or 61 * decrease the frequency of the manual purge. 62 * 63 * @param string $timeout Interval with which to purge stale sessions 64 */ 65 $timeout = apply_filters('wp_session_gc_interval', 'hourly'); 66 67 if (!wp_next_scheduled('wp_session_database_gc')) { 68 wp_schedule_event(time(), $timeout, 'wp_session_database_gc'); 69 } 70 71 add_action('wp_session_database_gc', ['EAMann\WPSession\DatabaseHandler', 'directClean']); 72 } 73 74 // If we have an external object cache, let's use it! 75 if (wp_using_ext_object_cache()) { 76 $wp_session_handler->addHandler(new EAMann\WPSession\CacheHandler()); 77 } 78 79 // Decrypt the data surfacing from external storage. 80 if (defined('WP_SESSION_ENC_KEY') && WP_SESSION_ENC_KEY) { 81 $wp_session_handler->addHandler(new \EAMann\Sessionz\Handlers\EncryptionHandler(WP_SESSION_ENC_KEY)); 82 } 83 84 // Use an in-memory cache for the instance if we can. This will only help in rare cases. 85 $wp_session_handler->addHandler(new \EAMann\Sessionz\Handlers\MemoryHandler()); 86 87 $_SESSION['wp_session_manager'] = 'active'; 88 } 89 90 if (! isset($_SESSION['wp_session_manager']) || $_SESSION['wp_session_manager'] !== 'active') { 91 add_action('admin_notices', 'wp_session_manager_multiple_sessions_notice'); 92 return; 93 } 94 95 // Create the required table. 96 \EAMann\WPSession\DatabaseHandler::createTable(); 97 98 register_deactivation_hook(__FILE__, function () { 99 wp_clear_scheduled_hook('wp_session_database_gc'); 100 }); 21 101 } 22 102 23 // Queue up the session stack. 24 $wp_session_handler = EAMann\Sessionz\Manager::initialize(); 25 26 // Fall back to database storage where needed. 27 if (defined('WP_SESSION_USE_OPTIONS') && WP_SESSION_USE_OPTIONS) { 28 $wp_session_handler->addHandler(new \EAMann\WPSession\OptionsHandler()); 29 } else { 30 $wp_session_handler->addHandler(new \EAMann\WPSession\DatabaseHandler()); 103 /** 104 * Print an admin notice if too many plugins are manipulating sessions. 105 * 106 * @global array $wp_session_messages 107 */ 108 function wp_session_manager_multiple_sessions_notice() 109 { 110 global $wp_session_messages; 111 ?> 112 <div class="notice notice-error"> 113 <p><?php echo esc_html($wp_session_messages['multiple_sessions']); ?></p> 114 </div> 115 <?php 31 116 } 32 117 33 // If we have an external object cache, let's use it! 34 if (wp_using_ext_object_cache()) { 35 $wp_session_handler->addHandler(new EAMann\WPSession\CacheHandler()); 118 /** 119 * Print an admin notice if we're on a bad version of PHP. 120 * 121 * @global array $wp_session_messages 122 */ 123 function wp_session_manager_deactivated_notice() 124 { 125 global $wp_session_messages; 126 ?> 127 <div class="notice notice-error"> 128 <p><?php echo esc_html($wp_session_messages['bad_php_version']); ?></p> 129 </div> 130 <?php 36 131 } 37 38 // Decrypt the data surfacing from external storage.39 if (defined('WP_SESSION_ENC_KEY') && WP_SESSION_ENC_KEY) {40 $wp_session_handler->addHandler(new \EAMann\Sessionz\Handlers\EncryptionHandler(WP_SESSION_ENC_KEY));41 }42 43 // Use an in-memory cache for the instance if we can. This will only help in rare cases.44 $wp_session_handler->addHandler(new \EAMann\Sessionz\Handlers\MemoryHandler());45 46 // Create the required table.47 add_action('admin_init', ['EAMann\WPSession\DatabaseHandler', 'createTable']);48 add_action('wp_session_init', ['EAMann\WPSession\DatabaseHandler', 'createTable']);49 add_action('wp_install', ['EAMann\WPSession\DatabaseHandler', 'createTable']);50 register_activation_hook(__FILE__, ['EAMann\WPSession\DatabaseHandler', 'createTable']);51 132 52 133 /** … … 55 136 function wp_session_manager_start_session() 56 137 { 57 $bootstrap = \EAMann\WPSession\DatabaseHandler::createTable(); 58 59 if (! is_wp_error($bootstrap) && session_status() !== PHP_SESSION_ACTIVE) { 138 if (session_status() !== PHP_SESSION_ACTIVE) { 60 139 session_start(); 61 140 } 62 141 } 63 142 64 // Start up session management, if we're not in the CLI. 65 if (!defined('WP_CLI') || false === WP_CLI) { 66 add_action('plugins_loaded', 'wp_session_manager_start_session', 10, 0); 143 // WordPress won't enforce the minimum version of PHP for us, so we need to check. 144 if (version_compare(PHP_VERSION, WP_SESSION_MINIMUM_PHP_VERSION, '<')) { 145 add_action('admin_notices', 'wp_session_manager_deactivated_notice'); 146 } else { 147 add_action('plugins_loaded', 'wp_session_manager_initialize', 1, 0); 148 149 // Start up session management, if we're not in the CLI. 150 if (!defined('WP_CLI') || false === WP_CLI) { 151 add_action('plugins_loaded', 'wp_session_manager_start_session', 10, 0); 152 } 67 153 }
Note: See TracChangeset
for help on using the changeset viewer.