PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.4.9
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.4.9
1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 1.7.0.9 1.8.0 All 210 releases
charitable / includes / libraries / wp-session / wp-session.php

wp-session.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.4.9, at includes/libraries/wp-session/wp-session.php

170 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WordPress session managment.
4 *
5 * Standardizes WordPress session data and uses either database transients or in-memory caching
6 * for storing user session information.
7 *
8 * @package WordPress
9 * @subpackage Session
10 * @since 3.7.0
11 */
12
13 /**
14 * Return the current cache expire setting.
15 *
16 * @return int
17 */
18 function wp_session_cache_expire() {
19 $wp_session = WP_Session::get_instance();
20
21 return $wp_session->cache_expiration();
22 }
23
24 /**
25 * Alias of wp_session_write_close()
26 */
27 function wp_session_commit() {
28 wp_session_write_close();
29 }
30
31 /**
32 * Load a JSON-encoded string into the current session.
33 *
34 * @param string $data
35 */
36 function wp_session_decode( $data ) {
37 $wp_session = WP_Session::get_instance();
38
39 return $wp_session->json_in( $data );
40 }
41
42 /**
43 * Encode the current session's data as a JSON string.
44 *
45 * @return string
46 */
47 function wp_session_encode() {
48 $wp_session = WP_Session::get_instance();
49
50 return $wp_session->json_out();
51 }
52
53 /**
54 * Regenerate the session ID.
55 *
56 * @param bool $delete_old_session
57 *
58 * @return bool
59 */
60 function wp_session_regenerate_id( $delete_old_session = false ) {
61 $wp_session = WP_Session::get_instance();
62
63 $wp_session->regenerate_id( $delete_old_session );
64
65 return true;
66 }
67
68 /**
69 * Start new or resume existing session.
70 *
71 * Resumes an existing session based on a value sent by the _wp_session cookie.
72 *
73 * @return bool
74 */
75 function wp_session_start() {
76 $wp_session = WP_Session::get_instance();
77 do_action( 'wp_session_start' );
78
79 return $wp_session->session_started();
80 }
81 add_action( 'plugins_loaded', 'wp_session_start' );
82
83 /**
84 * Return the current session status.
85 *
86 * @return int
87 */
88 function wp_session_status() {
89 $wp_session = WP_Session::get_instance();
90
91 if ( $wp_session->session_started() ) {
92 return PHP_SESSION_ACTIVE;
93 }
94
95 return PHP_SESSION_NONE;
96 }
97
98 /**
99 * Unset all session variables.
100 */
101 function wp_session_unset() {
102 $wp_session = WP_Session::get_instance();
103
104 $wp_session->reset();
105 }
106
107 /**
108 * Write session data and end session
109 */
110 function wp_session_write_close() {
111 $wp_session = WP_Session::get_instance();
112
113 $wp_session->write_data();
114 do_action( 'wp_session_commit' );
115 }
116 add_action( 'shutdown', 'wp_session_write_close' );
117
118 /**
119 * Clean up expired sessions by removing data and their expiration entries from
120 * the WordPress options table.
121 *
122 * This method should never be called directly and should instead be triggered as part
123 * of a scheduled task or cron job.
124 */
125 function wp_session_cleanup() {
126 global $wpdb;
127
128 if ( defined( 'WP_SETUP_CONFIG' ) ) {
129 return;
130 }
131
132 if ( ! defined( 'WP_INSTALLING' ) ) {
133 $expiration_keys = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE option_name LIKE '_wp_session_expires_%'" );
134
135 $now = time();
136 $expired_sessions = array();
137
138 foreach( $expiration_keys as $expiration ) {
139 // If the session has expired
140 if ( $now > intval( $expiration->option_value ) ) {
141 // Get the session ID by parsing the option_name
142 $session_id = addslashes(substr( $expiration->option_name, 20 ));
143
144 $expired_sessions[] = $expiration->option_name;
145 $expired_sessions[] = "_wp_session_$session_id";
146 }
147 }
148
149 // Delete all expired sessions in a single query
150 if ( ! empty( $expired_sessions ) ) {
151 $option_names = implode( "','", $expired_sessions );
152 $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name IN ('$option_names')" );
153 }
154 }
155
156 // Allow other plugins to hook in to the garbage collection process.
157 do_action( 'wp_session_cleanup' );
158 }
159 add_action( 'wp_session_garbage_collection', 'wp_session_cleanup' );
160
161 /**
162 * Register the garbage collector as a twice daily event.
163 */
164 function wp_session_register_garbage_collection() {
165 if ( ! wp_next_scheduled( 'wp_session_garbage_collection' ) ) {
166 wp_schedule_event( time(), 'hourly', 'wp_session_garbage_collection' );
167 }
168 }
169 add_action( 'wp', 'wp_session_register_garbage_collection' );
170