/** * Generate a number of dummy sessions for testing purposes. * * ## OPTIONS * * <count> * : Number of sessions to create. * * [--expires=<date>] * : Optional expiration time tagged for each session. Will use WordPress' local time. * * ## EXAMPLES * * wp session generate 5000 * wp session generate 5000 --expires="2014-11-09T08:00" * * @synopsis <count> [--expires=<date>] * * @param array $args * @param array $assoc_args */ public function generate($args, $assoc_args) { $count = absint($args[0]); $date = isset($assoc_args['expires']) ? $assoc_args['expires'] : null; $notify = \WP_CLI\Utils\make_progress_bar('Generating sessions', $count); for ($i = 0; $i < $count; $i++) { WP_Session_Utils::create_dummy_session($date); $notify->tick(); } $notify->finish(); }
/** * Clean up expired sessions by removing data and their expiration entries from * the WordPress options table. * * This method should never be called directly and should instead be triggered as part * of a scheduled task or cron job. */ function wp_session_cleanup() { if (defined('WP_SETUP_CONFIG')) { return; } if (!defined('WP_INSTALLING')) { /** * Determine the size of each batch for deletion. * * @param int */ $batch_size = apply_filters('wp_session_delete_batch_size', 1000); // Delete a batch of old sessions WP_Session_Utils::delete_old_sessions($batch_size); } // Allow other plugins to hook in to the garbage collection process. do_action('wp_session_cleanup'); }
/** * Regenerate the current session's ID. * * @param bool $delete_old Flag whether or not to delete the old session data from the server. */ public function regenerate_id($delete_old = false) { if ($delete_old) { delete_option("_wp_session_{$this->session_id}"); } $this->session_id = WP_Session_Utils::generate_id(); $this->set_cookie(); }