Completed
Branch FET/11406/add-user-id-notices (2f10ee)
by
unknown
62:49 queued 50:36
created
core/EE_Session.core.php 3 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
 
249 249
 
250 250
     /**
251
-     * @return int
251
+     * @return boolean
252 252
      */
253 253
     public function isActive()
254 254
     {
@@ -528,7 +528,7 @@  discard block
 block discarded – undo
528 528
     /**
529 529
      * @initiate session
530 530
      * @access   private
531
-     * @return TRUE on success, FALSE on fail
531
+     * @return boolean on success, FALSE on fail
532 532
      * @throws EE_Error
533 533
      * @throws InvalidArgumentException
534 534
      * @throws InvalidDataTypeException
@@ -764,7 +764,7 @@  discard block
 block discarded – undo
764 764
      * @update session data  prior to saving to the db
765 765
      * @access public
766 766
      * @param bool $new_session
767
-     * @return TRUE on success, FALSE on fail
767
+     * @return boolean on success, FALSE on fail
768 768
      * @throws EE_Error
769 769
      * @throws InvalidArgumentException
770 770
      * @throws InvalidDataTypeException
@@ -865,7 +865,7 @@  discard block
 block discarded – undo
865 865
      * _save_session_to_db
866 866
      *
867 867
      * @param bool $clear_session
868
-     * @return string
868
+     * @return boolean
869 869
      * @throws EE_Error
870 870
      * @throws InvalidArgumentException
871 871
      * @throws InvalidDataTypeException
Please login to merge, or discard this patch.
Indentation   +1224 added lines, -1224 removed lines patch added patch discarded remove patch
@@ -20,1227 +20,1227 @@  discard block
 block discarded – undo
20 20
 class EE_Session implements SessionIdentifierInterface
21 21
 {
22 22
 
23
-    const session_id_prefix    = 'ee_ssn_';
24
-
25
-    const hash_check_prefix    = 'ee_shc_';
26
-
27
-    const OPTION_NAME_SETTINGS = 'ee_session_settings';
28
-
29
-    const EE_SESSION_STATUS_CLOSED = 0;
30
-
31
-    const EE_SESSION_STATUS_OPEN = 1;
32
-
33
-    /**
34
-     * instance of the EE_Session object
35
-     *
36
-     * @var EE_Session
37
-     */
38
-    private static $_instance;
39
-
40
-    /**
41
-     * @var CacheStorageInterface $cache_storage
42
-     */
43
-    protected $cache_storage;
44
-
45
-    /**
46
-     * EE_Encryption object
47
-     *
48
-     * @var EE_Encryption
49
-     */
50
-    protected $encryption;
51
-
52
-    /**
53
-     * the session id
54
-     *
55
-     * @var string
56
-     */
57
-    private $_sid;
58
-
59
-    /**
60
-     * session id salt
61
-     *
62
-     * @var string
63
-     */
64
-    private $_sid_salt;
65
-
66
-    /**
67
-     * session data
68
-     *
69
-     * @var array
70
-     */
71
-    private $_session_data = array();
72
-
73
-    /**
74
-     * how long an EE session lasts
75
-     * default session lifespan of 2 hours (for not so instant IPNs)
76
-     *
77
-     * @var int
78
-     */
79
-    private $_lifespan;
80
-
81
-    /**
82
-     * session expiration time as Unix timestamp in GMT
83
-     *
84
-     * @var int
85
-     */
86
-    private $_expiration;
87
-
88
-    /**
89
-     * whether or not session has expired at some point
90
-     *
91
-     * @var boolean
92
-     */
93
-    private $_expired = false;
94
-
95
-    /**
96
-     * current time as Unix timestamp in GMT
97
-     *
98
-     * @var int
99
-     */
100
-    private $_time;
101
-
102
-    /**
103
-     * whether to encrypt session data
104
-     *
105
-     * @var bool
106
-     */
107
-    private $_use_encryption;
108
-
109
-    /**
110
-     * well... according to the server...
111
-     *
112
-     * @var null
113
-     */
114
-    private $_user_agent;
115
-
116
-    /**
117
-     * do you really trust the server ?
118
-     *
119
-     * @var null
120
-     */
121
-    private $_ip_address;
122
-
123
-    /**
124
-     * current WP user_id
125
-     *
126
-     * @var null
127
-     */
128
-    private $_wp_user_id;
129
-
130
-    /**
131
-     * array for defining default session vars
132
-     *
133
-     * @var array
134
-     */
135
-    private $_default_session_vars = array(
136
-        'id'            => null,
137
-        'user_id'       => null,
138
-        'ip_address'    => null,
139
-        'user_agent'    => null,
140
-        'init_access'   => null,
141
-        'last_access'   => null,
142
-        'expiration'    => null,
143
-        'pages_visited' => array(),
144
-    );
145
-
146
-    /**
147
-     * timestamp for when last garbage collection cycle was performed
148
-     *
149
-     * @var int $_last_gc
150
-     */
151
-    private $_last_gc;
152
-
153
-    /**
154
-     * whether session is active or not
155
-     *
156
-     * @var int $status
157
-     */
158
-    private $status = EE_Session::EE_SESSION_STATUS_CLOSED;
159
-
160
-
161
-
162
-    /**
163
-     * @singleton method used to instantiate class object
164
-     * @param CacheStorageInterface $cache_storage
165
-     * @param EE_Encryption         $encryption
166
-     * @return EE_Session
167
-     * @throws InvalidArgumentException
168
-     * @throws InvalidDataTypeException
169
-     * @throws InvalidInterfaceException
170
-     */
171
-    public static function instance(
172
-        CacheStorageInterface $cache_storage = null,
173
-        EE_Encryption $encryption = null
174
-    ) {
175
-        // check if class object is instantiated
176
-        // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via:
177
-        // add_filter( 'FHEE_load_EE_Session', '__return_false' );
178
-        if (! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) {
179
-            self::$_instance = new self($cache_storage, $encryption);
180
-        }
181
-        return self::$_instance;
182
-    }
183
-
184
-
185
-
186
-    /**
187
-     * protected constructor to prevent direct creation
188
-     *
189
-     * @param CacheStorageInterface $cache_storage
190
-     * @param EE_Encryption         $encryption
191
-     * @throws InvalidArgumentException
192
-     * @throws InvalidDataTypeException
193
-     * @throws InvalidInterfaceException
194
-     */
195
-    protected function __construct(CacheStorageInterface $cache_storage, EE_Encryption $encryption = null)
196
-    {
197
-        // session loading is turned ON by default,
198
-        // but prior to the 'AHEE__EE_System__core_loaded_and_ready' hook
199
-        // (which currently fires on the init hook at priority 9),
200
-        // can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' );
201
-        if (! apply_filters('FHEE_load_EE_Session', true)) {
202
-            return;
203
-        }
204
-        if (! defined('ESPRESSO_SESSION')) {
205
-            define('ESPRESSO_SESSION', true);
206
-        }
207
-        // default session lifespan in seconds
208
-        $this->_lifespan = apply_filters(
209
-                               'FHEE__EE_Session__construct___lifespan',
210
-                               60 * MINUTE_IN_SECONDS
211
-                           ) + 1;
212
-        /*
23
+	const session_id_prefix    = 'ee_ssn_';
24
+
25
+	const hash_check_prefix    = 'ee_shc_';
26
+
27
+	const OPTION_NAME_SETTINGS = 'ee_session_settings';
28
+
29
+	const EE_SESSION_STATUS_CLOSED = 0;
30
+
31
+	const EE_SESSION_STATUS_OPEN = 1;
32
+
33
+	/**
34
+	 * instance of the EE_Session object
35
+	 *
36
+	 * @var EE_Session
37
+	 */
38
+	private static $_instance;
39
+
40
+	/**
41
+	 * @var CacheStorageInterface $cache_storage
42
+	 */
43
+	protected $cache_storage;
44
+
45
+	/**
46
+	 * EE_Encryption object
47
+	 *
48
+	 * @var EE_Encryption
49
+	 */
50
+	protected $encryption;
51
+
52
+	/**
53
+	 * the session id
54
+	 *
55
+	 * @var string
56
+	 */
57
+	private $_sid;
58
+
59
+	/**
60
+	 * session id salt
61
+	 *
62
+	 * @var string
63
+	 */
64
+	private $_sid_salt;
65
+
66
+	/**
67
+	 * session data
68
+	 *
69
+	 * @var array
70
+	 */
71
+	private $_session_data = array();
72
+
73
+	/**
74
+	 * how long an EE session lasts
75
+	 * default session lifespan of 2 hours (for not so instant IPNs)
76
+	 *
77
+	 * @var int
78
+	 */
79
+	private $_lifespan;
80
+
81
+	/**
82
+	 * session expiration time as Unix timestamp in GMT
83
+	 *
84
+	 * @var int
85
+	 */
86
+	private $_expiration;
87
+
88
+	/**
89
+	 * whether or not session has expired at some point
90
+	 *
91
+	 * @var boolean
92
+	 */
93
+	private $_expired = false;
94
+
95
+	/**
96
+	 * current time as Unix timestamp in GMT
97
+	 *
98
+	 * @var int
99
+	 */
100
+	private $_time;
101
+
102
+	/**
103
+	 * whether to encrypt session data
104
+	 *
105
+	 * @var bool
106
+	 */
107
+	private $_use_encryption;
108
+
109
+	/**
110
+	 * well... according to the server...
111
+	 *
112
+	 * @var null
113
+	 */
114
+	private $_user_agent;
115
+
116
+	/**
117
+	 * do you really trust the server ?
118
+	 *
119
+	 * @var null
120
+	 */
121
+	private $_ip_address;
122
+
123
+	/**
124
+	 * current WP user_id
125
+	 *
126
+	 * @var null
127
+	 */
128
+	private $_wp_user_id;
129
+
130
+	/**
131
+	 * array for defining default session vars
132
+	 *
133
+	 * @var array
134
+	 */
135
+	private $_default_session_vars = array(
136
+		'id'            => null,
137
+		'user_id'       => null,
138
+		'ip_address'    => null,
139
+		'user_agent'    => null,
140
+		'init_access'   => null,
141
+		'last_access'   => null,
142
+		'expiration'    => null,
143
+		'pages_visited' => array(),
144
+	);
145
+
146
+	/**
147
+	 * timestamp for when last garbage collection cycle was performed
148
+	 *
149
+	 * @var int $_last_gc
150
+	 */
151
+	private $_last_gc;
152
+
153
+	/**
154
+	 * whether session is active or not
155
+	 *
156
+	 * @var int $status
157
+	 */
158
+	private $status = EE_Session::EE_SESSION_STATUS_CLOSED;
159
+
160
+
161
+
162
+	/**
163
+	 * @singleton method used to instantiate class object
164
+	 * @param CacheStorageInterface $cache_storage
165
+	 * @param EE_Encryption         $encryption
166
+	 * @return EE_Session
167
+	 * @throws InvalidArgumentException
168
+	 * @throws InvalidDataTypeException
169
+	 * @throws InvalidInterfaceException
170
+	 */
171
+	public static function instance(
172
+		CacheStorageInterface $cache_storage = null,
173
+		EE_Encryption $encryption = null
174
+	) {
175
+		// check if class object is instantiated
176
+		// session loading is turned ON by default, but prior to the init hook, can be turned back OFF via:
177
+		// add_filter( 'FHEE_load_EE_Session', '__return_false' );
178
+		if (! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) {
179
+			self::$_instance = new self($cache_storage, $encryption);
180
+		}
181
+		return self::$_instance;
182
+	}
183
+
184
+
185
+
186
+	/**
187
+	 * protected constructor to prevent direct creation
188
+	 *
189
+	 * @param CacheStorageInterface $cache_storage
190
+	 * @param EE_Encryption         $encryption
191
+	 * @throws InvalidArgumentException
192
+	 * @throws InvalidDataTypeException
193
+	 * @throws InvalidInterfaceException
194
+	 */
195
+	protected function __construct(CacheStorageInterface $cache_storage, EE_Encryption $encryption = null)
196
+	{
197
+		// session loading is turned ON by default,
198
+		// but prior to the 'AHEE__EE_System__core_loaded_and_ready' hook
199
+		// (which currently fires on the init hook at priority 9),
200
+		// can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' );
201
+		if (! apply_filters('FHEE_load_EE_Session', true)) {
202
+			return;
203
+		}
204
+		if (! defined('ESPRESSO_SESSION')) {
205
+			define('ESPRESSO_SESSION', true);
206
+		}
207
+		// default session lifespan in seconds
208
+		$this->_lifespan = apply_filters(
209
+							   'FHEE__EE_Session__construct___lifespan',
210
+							   60 * MINUTE_IN_SECONDS
211
+						   ) + 1;
212
+		/*
213 213
          * do something like the following to adjust the session lifespan:
214 214
          * 		public static function session_lifespan() {
215 215
          * 			return 15 * MINUTE_IN_SECONDS;
216 216
          * 		}
217 217
          */
218
-        // retrieve session options from db
219
-        $session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array());
220
-        if (! empty($session_settings)) {
221
-            // cycle though existing session options
222
-            foreach ($session_settings as $var_name => $session_setting) {
223
-                // set values for class properties
224
-                $var_name          = '_' . $var_name;
225
-                $this->{$var_name} = $session_setting;
226
-            }
227
-        }
228
-        $this->cache_storage = $cache_storage;
229
-        // are we using encryption?
230
-        $this->_use_encryption = $encryption instanceof EE_Encryption
231
-                                 && EE_Registry::instance()->CFG->admin->encode_session_data();
232
-        // \EEH_Debug_Tools::printr($this->_use_encryption, '$this->_use_encryption', __FILE__, __LINE__);
233
-        // encrypt data via: $this->encryption->encrypt();
234
-        $this->encryption = $encryption;
235
-        // filter hook allows outside functions/classes/plugins to change default empty cart
236
-        $extra_default_session_vars = apply_filters('FHEE__EE_Session__construct__extra_default_session_vars', array());
237
-        array_merge($this->_default_session_vars, $extra_default_session_vars);
238
-        // apply default session vars
239
-        $this->_set_defaults();
240
-        add_action('AHEE__EE_System__initialize', array($this, 'open_session'));
241
-        // check request for 'clear_session' param
242
-        add_action('AHEE__EE_Request_Handler__construct__complete', array($this, 'wp_loaded'));
243
-        // once everything is all said and done,
244
-        add_action('shutdown', array($this, 'update'), 100);
245
-        add_action('shutdown', array($this, 'garbageCollection'), 1000);
246
-        $this->configure_garbage_collection_filters();
247
-    }
248
-
249
-
250
-    /**
251
-     * @return int
252
-     */
253
-    public function isActive()
254
-    {
255
-        return $this->status === EE_Session::EE_SESSION_STATUS_OPEN;
256
-    }
257
-
258
-
259
-
260
-    /**
261
-     * @return void
262
-     * @throws EE_Error
263
-     * @throws InvalidArgumentException
264
-     * @throws InvalidDataTypeException
265
-     * @throws InvalidInterfaceException
266
-     * @throws InvalidSessionDataException
267
-     */
268
-    public function open_session()
269
-    {
270
-        // check for existing session and retrieve it from db
271
-        if (! $this->_espresso_session()) {
272
-            // or just start a new one
273
-            $this->_create_espresso_session();
274
-        }
275
-    }
276
-
277
-
278
-
279
-    /**
280
-     * @return bool
281
-     */
282
-    public function expired()
283
-    {
284
-        return $this->_expired;
285
-    }
286
-
287
-
288
-
289
-    /**
290
-     * @return void
291
-     */
292
-    public function reset_expired()
293
-    {
294
-        $this->_expired = false;
295
-    }
296
-
297
-
298
-    /**
299
-     * @return int
300
-     */
301
-    public function expiration()
302
-    {
303
-        return $this->_expiration;
304
-    }
305
-
306
-
307
-
308
-    /**
309
-     * @return int
310
-     */
311
-    public function extension()
312
-    {
313
-        return apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS);
314
-    }
315
-
316
-
317
-
318
-    /**
319
-     * @param int $time number of seconds to add to session expiration
320
-     */
321
-    public function extend_expiration($time = 0)
322
-    {
323
-        $time              = $time ? $time : $this->extension();
324
-        $this->_expiration += absint($time);
325
-    }
326
-
327
-
328
-
329
-    /**
330
-     * @return int
331
-     */
332
-    public function lifespan()
333
-    {
334
-        return $this->_lifespan;
335
-    }
336
-
337
-
338
-
339
-    /**
340
-     * This just sets some defaults for the _session data property
341
-     *
342
-     * @access private
343
-     * @return void
344
-     */
345
-    private function _set_defaults()
346
-    {
347
-        // set some defaults
348
-        foreach ($this->_default_session_vars as $key => $default_var) {
349
-            if (is_array($default_var)) {
350
-                $this->_session_data[ $key ] = array();
351
-            } else {
352
-                $this->_session_data[ $key ] = '';
353
-            }
354
-        }
355
-    }
218
+		// retrieve session options from db
219
+		$session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array());
220
+		if (! empty($session_settings)) {
221
+			// cycle though existing session options
222
+			foreach ($session_settings as $var_name => $session_setting) {
223
+				// set values for class properties
224
+				$var_name          = '_' . $var_name;
225
+				$this->{$var_name} = $session_setting;
226
+			}
227
+		}
228
+		$this->cache_storage = $cache_storage;
229
+		// are we using encryption?
230
+		$this->_use_encryption = $encryption instanceof EE_Encryption
231
+								 && EE_Registry::instance()->CFG->admin->encode_session_data();
232
+		// \EEH_Debug_Tools::printr($this->_use_encryption, '$this->_use_encryption', __FILE__, __LINE__);
233
+		// encrypt data via: $this->encryption->encrypt();
234
+		$this->encryption = $encryption;
235
+		// filter hook allows outside functions/classes/plugins to change default empty cart
236
+		$extra_default_session_vars = apply_filters('FHEE__EE_Session__construct__extra_default_session_vars', array());
237
+		array_merge($this->_default_session_vars, $extra_default_session_vars);
238
+		// apply default session vars
239
+		$this->_set_defaults();
240
+		add_action('AHEE__EE_System__initialize', array($this, 'open_session'));
241
+		// check request for 'clear_session' param
242
+		add_action('AHEE__EE_Request_Handler__construct__complete', array($this, 'wp_loaded'));
243
+		// once everything is all said and done,
244
+		add_action('shutdown', array($this, 'update'), 100);
245
+		add_action('shutdown', array($this, 'garbageCollection'), 1000);
246
+		$this->configure_garbage_collection_filters();
247
+	}
248
+
249
+
250
+	/**
251
+	 * @return int
252
+	 */
253
+	public function isActive()
254
+	{
255
+		return $this->status === EE_Session::EE_SESSION_STATUS_OPEN;
256
+	}
257
+
258
+
259
+
260
+	/**
261
+	 * @return void
262
+	 * @throws EE_Error
263
+	 * @throws InvalidArgumentException
264
+	 * @throws InvalidDataTypeException
265
+	 * @throws InvalidInterfaceException
266
+	 * @throws InvalidSessionDataException
267
+	 */
268
+	public function open_session()
269
+	{
270
+		// check for existing session and retrieve it from db
271
+		if (! $this->_espresso_session()) {
272
+			// or just start a new one
273
+			$this->_create_espresso_session();
274
+		}
275
+	}
276
+
277
+
278
+
279
+	/**
280
+	 * @return bool
281
+	 */
282
+	public function expired()
283
+	{
284
+		return $this->_expired;
285
+	}
286
+
287
+
288
+
289
+	/**
290
+	 * @return void
291
+	 */
292
+	public function reset_expired()
293
+	{
294
+		$this->_expired = false;
295
+	}
296
+
297
+
298
+	/**
299
+	 * @return int
300
+	 */
301
+	public function expiration()
302
+	{
303
+		return $this->_expiration;
304
+	}
305
+
306
+
307
+
308
+	/**
309
+	 * @return int
310
+	 */
311
+	public function extension()
312
+	{
313
+		return apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS);
314
+	}
315
+
316
+
317
+
318
+	/**
319
+	 * @param int $time number of seconds to add to session expiration
320
+	 */
321
+	public function extend_expiration($time = 0)
322
+	{
323
+		$time              = $time ? $time : $this->extension();
324
+		$this->_expiration += absint($time);
325
+	}
326
+
327
+
328
+
329
+	/**
330
+	 * @return int
331
+	 */
332
+	public function lifespan()
333
+	{
334
+		return $this->_lifespan;
335
+	}
336
+
337
+
338
+
339
+	/**
340
+	 * This just sets some defaults for the _session data property
341
+	 *
342
+	 * @access private
343
+	 * @return void
344
+	 */
345
+	private function _set_defaults()
346
+	{
347
+		// set some defaults
348
+		foreach ($this->_default_session_vars as $key => $default_var) {
349
+			if (is_array($default_var)) {
350
+				$this->_session_data[ $key ] = array();
351
+			} else {
352
+				$this->_session_data[ $key ] = '';
353
+			}
354
+		}
355
+	}
356 356
 
357 357
 
358
-
359
-    /**
360
-     * @retrieve  session data
361
-     * @access    public
362
-     * @return    string
363
-     */
364
-    public function id()
365
-    {
366
-        return $this->_sid;
367
-    }
358
+
359
+	/**
360
+	 * @retrieve  session data
361
+	 * @access    public
362
+	 * @return    string
363
+	 */
364
+	public function id()
365
+	{
366
+		return $this->_sid;
367
+	}
368 368
 
369 369
 
370 370
 
371
-    /**
372
-     * @param \EE_Cart $cart
373
-     * @return bool
374
-     */
375
-    public function set_cart(EE_Cart $cart)
376
-    {
377
-        $this->_session_data['cart'] = $cart;
378
-        return true;
379
-    }
380
-
381
-
382
-
383
-    /**
384
-     * reset_cart
385
-     */
386
-    public function reset_cart()
387
-    {
388
-        do_action('AHEE__EE_Session__reset_cart__before_reset', $this);
389
-        $this->_session_data['cart'] = null;
390
-    }
391
-
392
-
393
-
394
-    /**
395
-     * @return \EE_Cart
396
-     */
397
-    public function cart()
398
-    {
399
-        return isset($this->_session_data['cart']) && $this->_session_data['cart'] instanceof EE_Cart
400
-            ? $this->_session_data['cart']
401
-            : null;
402
-    }
403
-
404
-
405
-
406
-    /**
407
-     * @param \EE_Checkout $checkout
408
-     * @return bool
409
-     */
410
-    public function set_checkout(EE_Checkout $checkout)
411
-    {
412
-        $this->_session_data['checkout'] = $checkout;
413
-        return true;
414
-    }
415
-
416
-
417
-
418
-    /**
419
-     * reset_checkout
420
-     */
421
-    public function reset_checkout()
422
-    {
423
-        do_action('AHEE__EE_Session__reset_checkout__before_reset', $this);
424
-        $this->_session_data['checkout'] = null;
425
-    }
426
-
427
-
428
-
429
-    /**
430
-     * @return \EE_Checkout
431
-     */
432
-    public function checkout()
433
-    {
434
-        return isset($this->_session_data['checkout']) && $this->_session_data['checkout'] instanceof EE_Checkout
435
-            ? $this->_session_data['checkout']
436
-            : null;
437
-    }
438
-
439
-
440
-
441
-    /**
442
-     * @param \EE_Transaction $transaction
443
-     * @return bool
444
-     * @throws EE_Error
445
-     */
446
-    public function set_transaction(EE_Transaction $transaction)
447
-    {
448
-        // first remove the session from the transaction before we save the transaction in the session
449
-        $transaction->set_txn_session_data(null);
450
-        $this->_session_data['transaction'] = $transaction;
451
-        return true;
452
-    }
453
-
454
-
455
-
456
-    /**
457
-     * reset_transaction
458
-     */
459
-    public function reset_transaction()
460
-    {
461
-        do_action('AHEE__EE_Session__reset_transaction__before_reset', $this);
462
-        $this->_session_data['transaction'] = null;
463
-    }
464
-
465
-
466
-
467
-    /**
468
-     * @return \EE_Transaction
469
-     */
470
-    public function transaction()
471
-    {
472
-        return isset($this->_session_data['transaction'])
473
-               && $this->_session_data['transaction'] instanceof EE_Transaction
474
-            ? $this->_session_data['transaction']
475
-            : null;
476
-    }
477
-
478
-
479
-    /**
480
-     * retrieve session data
481
-     *
482
-     * @param null $key
483
-     * @param bool $reset_cache
484
-     * @return array
485
-     */
486
-    public function get_session_data($key = null, $reset_cache = false)
487
-    {
488
-        if ($reset_cache) {
489
-            $this->reset_cart();
490
-            $this->reset_checkout();
491
-            $this->reset_transaction();
492
-        }
493
-        if (! empty($key)) {
494
-            return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null;
495
-        }
496
-        return $this->_session_data;
497
-    }
498
-
499
-
500
-    /**
501
-     * Returns TRUE on success, FALSE on fail
502
-     *
503
-     * @param array $data
504
-     * @return bool
505
-     */
506
-    public function set_session_data($data)
507
-    {
508
-
509
-        // nothing ??? bad data ??? go home!
510
-        if (empty($data) || ! is_array($data)) {
511
-            EE_Error::add_error(__('No session data or invalid session data was provided.', 'event_espresso'), __FILE__,
512
-                __FUNCTION__, __LINE__);
513
-            return false;
514
-        }
515
-        foreach ($data as $key => $value) {
516
-            if (isset($this->_default_session_vars[ $key ])) {
517
-                EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.',
518
-                    'event_espresso'), $key), __FILE__, __FUNCTION__, __LINE__);
519
-                return false;
520
-            }
521
-            $this->_session_data[ $key ] = $value;
522
-        }
523
-        return true;
524
-    }
525
-
526
-
527
-
528
-    /**
529
-     * @initiate session
530
-     * @access   private
531
-     * @return TRUE on success, FALSE on fail
532
-     * @throws EE_Error
533
-     * @throws InvalidArgumentException
534
-     * @throws InvalidDataTypeException
535
-     * @throws InvalidInterfaceException
536
-     * @throws InvalidSessionDataException
537
-     */
538
-    private function _espresso_session()
539
-    {
540
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
541
-        // check that session has started
542
-        if (session_id() === '') {
543
-            //starts a new session if one doesn't already exist, or re-initiates an existing one
544
-            session_start();
545
-        }
546
-        $this->status = EE_Session::EE_SESSION_STATUS_OPEN;
547
-        // get our modified session ID
548
-        $this->_sid = $this->_generate_session_id();
549
-        // and the visitors IP
550
-        $this->_ip_address = $this->_visitor_ip();
551
-        // set the "user agent"
552
-        $this->_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? esc_attr($_SERVER['HTTP_USER_AGENT']) : false;
553
-        // now let's retrieve what's in the db
554
-        $session_data = $this->_retrieve_session_data();
555
-        if (! empty($session_data)) {
556
-            // get the current time in UTC
557
-            $this->_time = $this->_time !== null ? $this->_time : time();
558
-            // and reset the session expiration
559
-            $this->_expiration = isset($session_data['expiration'])
560
-                ? $session_data['expiration']
561
-                : $this->_time + $this->_lifespan;
562
-        } else {
563
-            // set initial site access time and the session expiration
564
-            $this->_set_init_access_and_expiration();
565
-            // set referer
566
-            $this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = isset($_SERVER['HTTP_REFERER'])
567
-                ? esc_attr($_SERVER['HTTP_REFERER'])
568
-                : '';
569
-            // no previous session = go back and create one (on top of the data above)
570
-            return false;
571
-        }
572
-        // now the user agent
573
-        if ($session_data['user_agent'] !== $this->_user_agent) {
574
-            return false;
575
-        }
576
-        // wait a minute... how old are you?
577
-        if ($this->_time > $this->_expiration) {
578
-            // yer too old fer me!
579
-            $this->_expired = true;
580
-            // wipe out everything that isn't a default session datum
581
-            $this->clear_session(__CLASS__, __FUNCTION__);
582
-        }
583
-        // make event espresso session data available to plugin
584
-        $this->_session_data = array_merge($this->_session_data, $session_data);
585
-        return true;
586
-    }
587
-
588
-
589
-
590
-    /**
591
-     * _get_session_data
592
-     * Retrieves the session data, and attempts to correct any encoding issues that can occur due to improperly setup
593
-     * databases
594
-     *
595
-     * @return array
596
-     * @throws EE_Error
597
-     * @throws InvalidArgumentException
598
-     * @throws InvalidSessionDataException
599
-     * @throws InvalidDataTypeException
600
-     * @throws InvalidInterfaceException
601
-     */
602
-    protected function _retrieve_session_data()
603
-    {
604
-        $ssn_key = EE_Session::session_id_prefix . $this->_sid;
605
-        try {
606
-            // we're using WP's Transient API to store session data using the PHP session ID as the option name
607
-            $session_data = $this->cache_storage->get($ssn_key, false);
608
-            if (empty($session_data)) {
609
-                return array();
610
-            }
611
-            if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
612
-                $hash_check = $this->cache_storage->get(
613
-                    EE_Session::hash_check_prefix . $this->_sid,
614
-                    false
615
-                );
616
-                if ($hash_check && $hash_check !== md5($session_data)) {
617
-                    EE_Error::add_error(
618
-                        sprintf(
619
-                            __(
620
-                                'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.',
621
-                                'event_espresso'
622
-                            ),
623
-                            EE_Session::session_id_prefix . $this->_sid
624
-                        ),
625
-                        __FILE__, __FUNCTION__, __LINE__
626
-                    );
627
-                }
628
-            }
629
-        } catch (Exception $e) {
630
-            // let's just eat that error for now and attempt to correct any corrupted data
631
-            global $wpdb;
632
-            $row          = $wpdb->get_row(
633
-                $wpdb->prepare(
634
-                    "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1",
635
-                    '_transient_' . $ssn_key
636
-                )
637
-            );
638
-            $session_data = is_object($row) ? $row->option_value : null;
639
-            if ($session_data) {
640
-                $session_data = preg_replace_callback(
641
-                    '!s:(d+):"(.*?)";!',
642
-                    function ($match)
643
-                    {
644
-                        return $match[1] === strlen($match[2])
645
-                            ? $match[0]
646
-                            : 's:' . strlen($match[2]) . ':"' . $match[2] . '";';
647
-                    },
648
-                    $session_data
649
-                );
650
-            }
651
-            $session_data = maybe_unserialize($session_data);
652
-        }
653
-        // in case the data is encoded... try to decode it
654
-        $session_data = $this->encryption instanceof EE_Encryption
655
-            ? $this->encryption->base64_string_decode($session_data)
656
-            : $session_data;
657
-        if (! is_array($session_data)) {
658
-            try {
659
-                $session_data = maybe_unserialize($session_data);
660
-            } catch (Exception $e) {
661
-                $msg = esc_html__(
662
-                    'An error occurred while attempting to unserialize the session data.',
663
-                    'event_espresso'
664
-                );
665
-                $msg .= WP_DEBUG
666
-                    ? '<br><pre>'
667
-                      . print_r($session_data, true)
668
-                      . '</pre><br>'
669
-                      . $this->find_serialize_error($session_data)
670
-                    : '';
671
-                $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
672
-                throw new InvalidSessionDataException($msg, 0, $e);
673
-            }
674
-        }
675
-        // just a check to make sure the session array is indeed an array
676
-        if (! is_array($session_data)) {
677
-            // no?!?! then something is wrong
678
-            $msg = esc_html__(
679
-                'The session data is missing, invalid, or corrupted.',
680
-                'event_espresso'
681
-            );
682
-            $msg .= WP_DEBUG
683
-                ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
684
-                : '';
685
-            $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
686
-            throw new InvalidSessionDataException($msg);
687
-        }
688
-        if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) {
689
-            $session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID(
690
-                $session_data['transaction']
691
-            );
692
-        }
693
-        return $session_data;
694
-    }
695
-
696
-
697
-
698
-    /**
699
-     * _generate_session_id
700
-     * Retrieves the PHP session id either directly from the PHP session,
701
-     * or from the $_REQUEST array if it was passed in from an AJAX request.
702
-     * The session id is then salted and hashed (mmm sounds tasty)
703
-     * so that it can be safely used as a $_REQUEST param
704
-     *
705
-     * @return string
706
-     */
707
-    protected function _generate_session_id()
708
-    {
709
-        // check if the SID was passed explicitly, otherwise get from session, then add salt and hash it to reduce length
710
-        if (isset($_REQUEST['EESID'])) {
711
-            $session_id = sanitize_text_field($_REQUEST['EESID']);
712
-        } else {
713
-            $session_id = md5(session_id() . get_current_blog_id() . $this->_get_sid_salt());
714
-        }
715
-        return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id);
716
-    }
717
-
718
-
719
-
720
-    /**
721
-     * _get_sid_salt
722
-     *
723
-     * @return string
724
-     */
725
-    protected function _get_sid_salt()
726
-    {
727
-        // was session id salt already saved to db ?
728
-        if (empty($this->_sid_salt)) {
729
-            // no?  then maybe use WP defined constant
730
-            if (defined('AUTH_SALT')) {
731
-                $this->_sid_salt = AUTH_SALT;
732
-            }
733
-            // if salt doesn't exist or is too short
734
-            if (strlen($this->_sid_salt) < 32) {
735
-                // create a new one
736
-                $this->_sid_salt = wp_generate_password(64);
737
-            }
738
-            // and save it as a permanent session setting
739
-            $this->updateSessionSettings(array('sid_salt' => $this->_sid_salt));
740
-        }
741
-        return $this->_sid_salt;
742
-    }
743
-
744
-
745
-
746
-    /**
747
-     * _set_init_access_and_expiration
748
-     *
749
-     * @return void
750
-     */
751
-    protected function _set_init_access_and_expiration()
752
-    {
753
-        $this->_time       = time();
754
-        $this->_expiration = $this->_time + $this->_lifespan;
755
-        // set initial site access time
756
-        $this->_session_data['init_access'] = $this->_time;
757
-        // and the session expiration
758
-        $this->_session_data['expiration'] = $this->_expiration;
759
-    }
760
-
761
-
762
-
763
-    /**
764
-     * @update session data  prior to saving to the db
765
-     * @access public
766
-     * @param bool $new_session
767
-     * @return TRUE on success, FALSE on fail
768
-     * @throws EE_Error
769
-     * @throws InvalidArgumentException
770
-     * @throws InvalidDataTypeException
771
-     * @throws InvalidInterfaceException
772
-     */
773
-    public function update($new_session = false)
774
-    {
775
-        $this->_session_data = $this->_session_data !== null
776
-                               && is_array($this->_session_data)
777
-                               && isset($this->_session_data['id'])
778
-            ? $this->_session_data
779
-            : array();
780
-        if (empty($this->_session_data)) {
781
-            $this->_set_defaults();
782
-        }
783
-        $session_data = array();
784
-        foreach ($this->_session_data as $key => $value) {
785
-
786
-            switch ($key) {
787
-
788
-                case 'id' :
789
-                    // session ID
790
-                    $session_data['id'] = $this->_sid;
791
-                    break;
792
-                case 'ip_address' :
793
-                    // visitor ip address
794
-                    $session_data['ip_address'] = $this->_visitor_ip();
795
-                    break;
796
-                case 'user_agent' :
797
-                    // visitor user_agent
798
-                    $session_data['user_agent'] = $this->_user_agent;
799
-                    break;
800
-                case 'init_access' :
801
-                    $session_data['init_access'] = absint($value);
802
-                    break;
803
-                case 'last_access' :
804
-                    // current access time
805
-                    $session_data['last_access'] = $this->_time;
806
-                    break;
807
-                case 'expiration' :
808
-                    // when the session expires
809
-                    $session_data['expiration'] = ! empty($this->_expiration)
810
-                        ? $this->_expiration
811
-                        : $session_data['init_access'] + $this->_lifespan;
812
-                    break;
813
-                case 'user_id' :
814
-                    // current user if logged in
815
-                    $session_data['user_id'] = $this->_wp_user_id();
816
-                    break;
817
-                case 'pages_visited' :
818
-                    $page_visit = $this->_get_page_visit();
819
-                    if ($page_visit) {
820
-                        // set pages visited where the first will be the http referrer
821
-                        $this->_session_data['pages_visited'][ $this->_time ] = $page_visit;
822
-                        // we'll only save the last 10 page visits.
823
-                        $session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10);
824
-                    }
825
-                    break;
826
-                default :
827
-                    // carry any other data over
828
-                    $session_data[ $key ] = $this->_session_data[ $key ];
829
-            }
830
-        }
831
-        $this->_session_data = $session_data;
832
-        // creating a new session does not require saving to the db just yet
833
-        if (! $new_session) {
834
-            // ready? let's save
835
-            if ($this->_save_session_to_db()) {
836
-                return true;
837
-            }
838
-            return false;
839
-        }
840
-        // meh, why not?
841
-        return true;
842
-    }
843
-
844
-
845
-
846
-    /**
847
-     * @create session data array
848
-     * @access public
849
-     * @return bool
850
-     * @throws EE_Error
851
-     * @throws InvalidArgumentException
852
-     * @throws InvalidDataTypeException
853
-     * @throws InvalidInterfaceException
854
-     */
855
-    private function _create_espresso_session()
856
-    {
857
-        do_action('AHEE_log', __CLASS__, __FUNCTION__, '');
858
-        // use the update function for now with $new_session arg set to TRUE
859
-        return $this->update(true) ? true : false;
860
-    }
861
-
862
-
863
-
864
-    /**
865
-     * _save_session_to_db
866
-     *
867
-     * @param bool $clear_session
868
-     * @return string
869
-     * @throws EE_Error
870
-     * @throws InvalidArgumentException
871
-     * @throws InvalidDataTypeException
872
-     * @throws InvalidInterfaceException
873
-     */
874
-    private function _save_session_to_db($clear_session = false)
875
-    {
876
-        // unless we're deleting the session data, don't save anything if there isn't a cart
877
-        if (! $clear_session && ! $this->cart() instanceof EE_Cart) {
878
-            return false;
879
-        }
880
-        $transaction = $this->transaction();
881
-        if ($transaction instanceof EE_Transaction) {
882
-            if (! $transaction->ID()) {
883
-                $transaction->save();
884
-            }
885
-            $this->_session_data['transaction'] = $transaction->ID();
886
-        }
887
-        // then serialize all of our session data
888
-        $session_data = serialize($this->_session_data);
889
-        // do we need to also encode it to avoid corrupted data when saved to the db?
890
-        $session_data = $this->_use_encryption
891
-            ? $this->encryption->base64_string_encode($session_data)
892
-            : $session_data;
893
-        // maybe save hash check
894
-        if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
895
-            $this->cache_storage->add(
896
-                EE_Session::hash_check_prefix . $this->_sid,
897
-                md5($session_data),
898
-                $this->_lifespan
899
-            );
900
-        }
901
-        // we're using the Transient API for storing session data,
902
-        return $this->cache_storage->add(
903
-            EE_Session::session_id_prefix . $this->_sid,
904
-            $session_data,
905
-            $this->_lifespan
906
-        );
907
-    }
908
-
909
-
910
-
911
-    /**
912
-     * _visitor_ip
913
-     *    attempt to get IP address of current visitor from server
914
-     * plz see: http://stackoverflow.com/a/2031935/1475279
915
-     *
916
-     * @access public
917
-     * @return string
918
-     */
919
-    private function _visitor_ip()
920
-    {
921
-        $visitor_ip  = '0.0.0.0';
922
-        $server_keys = array(
923
-            'HTTP_CLIENT_IP',
924
-            'HTTP_X_FORWARDED_FOR',
925
-            'HTTP_X_FORWARDED',
926
-            'HTTP_X_CLUSTER_CLIENT_IP',
927
-            'HTTP_FORWARDED_FOR',
928
-            'HTTP_FORWARDED',
929
-            'REMOTE_ADDR',
930
-        );
931
-        foreach ($server_keys as $key) {
932
-            if (isset($_SERVER[ $key ])) {
933
-                foreach (array_map('trim', explode(',', $_SERVER[ $key ])) as $ip) {
934
-                    if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
935
-                        $visitor_ip = $ip;
936
-                    }
937
-                }
938
-            }
939
-        }
940
-        return $visitor_ip;
941
-    }
942
-
943
-
944
-
945
-    /**
946
-     * @get    the full page request the visitor is accessing
947
-     * @access public
948
-     * @return string
949
-     */
950
-    public function _get_page_visit()
951
-    {
952
-        $page_visit = home_url('/') . 'wp-admin/admin-ajax.php';
953
-        // check for request url
954
-        if (isset($_SERVER['REQUEST_URI'])) {
955
-            $http_host   = '';
956
-            $page_id     = '?';
957
-            $e_reg       = '';
958
-            $request_uri = esc_url($_SERVER['REQUEST_URI']);
959
-            $ru_bits     = explode('?', $request_uri);
960
-            $request_uri = $ru_bits[0];
961
-            // check for and grab host as well
962
-            if (isset($_SERVER['HTTP_HOST'])) {
963
-                $http_host = esc_url($_SERVER['HTTP_HOST']);
964
-            }
965
-            // check for page_id in SERVER REQUEST
966
-            if (isset($_REQUEST['page_id'])) {
967
-                // rebuild $e_reg without any of the extra parameters
968
-                $page_id = '?page_id=' . esc_attr($_REQUEST['page_id']) . '&amp;';
969
-            }
970
-            // check for $e_reg in SERVER REQUEST
971
-            if (isset($_REQUEST['ee'])) {
972
-                // rebuild $e_reg without any of the extra parameters
973
-                $e_reg = 'ee=' . esc_attr($_REQUEST['ee']);
974
-            }
975
-            $page_visit = rtrim($http_host . $request_uri . $page_id . $e_reg, '?');
976
-        }
977
-        return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : '';
978
-    }
979
-
980
-
981
-
982
-    /**
983
-     * @the    current wp user id
984
-     * @access public
985
-     * @return int
986
-     */
987
-    public function _wp_user_id()
988
-    {
989
-        // if I need to explain the following lines of code, then you shouldn't be looking at this!
990
-        $this->_wp_user_id = get_current_user_id();
991
-        return $this->_wp_user_id;
992
-    }
993
-
994
-
995
-
996
-    /**
997
-     * Clear EE_Session data
998
-     *
999
-     * @access public
1000
-     * @param string $class
1001
-     * @param string $function
1002
-     * @return void
1003
-     * @throws EE_Error
1004
-     * @throws InvalidArgumentException
1005
-     * @throws InvalidDataTypeException
1006
-     * @throws InvalidInterfaceException
1007
-     */
1008
-    public function clear_session($class = '', $function = '')
1009
-    {
1010
-        //echo '<h3 style="color:#999;line-height:.9em;"><span style="color:#2EA2CC">' . __CLASS__ . '</span>::<span style="color:#E76700">' . __FUNCTION__ . '( ' . $class . '::' . $function . '() )</span><br/><span style="font-size:9px;font-weight:normal;">' . __FILE__ . '</span>    <b style="font-size:10px;">  ' . __LINE__ . ' </b></h3>';
1011
-        do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()');
1012
-        $this->reset_cart();
1013
-        $this->reset_checkout();
1014
-        $this->reset_transaction();
1015
-        // wipe out everything that isn't a default session datum
1016
-        $this->reset_data(array_keys($this->_session_data));
1017
-        // reset initial site access time and the session expiration
1018
-        $this->_set_init_access_and_expiration();
1019
-        $this->_save_session_to_db(true);
1020
-    }
1021
-
1022
-
1023
-    /**
1024
-     * resets all non-default session vars. Returns TRUE on success, FALSE on fail
1025
-     *
1026
-     * @param array|mixed $data_to_reset
1027
-     * @param bool        $show_all_notices
1028
-     * @return bool
1029
-     */
1030
-    public function reset_data($data_to_reset = array(), $show_all_notices = false)
1031
-    {
1032
-        // if $data_to_reset is not in an array, then put it in one
1033
-        if (! is_array($data_to_reset)) {
1034
-            $data_to_reset = array($data_to_reset);
1035
-        }
1036
-        // nothing ??? go home!
1037
-        if (empty($data_to_reset)) {
1038
-            EE_Error::add_error(__('No session data could be reset, because no session var name was provided.',
1039
-                'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1040
-            return false;
1041
-        }
1042
-        $return_value = true;
1043
-        // since $data_to_reset is an array, cycle through the values
1044
-        foreach ($data_to_reset as $reset) {
1045
-
1046
-            // first check to make sure it is a valid session var
1047
-            if (isset($this->_session_data[ $reset ])) {
1048
-                // then check to make sure it is not a default var
1049
-                if (! array_key_exists($reset, $this->_default_session_vars)) {
1050
-                    // remove session var
1051
-                    unset($this->_session_data[ $reset ]);
1052
-                    if ($show_all_notices) {
1053
-                        EE_Error::add_success(sprintf(__('The session variable %s was removed.', 'event_espresso'),
1054
-                            $reset), __FILE__, __FUNCTION__, __LINE__);
1055
-                    }
1056
-                } else {
1057
-                    // yeeeeeeeeerrrrrrrrrrr OUT !!!!
1058
-                    if ($show_all_notices) {
1059
-                        EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.',
1060
-                            'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__);
1061
-                    }
1062
-                    $return_value = false;
1063
-                }
1064
-            } elseif ($show_all_notices) {
1065
-                // oops! that session var does not exist!
1066
-                EE_Error::add_error(sprintf(__('The session item provided, %s, is invalid or does not exist.',
1067
-                    'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__);
1068
-                $return_value = false;
1069
-            }
1070
-        } // end of foreach
1071
-        return $return_value;
1072
-    }
1073
-
1074
-
1075
-
1076
-    /**
1077
-     *   wp_loaded
1078
-     *
1079
-     * @access public
1080
-     * @throws EE_Error
1081
-     * @throws InvalidDataTypeException
1082
-     * @throws InvalidInterfaceException
1083
-     * @throws InvalidArgumentException
1084
-     */
1085
-    public function wp_loaded()
1086
-    {
1087
-        if (
1088
-            EE_Registry::instance()->REQ instanceof EE_Request_Handler
1089
-            && EE_Registry::instance()->REQ->is_set('clear_session')
1090
-        ) {
1091
-            $this->clear_session(__CLASS__, __FUNCTION__);
1092
-        }
1093
-    }
1094
-
1095
-
1096
-
1097
-    /**
1098
-     * Used to reset the entire object (for tests).
1099
-     *
1100
-     * @since 4.3.0
1101
-     * @throws EE_Error
1102
-     * @throws InvalidDataTypeException
1103
-     * @throws InvalidInterfaceException
1104
-     * @throws InvalidArgumentException
1105
-     */
1106
-    public function reset_instance()
1107
-    {
1108
-        $this->clear_session();
1109
-        self::$_instance = null;
1110
-    }
1111
-
1112
-
1113
-
1114
-    public function configure_garbage_collection_filters()
1115
-    {
1116
-        // run old filter we had for controlling session cleanup
1117
-        $expired_session_transient_delete_query_limit = absint(
1118
-            apply_filters(
1119
-                'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit',
1120
-                50
1121
-            )
1122
-        );
1123
-        // is there a value? or one that is different than the default 50 records?
1124
-        if ($expired_session_transient_delete_query_limit === 0) {
1125
-            // hook into TransientCacheStorage in case Session cleanup was turned off
1126
-            add_filter('FHEE__TransientCacheStorage__transient_cleanup_schedule', '__return_zero');
1127
-        } elseif ($expired_session_transient_delete_query_limit !== 50) {
1128
-            // or use that for the new transient cleanup query limit
1129
-            add_filter(
1130
-                'FHEE__TransientCacheStorage__clearExpiredTransients__limit',
1131
-                function () use ($expired_session_transient_delete_query_limit)
1132
-                {
1133
-                    return $expired_session_transient_delete_query_limit;
1134
-                }
1135
-            );
1136
-        }
1137
-    }
1138
-
1139
-
1140
-
1141
-    /**
1142
-     * @see http://stackoverflow.com/questions/10152904/unserialize-function-unserialize-error-at-offset/21389439#10152996
1143
-     * @param $data1
1144
-     * @return string
1145
-     */
1146
-    private function find_serialize_error($data1)
1147
-    {
1148
-        $error = '<pre>';
1149
-        $data2 = preg_replace_callback(
1150
-            '!s:(\d+):"(.*?)";!',
1151
-            function ($match)
1152
-            {
1153
-                return ($match[1] === strlen($match[2]))
1154
-                    ? $match[0]
1155
-                    : 's:'
1156
-                      . strlen($match[2])
1157
-                      . ':"'
1158
-                      . $match[2]
1159
-                      . '";';
1160
-            },
1161
-            $data1
1162
-        );
1163
-        $max   = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2);
1164
-        $error .= $data1 . PHP_EOL;
1165
-        $error .= $data2 . PHP_EOL;
1166
-        for ($i = 0; $i < $max; $i++) {
1167
-            if (@$data1[ $i ] !== @$data2[ $i ]) {
1168
-                $error  .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL;
1169
-                $error  .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL;
1170
-                $error  .= "\t-> Line Number = $i" . PHP_EOL;
1171
-                $start  = ($i - 20);
1172
-                $start  = ($start < 0) ? 0 : $start;
1173
-                $length = 40;
1174
-                $point  = $max - $i;
1175
-                if ($point < 20) {
1176
-                    $rlength = 1;
1177
-                    $rpoint  = -$point;
1178
-                } else {
1179
-                    $rpoint  = $length - 20;
1180
-                    $rlength = 1;
1181
-                }
1182
-                $error .= "\t-> Section Data1  = ";
1183
-                $error .= substr_replace(
1184
-                    substr($data1, $start, $length),
1185
-                    "<b style=\"color:green\">{$data1[ $i ]}</b>",
1186
-                    $rpoint,
1187
-                    $rlength
1188
-                );
1189
-                $error .= PHP_EOL;
1190
-                $error .= "\t-> Section Data2  = ";
1191
-                $error .= substr_replace(
1192
-                    substr($data2, $start, $length),
1193
-                    "<b style=\"color:red\">{$data2[ $i ]}</b>",
1194
-                    $rpoint,
1195
-                    $rlength
1196
-                );
1197
-                $error .= PHP_EOL;
1198
-            }
1199
-        }
1200
-        $error .= '</pre>';
1201
-        return $error;
1202
-    }
1203
-
1204
-
1205
-    /**
1206
-     * Saves an  array of settings used for configuring aspects of session behaviour
1207
-     *
1208
-     * @param array $updated_settings
1209
-     */
1210
-    private function updateSessionSettings(array $updated_settings = array())
1211
-    {
1212
-        // add existing settings, but only if not included in incoming $updated_settings array
1213
-        $updated_settings += get_option(EE_Session::OPTION_NAME_SETTINGS, array());
1214
-        update_option(EE_Session::OPTION_NAME_SETTINGS, $updated_settings);
1215
-    }
1216
-
1217
-
1218
-    /**
1219
-     * garbage_collection
1220
-     */
1221
-    public function garbageCollection()
1222
-    {
1223
-        // only perform during regular requests if last garbage collection was over an hour ago
1224
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) {
1225
-            $this->_last_gc = time();
1226
-            $this->updateSessionSettings(array('last_gc' => $this->_last_gc));
1227
-            /** @type WPDB $wpdb */
1228
-            global $wpdb;
1229
-            // filter the query limit. Set to 0 to turn off garbage collection
1230
-            $expired_session_transient_delete_query_limit = absint(
1231
-                apply_filters(
1232
-                    'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit',
1233
-                    50
1234
-                )
1235
-            );
1236
-            // non-zero LIMIT means take out the trash
1237
-            if ($expired_session_transient_delete_query_limit) {
1238
-                $session_key    = str_replace('_', '\_', EE_Session::session_id_prefix);
1239
-                $hash_check_key = str_replace('_', '\_', EE_Session::hash_check_prefix);
1240
-                // since transient expiration timestamps are set in the future, we can compare against NOW
1241
-                // but we only want to pick up any trash that's been around for more than a day
1242
-                $expiration = time() - DAY_IN_SECONDS;
1243
-                $SQL        = "
371
+	/**
372
+	 * @param \EE_Cart $cart
373
+	 * @return bool
374
+	 */
375
+	public function set_cart(EE_Cart $cart)
376
+	{
377
+		$this->_session_data['cart'] = $cart;
378
+		return true;
379
+	}
380
+
381
+
382
+
383
+	/**
384
+	 * reset_cart
385
+	 */
386
+	public function reset_cart()
387
+	{
388
+		do_action('AHEE__EE_Session__reset_cart__before_reset', $this);
389
+		$this->_session_data['cart'] = null;
390
+	}
391
+
392
+
393
+
394
+	/**
395
+	 * @return \EE_Cart
396
+	 */
397
+	public function cart()
398
+	{
399
+		return isset($this->_session_data['cart']) && $this->_session_data['cart'] instanceof EE_Cart
400
+			? $this->_session_data['cart']
401
+			: null;
402
+	}
403
+
404
+
405
+
406
+	/**
407
+	 * @param \EE_Checkout $checkout
408
+	 * @return bool
409
+	 */
410
+	public function set_checkout(EE_Checkout $checkout)
411
+	{
412
+		$this->_session_data['checkout'] = $checkout;
413
+		return true;
414
+	}
415
+
416
+
417
+
418
+	/**
419
+	 * reset_checkout
420
+	 */
421
+	public function reset_checkout()
422
+	{
423
+		do_action('AHEE__EE_Session__reset_checkout__before_reset', $this);
424
+		$this->_session_data['checkout'] = null;
425
+	}
426
+
427
+
428
+
429
+	/**
430
+	 * @return \EE_Checkout
431
+	 */
432
+	public function checkout()
433
+	{
434
+		return isset($this->_session_data['checkout']) && $this->_session_data['checkout'] instanceof EE_Checkout
435
+			? $this->_session_data['checkout']
436
+			: null;
437
+	}
438
+
439
+
440
+
441
+	/**
442
+	 * @param \EE_Transaction $transaction
443
+	 * @return bool
444
+	 * @throws EE_Error
445
+	 */
446
+	public function set_transaction(EE_Transaction $transaction)
447
+	{
448
+		// first remove the session from the transaction before we save the transaction in the session
449
+		$transaction->set_txn_session_data(null);
450
+		$this->_session_data['transaction'] = $transaction;
451
+		return true;
452
+	}
453
+
454
+
455
+
456
+	/**
457
+	 * reset_transaction
458
+	 */
459
+	public function reset_transaction()
460
+	{
461
+		do_action('AHEE__EE_Session__reset_transaction__before_reset', $this);
462
+		$this->_session_data['transaction'] = null;
463
+	}
464
+
465
+
466
+
467
+	/**
468
+	 * @return \EE_Transaction
469
+	 */
470
+	public function transaction()
471
+	{
472
+		return isset($this->_session_data['transaction'])
473
+			   && $this->_session_data['transaction'] instanceof EE_Transaction
474
+			? $this->_session_data['transaction']
475
+			: null;
476
+	}
477
+
478
+
479
+	/**
480
+	 * retrieve session data
481
+	 *
482
+	 * @param null $key
483
+	 * @param bool $reset_cache
484
+	 * @return array
485
+	 */
486
+	public function get_session_data($key = null, $reset_cache = false)
487
+	{
488
+		if ($reset_cache) {
489
+			$this->reset_cart();
490
+			$this->reset_checkout();
491
+			$this->reset_transaction();
492
+		}
493
+		if (! empty($key)) {
494
+			return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null;
495
+		}
496
+		return $this->_session_data;
497
+	}
498
+
499
+
500
+	/**
501
+	 * Returns TRUE on success, FALSE on fail
502
+	 *
503
+	 * @param array $data
504
+	 * @return bool
505
+	 */
506
+	public function set_session_data($data)
507
+	{
508
+
509
+		// nothing ??? bad data ??? go home!
510
+		if (empty($data) || ! is_array($data)) {
511
+			EE_Error::add_error(__('No session data or invalid session data was provided.', 'event_espresso'), __FILE__,
512
+				__FUNCTION__, __LINE__);
513
+			return false;
514
+		}
515
+		foreach ($data as $key => $value) {
516
+			if (isset($this->_default_session_vars[ $key ])) {
517
+				EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.',
518
+					'event_espresso'), $key), __FILE__, __FUNCTION__, __LINE__);
519
+				return false;
520
+			}
521
+			$this->_session_data[ $key ] = $value;
522
+		}
523
+		return true;
524
+	}
525
+
526
+
527
+
528
+	/**
529
+	 * @initiate session
530
+	 * @access   private
531
+	 * @return TRUE on success, FALSE on fail
532
+	 * @throws EE_Error
533
+	 * @throws InvalidArgumentException
534
+	 * @throws InvalidDataTypeException
535
+	 * @throws InvalidInterfaceException
536
+	 * @throws InvalidSessionDataException
537
+	 */
538
+	private function _espresso_session()
539
+	{
540
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
541
+		// check that session has started
542
+		if (session_id() === '') {
543
+			//starts a new session if one doesn't already exist, or re-initiates an existing one
544
+			session_start();
545
+		}
546
+		$this->status = EE_Session::EE_SESSION_STATUS_OPEN;
547
+		// get our modified session ID
548
+		$this->_sid = $this->_generate_session_id();
549
+		// and the visitors IP
550
+		$this->_ip_address = $this->_visitor_ip();
551
+		// set the "user agent"
552
+		$this->_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? esc_attr($_SERVER['HTTP_USER_AGENT']) : false;
553
+		// now let's retrieve what's in the db
554
+		$session_data = $this->_retrieve_session_data();
555
+		if (! empty($session_data)) {
556
+			// get the current time in UTC
557
+			$this->_time = $this->_time !== null ? $this->_time : time();
558
+			// and reset the session expiration
559
+			$this->_expiration = isset($session_data['expiration'])
560
+				? $session_data['expiration']
561
+				: $this->_time + $this->_lifespan;
562
+		} else {
563
+			// set initial site access time and the session expiration
564
+			$this->_set_init_access_and_expiration();
565
+			// set referer
566
+			$this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = isset($_SERVER['HTTP_REFERER'])
567
+				? esc_attr($_SERVER['HTTP_REFERER'])
568
+				: '';
569
+			// no previous session = go back and create one (on top of the data above)
570
+			return false;
571
+		}
572
+		// now the user agent
573
+		if ($session_data['user_agent'] !== $this->_user_agent) {
574
+			return false;
575
+		}
576
+		// wait a minute... how old are you?
577
+		if ($this->_time > $this->_expiration) {
578
+			// yer too old fer me!
579
+			$this->_expired = true;
580
+			// wipe out everything that isn't a default session datum
581
+			$this->clear_session(__CLASS__, __FUNCTION__);
582
+		}
583
+		// make event espresso session data available to plugin
584
+		$this->_session_data = array_merge($this->_session_data, $session_data);
585
+		return true;
586
+	}
587
+
588
+
589
+
590
+	/**
591
+	 * _get_session_data
592
+	 * Retrieves the session data, and attempts to correct any encoding issues that can occur due to improperly setup
593
+	 * databases
594
+	 *
595
+	 * @return array
596
+	 * @throws EE_Error
597
+	 * @throws InvalidArgumentException
598
+	 * @throws InvalidSessionDataException
599
+	 * @throws InvalidDataTypeException
600
+	 * @throws InvalidInterfaceException
601
+	 */
602
+	protected function _retrieve_session_data()
603
+	{
604
+		$ssn_key = EE_Session::session_id_prefix . $this->_sid;
605
+		try {
606
+			// we're using WP's Transient API to store session data using the PHP session ID as the option name
607
+			$session_data = $this->cache_storage->get($ssn_key, false);
608
+			if (empty($session_data)) {
609
+				return array();
610
+			}
611
+			if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
612
+				$hash_check = $this->cache_storage->get(
613
+					EE_Session::hash_check_prefix . $this->_sid,
614
+					false
615
+				);
616
+				if ($hash_check && $hash_check !== md5($session_data)) {
617
+					EE_Error::add_error(
618
+						sprintf(
619
+							__(
620
+								'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.',
621
+								'event_espresso'
622
+							),
623
+							EE_Session::session_id_prefix . $this->_sid
624
+						),
625
+						__FILE__, __FUNCTION__, __LINE__
626
+					);
627
+				}
628
+			}
629
+		} catch (Exception $e) {
630
+			// let's just eat that error for now and attempt to correct any corrupted data
631
+			global $wpdb;
632
+			$row          = $wpdb->get_row(
633
+				$wpdb->prepare(
634
+					"SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1",
635
+					'_transient_' . $ssn_key
636
+				)
637
+			);
638
+			$session_data = is_object($row) ? $row->option_value : null;
639
+			if ($session_data) {
640
+				$session_data = preg_replace_callback(
641
+					'!s:(d+):"(.*?)";!',
642
+					function ($match)
643
+					{
644
+						return $match[1] === strlen($match[2])
645
+							? $match[0]
646
+							: 's:' . strlen($match[2]) . ':"' . $match[2] . '";';
647
+					},
648
+					$session_data
649
+				);
650
+			}
651
+			$session_data = maybe_unserialize($session_data);
652
+		}
653
+		// in case the data is encoded... try to decode it
654
+		$session_data = $this->encryption instanceof EE_Encryption
655
+			? $this->encryption->base64_string_decode($session_data)
656
+			: $session_data;
657
+		if (! is_array($session_data)) {
658
+			try {
659
+				$session_data = maybe_unserialize($session_data);
660
+			} catch (Exception $e) {
661
+				$msg = esc_html__(
662
+					'An error occurred while attempting to unserialize the session data.',
663
+					'event_espresso'
664
+				);
665
+				$msg .= WP_DEBUG
666
+					? '<br><pre>'
667
+					  . print_r($session_data, true)
668
+					  . '</pre><br>'
669
+					  . $this->find_serialize_error($session_data)
670
+					: '';
671
+				$this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
672
+				throw new InvalidSessionDataException($msg, 0, $e);
673
+			}
674
+		}
675
+		// just a check to make sure the session array is indeed an array
676
+		if (! is_array($session_data)) {
677
+			// no?!?! then something is wrong
678
+			$msg = esc_html__(
679
+				'The session data is missing, invalid, or corrupted.',
680
+				'event_espresso'
681
+			);
682
+			$msg .= WP_DEBUG
683
+				? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
684
+				: '';
685
+			$this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
686
+			throw new InvalidSessionDataException($msg);
687
+		}
688
+		if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) {
689
+			$session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID(
690
+				$session_data['transaction']
691
+			);
692
+		}
693
+		return $session_data;
694
+	}
695
+
696
+
697
+
698
+	/**
699
+	 * _generate_session_id
700
+	 * Retrieves the PHP session id either directly from the PHP session,
701
+	 * or from the $_REQUEST array if it was passed in from an AJAX request.
702
+	 * The session id is then salted and hashed (mmm sounds tasty)
703
+	 * so that it can be safely used as a $_REQUEST param
704
+	 *
705
+	 * @return string
706
+	 */
707
+	protected function _generate_session_id()
708
+	{
709
+		// check if the SID was passed explicitly, otherwise get from session, then add salt and hash it to reduce length
710
+		if (isset($_REQUEST['EESID'])) {
711
+			$session_id = sanitize_text_field($_REQUEST['EESID']);
712
+		} else {
713
+			$session_id = md5(session_id() . get_current_blog_id() . $this->_get_sid_salt());
714
+		}
715
+		return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id);
716
+	}
717
+
718
+
719
+
720
+	/**
721
+	 * _get_sid_salt
722
+	 *
723
+	 * @return string
724
+	 */
725
+	protected function _get_sid_salt()
726
+	{
727
+		// was session id salt already saved to db ?
728
+		if (empty($this->_sid_salt)) {
729
+			// no?  then maybe use WP defined constant
730
+			if (defined('AUTH_SALT')) {
731
+				$this->_sid_salt = AUTH_SALT;
732
+			}
733
+			// if salt doesn't exist or is too short
734
+			if (strlen($this->_sid_salt) < 32) {
735
+				// create a new one
736
+				$this->_sid_salt = wp_generate_password(64);
737
+			}
738
+			// and save it as a permanent session setting
739
+			$this->updateSessionSettings(array('sid_salt' => $this->_sid_salt));
740
+		}
741
+		return $this->_sid_salt;
742
+	}
743
+
744
+
745
+
746
+	/**
747
+	 * _set_init_access_and_expiration
748
+	 *
749
+	 * @return void
750
+	 */
751
+	protected function _set_init_access_and_expiration()
752
+	{
753
+		$this->_time       = time();
754
+		$this->_expiration = $this->_time + $this->_lifespan;
755
+		// set initial site access time
756
+		$this->_session_data['init_access'] = $this->_time;
757
+		// and the session expiration
758
+		$this->_session_data['expiration'] = $this->_expiration;
759
+	}
760
+
761
+
762
+
763
+	/**
764
+	 * @update session data  prior to saving to the db
765
+	 * @access public
766
+	 * @param bool $new_session
767
+	 * @return TRUE on success, FALSE on fail
768
+	 * @throws EE_Error
769
+	 * @throws InvalidArgumentException
770
+	 * @throws InvalidDataTypeException
771
+	 * @throws InvalidInterfaceException
772
+	 */
773
+	public function update($new_session = false)
774
+	{
775
+		$this->_session_data = $this->_session_data !== null
776
+							   && is_array($this->_session_data)
777
+							   && isset($this->_session_data['id'])
778
+			? $this->_session_data
779
+			: array();
780
+		if (empty($this->_session_data)) {
781
+			$this->_set_defaults();
782
+		}
783
+		$session_data = array();
784
+		foreach ($this->_session_data as $key => $value) {
785
+
786
+			switch ($key) {
787
+
788
+				case 'id' :
789
+					// session ID
790
+					$session_data['id'] = $this->_sid;
791
+					break;
792
+				case 'ip_address' :
793
+					// visitor ip address
794
+					$session_data['ip_address'] = $this->_visitor_ip();
795
+					break;
796
+				case 'user_agent' :
797
+					// visitor user_agent
798
+					$session_data['user_agent'] = $this->_user_agent;
799
+					break;
800
+				case 'init_access' :
801
+					$session_data['init_access'] = absint($value);
802
+					break;
803
+				case 'last_access' :
804
+					// current access time
805
+					$session_data['last_access'] = $this->_time;
806
+					break;
807
+				case 'expiration' :
808
+					// when the session expires
809
+					$session_data['expiration'] = ! empty($this->_expiration)
810
+						? $this->_expiration
811
+						: $session_data['init_access'] + $this->_lifespan;
812
+					break;
813
+				case 'user_id' :
814
+					// current user if logged in
815
+					$session_data['user_id'] = $this->_wp_user_id();
816
+					break;
817
+				case 'pages_visited' :
818
+					$page_visit = $this->_get_page_visit();
819
+					if ($page_visit) {
820
+						// set pages visited where the first will be the http referrer
821
+						$this->_session_data['pages_visited'][ $this->_time ] = $page_visit;
822
+						// we'll only save the last 10 page visits.
823
+						$session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10);
824
+					}
825
+					break;
826
+				default :
827
+					// carry any other data over
828
+					$session_data[ $key ] = $this->_session_data[ $key ];
829
+			}
830
+		}
831
+		$this->_session_data = $session_data;
832
+		// creating a new session does not require saving to the db just yet
833
+		if (! $new_session) {
834
+			// ready? let's save
835
+			if ($this->_save_session_to_db()) {
836
+				return true;
837
+			}
838
+			return false;
839
+		}
840
+		// meh, why not?
841
+		return true;
842
+	}
843
+
844
+
845
+
846
+	/**
847
+	 * @create session data array
848
+	 * @access public
849
+	 * @return bool
850
+	 * @throws EE_Error
851
+	 * @throws InvalidArgumentException
852
+	 * @throws InvalidDataTypeException
853
+	 * @throws InvalidInterfaceException
854
+	 */
855
+	private function _create_espresso_session()
856
+	{
857
+		do_action('AHEE_log', __CLASS__, __FUNCTION__, '');
858
+		// use the update function for now with $new_session arg set to TRUE
859
+		return $this->update(true) ? true : false;
860
+	}
861
+
862
+
863
+
864
+	/**
865
+	 * _save_session_to_db
866
+	 *
867
+	 * @param bool $clear_session
868
+	 * @return string
869
+	 * @throws EE_Error
870
+	 * @throws InvalidArgumentException
871
+	 * @throws InvalidDataTypeException
872
+	 * @throws InvalidInterfaceException
873
+	 */
874
+	private function _save_session_to_db($clear_session = false)
875
+	{
876
+		// unless we're deleting the session data, don't save anything if there isn't a cart
877
+		if (! $clear_session && ! $this->cart() instanceof EE_Cart) {
878
+			return false;
879
+		}
880
+		$transaction = $this->transaction();
881
+		if ($transaction instanceof EE_Transaction) {
882
+			if (! $transaction->ID()) {
883
+				$transaction->save();
884
+			}
885
+			$this->_session_data['transaction'] = $transaction->ID();
886
+		}
887
+		// then serialize all of our session data
888
+		$session_data = serialize($this->_session_data);
889
+		// do we need to also encode it to avoid corrupted data when saved to the db?
890
+		$session_data = $this->_use_encryption
891
+			? $this->encryption->base64_string_encode($session_data)
892
+			: $session_data;
893
+		// maybe save hash check
894
+		if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
895
+			$this->cache_storage->add(
896
+				EE_Session::hash_check_prefix . $this->_sid,
897
+				md5($session_data),
898
+				$this->_lifespan
899
+			);
900
+		}
901
+		// we're using the Transient API for storing session data,
902
+		return $this->cache_storage->add(
903
+			EE_Session::session_id_prefix . $this->_sid,
904
+			$session_data,
905
+			$this->_lifespan
906
+		);
907
+	}
908
+
909
+
910
+
911
+	/**
912
+	 * _visitor_ip
913
+	 *    attempt to get IP address of current visitor from server
914
+	 * plz see: http://stackoverflow.com/a/2031935/1475279
915
+	 *
916
+	 * @access public
917
+	 * @return string
918
+	 */
919
+	private function _visitor_ip()
920
+	{
921
+		$visitor_ip  = '0.0.0.0';
922
+		$server_keys = array(
923
+			'HTTP_CLIENT_IP',
924
+			'HTTP_X_FORWARDED_FOR',
925
+			'HTTP_X_FORWARDED',
926
+			'HTTP_X_CLUSTER_CLIENT_IP',
927
+			'HTTP_FORWARDED_FOR',
928
+			'HTTP_FORWARDED',
929
+			'REMOTE_ADDR',
930
+		);
931
+		foreach ($server_keys as $key) {
932
+			if (isset($_SERVER[ $key ])) {
933
+				foreach (array_map('trim', explode(',', $_SERVER[ $key ])) as $ip) {
934
+					if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
935
+						$visitor_ip = $ip;
936
+					}
937
+				}
938
+			}
939
+		}
940
+		return $visitor_ip;
941
+	}
942
+
943
+
944
+
945
+	/**
946
+	 * @get    the full page request the visitor is accessing
947
+	 * @access public
948
+	 * @return string
949
+	 */
950
+	public function _get_page_visit()
951
+	{
952
+		$page_visit = home_url('/') . 'wp-admin/admin-ajax.php';
953
+		// check for request url
954
+		if (isset($_SERVER['REQUEST_URI'])) {
955
+			$http_host   = '';
956
+			$page_id     = '?';
957
+			$e_reg       = '';
958
+			$request_uri = esc_url($_SERVER['REQUEST_URI']);
959
+			$ru_bits     = explode('?', $request_uri);
960
+			$request_uri = $ru_bits[0];
961
+			// check for and grab host as well
962
+			if (isset($_SERVER['HTTP_HOST'])) {
963
+				$http_host = esc_url($_SERVER['HTTP_HOST']);
964
+			}
965
+			// check for page_id in SERVER REQUEST
966
+			if (isset($_REQUEST['page_id'])) {
967
+				// rebuild $e_reg without any of the extra parameters
968
+				$page_id = '?page_id=' . esc_attr($_REQUEST['page_id']) . '&amp;';
969
+			}
970
+			// check for $e_reg in SERVER REQUEST
971
+			if (isset($_REQUEST['ee'])) {
972
+				// rebuild $e_reg without any of the extra parameters
973
+				$e_reg = 'ee=' . esc_attr($_REQUEST['ee']);
974
+			}
975
+			$page_visit = rtrim($http_host . $request_uri . $page_id . $e_reg, '?');
976
+		}
977
+		return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : '';
978
+	}
979
+
980
+
981
+
982
+	/**
983
+	 * @the    current wp user id
984
+	 * @access public
985
+	 * @return int
986
+	 */
987
+	public function _wp_user_id()
988
+	{
989
+		// if I need to explain the following lines of code, then you shouldn't be looking at this!
990
+		$this->_wp_user_id = get_current_user_id();
991
+		return $this->_wp_user_id;
992
+	}
993
+
994
+
995
+
996
+	/**
997
+	 * Clear EE_Session data
998
+	 *
999
+	 * @access public
1000
+	 * @param string $class
1001
+	 * @param string $function
1002
+	 * @return void
1003
+	 * @throws EE_Error
1004
+	 * @throws InvalidArgumentException
1005
+	 * @throws InvalidDataTypeException
1006
+	 * @throws InvalidInterfaceException
1007
+	 */
1008
+	public function clear_session($class = '', $function = '')
1009
+	{
1010
+		//echo '<h3 style="color:#999;line-height:.9em;"><span style="color:#2EA2CC">' . __CLASS__ . '</span>::<span style="color:#E76700">' . __FUNCTION__ . '( ' . $class . '::' . $function . '() )</span><br/><span style="font-size:9px;font-weight:normal;">' . __FILE__ . '</span>    <b style="font-size:10px;">  ' . __LINE__ . ' </b></h3>';
1011
+		do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()');
1012
+		$this->reset_cart();
1013
+		$this->reset_checkout();
1014
+		$this->reset_transaction();
1015
+		// wipe out everything that isn't a default session datum
1016
+		$this->reset_data(array_keys($this->_session_data));
1017
+		// reset initial site access time and the session expiration
1018
+		$this->_set_init_access_and_expiration();
1019
+		$this->_save_session_to_db(true);
1020
+	}
1021
+
1022
+
1023
+	/**
1024
+	 * resets all non-default session vars. Returns TRUE on success, FALSE on fail
1025
+	 *
1026
+	 * @param array|mixed $data_to_reset
1027
+	 * @param bool        $show_all_notices
1028
+	 * @return bool
1029
+	 */
1030
+	public function reset_data($data_to_reset = array(), $show_all_notices = false)
1031
+	{
1032
+		// if $data_to_reset is not in an array, then put it in one
1033
+		if (! is_array($data_to_reset)) {
1034
+			$data_to_reset = array($data_to_reset);
1035
+		}
1036
+		// nothing ??? go home!
1037
+		if (empty($data_to_reset)) {
1038
+			EE_Error::add_error(__('No session data could be reset, because no session var name was provided.',
1039
+				'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
1040
+			return false;
1041
+		}
1042
+		$return_value = true;
1043
+		// since $data_to_reset is an array, cycle through the values
1044
+		foreach ($data_to_reset as $reset) {
1045
+
1046
+			// first check to make sure it is a valid session var
1047
+			if (isset($this->_session_data[ $reset ])) {
1048
+				// then check to make sure it is not a default var
1049
+				if (! array_key_exists($reset, $this->_default_session_vars)) {
1050
+					// remove session var
1051
+					unset($this->_session_data[ $reset ]);
1052
+					if ($show_all_notices) {
1053
+						EE_Error::add_success(sprintf(__('The session variable %s was removed.', 'event_espresso'),
1054
+							$reset), __FILE__, __FUNCTION__, __LINE__);
1055
+					}
1056
+				} else {
1057
+					// yeeeeeeeeerrrrrrrrrrr OUT !!!!
1058
+					if ($show_all_notices) {
1059
+						EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.',
1060
+							'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__);
1061
+					}
1062
+					$return_value = false;
1063
+				}
1064
+			} elseif ($show_all_notices) {
1065
+				// oops! that session var does not exist!
1066
+				EE_Error::add_error(sprintf(__('The session item provided, %s, is invalid or does not exist.',
1067
+					'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__);
1068
+				$return_value = false;
1069
+			}
1070
+		} // end of foreach
1071
+		return $return_value;
1072
+	}
1073
+
1074
+
1075
+
1076
+	/**
1077
+	 *   wp_loaded
1078
+	 *
1079
+	 * @access public
1080
+	 * @throws EE_Error
1081
+	 * @throws InvalidDataTypeException
1082
+	 * @throws InvalidInterfaceException
1083
+	 * @throws InvalidArgumentException
1084
+	 */
1085
+	public function wp_loaded()
1086
+	{
1087
+		if (
1088
+			EE_Registry::instance()->REQ instanceof EE_Request_Handler
1089
+			&& EE_Registry::instance()->REQ->is_set('clear_session')
1090
+		) {
1091
+			$this->clear_session(__CLASS__, __FUNCTION__);
1092
+		}
1093
+	}
1094
+
1095
+
1096
+
1097
+	/**
1098
+	 * Used to reset the entire object (for tests).
1099
+	 *
1100
+	 * @since 4.3.0
1101
+	 * @throws EE_Error
1102
+	 * @throws InvalidDataTypeException
1103
+	 * @throws InvalidInterfaceException
1104
+	 * @throws InvalidArgumentException
1105
+	 */
1106
+	public function reset_instance()
1107
+	{
1108
+		$this->clear_session();
1109
+		self::$_instance = null;
1110
+	}
1111
+
1112
+
1113
+
1114
+	public function configure_garbage_collection_filters()
1115
+	{
1116
+		// run old filter we had for controlling session cleanup
1117
+		$expired_session_transient_delete_query_limit = absint(
1118
+			apply_filters(
1119
+				'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit',
1120
+				50
1121
+			)
1122
+		);
1123
+		// is there a value? or one that is different than the default 50 records?
1124
+		if ($expired_session_transient_delete_query_limit === 0) {
1125
+			// hook into TransientCacheStorage in case Session cleanup was turned off
1126
+			add_filter('FHEE__TransientCacheStorage__transient_cleanup_schedule', '__return_zero');
1127
+		} elseif ($expired_session_transient_delete_query_limit !== 50) {
1128
+			// or use that for the new transient cleanup query limit
1129
+			add_filter(
1130
+				'FHEE__TransientCacheStorage__clearExpiredTransients__limit',
1131
+				function () use ($expired_session_transient_delete_query_limit)
1132
+				{
1133
+					return $expired_session_transient_delete_query_limit;
1134
+				}
1135
+			);
1136
+		}
1137
+	}
1138
+
1139
+
1140
+
1141
+	/**
1142
+	 * @see http://stackoverflow.com/questions/10152904/unserialize-function-unserialize-error-at-offset/21389439#10152996
1143
+	 * @param $data1
1144
+	 * @return string
1145
+	 */
1146
+	private function find_serialize_error($data1)
1147
+	{
1148
+		$error = '<pre>';
1149
+		$data2 = preg_replace_callback(
1150
+			'!s:(\d+):"(.*?)";!',
1151
+			function ($match)
1152
+			{
1153
+				return ($match[1] === strlen($match[2]))
1154
+					? $match[0]
1155
+					: 's:'
1156
+					  . strlen($match[2])
1157
+					  . ':"'
1158
+					  . $match[2]
1159
+					  . '";';
1160
+			},
1161
+			$data1
1162
+		);
1163
+		$max   = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2);
1164
+		$error .= $data1 . PHP_EOL;
1165
+		$error .= $data2 . PHP_EOL;
1166
+		for ($i = 0; $i < $max; $i++) {
1167
+			if (@$data1[ $i ] !== @$data2[ $i ]) {
1168
+				$error  .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL;
1169
+				$error  .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL;
1170
+				$error  .= "\t-> Line Number = $i" . PHP_EOL;
1171
+				$start  = ($i - 20);
1172
+				$start  = ($start < 0) ? 0 : $start;
1173
+				$length = 40;
1174
+				$point  = $max - $i;
1175
+				if ($point < 20) {
1176
+					$rlength = 1;
1177
+					$rpoint  = -$point;
1178
+				} else {
1179
+					$rpoint  = $length - 20;
1180
+					$rlength = 1;
1181
+				}
1182
+				$error .= "\t-> Section Data1  = ";
1183
+				$error .= substr_replace(
1184
+					substr($data1, $start, $length),
1185
+					"<b style=\"color:green\">{$data1[ $i ]}</b>",
1186
+					$rpoint,
1187
+					$rlength
1188
+				);
1189
+				$error .= PHP_EOL;
1190
+				$error .= "\t-> Section Data2  = ";
1191
+				$error .= substr_replace(
1192
+					substr($data2, $start, $length),
1193
+					"<b style=\"color:red\">{$data2[ $i ]}</b>",
1194
+					$rpoint,
1195
+					$rlength
1196
+				);
1197
+				$error .= PHP_EOL;
1198
+			}
1199
+		}
1200
+		$error .= '</pre>';
1201
+		return $error;
1202
+	}
1203
+
1204
+
1205
+	/**
1206
+	 * Saves an  array of settings used for configuring aspects of session behaviour
1207
+	 *
1208
+	 * @param array $updated_settings
1209
+	 */
1210
+	private function updateSessionSettings(array $updated_settings = array())
1211
+	{
1212
+		// add existing settings, but only if not included in incoming $updated_settings array
1213
+		$updated_settings += get_option(EE_Session::OPTION_NAME_SETTINGS, array());
1214
+		update_option(EE_Session::OPTION_NAME_SETTINGS, $updated_settings);
1215
+	}
1216
+
1217
+
1218
+	/**
1219
+	 * garbage_collection
1220
+	 */
1221
+	public function garbageCollection()
1222
+	{
1223
+		// only perform during regular requests if last garbage collection was over an hour ago
1224
+		if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) {
1225
+			$this->_last_gc = time();
1226
+			$this->updateSessionSettings(array('last_gc' => $this->_last_gc));
1227
+			/** @type WPDB $wpdb */
1228
+			global $wpdb;
1229
+			// filter the query limit. Set to 0 to turn off garbage collection
1230
+			$expired_session_transient_delete_query_limit = absint(
1231
+				apply_filters(
1232
+					'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit',
1233
+					50
1234
+				)
1235
+			);
1236
+			// non-zero LIMIT means take out the trash
1237
+			if ($expired_session_transient_delete_query_limit) {
1238
+				$session_key    = str_replace('_', '\_', EE_Session::session_id_prefix);
1239
+				$hash_check_key = str_replace('_', '\_', EE_Session::hash_check_prefix);
1240
+				// since transient expiration timestamps are set in the future, we can compare against NOW
1241
+				// but we only want to pick up any trash that's been around for more than a day
1242
+				$expiration = time() - DAY_IN_SECONDS;
1243
+				$SQL        = "
1244 1244
                     SELECT option_name
1245 1245
                     FROM {$wpdb->options}
1246 1246
                     WHERE
@@ -1249,19 +1249,19 @@  discard block
 block discarded – undo
1249 1249
                     AND option_value < {$expiration}
1250 1250
                     LIMIT {$expired_session_transient_delete_query_limit}
1251 1251
                 ";
1252
-                // produces something like:
1253
-                // SELECT option_name FROM wp_options
1254
-                // WHERE ( option_name LIKE '\_transient\_timeout\_ee\_ssn\_%'
1255
-                // OR option_name LIKE '\_transient\_timeout\_ee\_shc\_%' )
1256
-                // AND option_value < 1508368198 LIMIT 50
1257
-                $expired_sessions = $wpdb->get_col($SQL);
1258
-                // valid results?
1259
-                if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) {
1260
-                    $this->cache_storage->deleteMany($expired_sessions, true);
1261
-                }
1262
-            }
1263
-        }
1264
-    }
1252
+				// produces something like:
1253
+				// SELECT option_name FROM wp_options
1254
+				// WHERE ( option_name LIKE '\_transient\_timeout\_ee\_ssn\_%'
1255
+				// OR option_name LIKE '\_transient\_timeout\_ee\_shc\_%' )
1256
+				// AND option_value < 1508368198 LIMIT 50
1257
+				$expired_sessions = $wpdb->get_col($SQL);
1258
+				// valid results?
1259
+				if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) {
1260
+					$this->cache_storage->deleteMany($expired_sessions, true);
1261
+				}
1262
+			}
1263
+		}
1264
+	}
1265 1265
 
1266 1266
 
1267 1267
 
Please login to merge, or discard this patch.
Spacing   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
         // check if class object is instantiated
176 176
         // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via:
177 177
         // add_filter( 'FHEE_load_EE_Session', '__return_false' );
178
-        if (! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) {
178
+        if ( ! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) {
179 179
             self::$_instance = new self($cache_storage, $encryption);
180 180
         }
181 181
         return self::$_instance;
@@ -198,10 +198,10 @@  discard block
 block discarded – undo
198 198
         // but prior to the 'AHEE__EE_System__core_loaded_and_ready' hook
199 199
         // (which currently fires on the init hook at priority 9),
200 200
         // can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' );
201
-        if (! apply_filters('FHEE_load_EE_Session', true)) {
201
+        if ( ! apply_filters('FHEE_load_EE_Session', true)) {
202 202
             return;
203 203
         }
204
-        if (! defined('ESPRESSO_SESSION')) {
204
+        if ( ! defined('ESPRESSO_SESSION')) {
205 205
             define('ESPRESSO_SESSION', true);
206 206
         }
207 207
         // default session lifespan in seconds
@@ -217,11 +217,11 @@  discard block
 block discarded – undo
217 217
          */
218 218
         // retrieve session options from db
219 219
         $session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array());
220
-        if (! empty($session_settings)) {
220
+        if ( ! empty($session_settings)) {
221 221
             // cycle though existing session options
222 222
             foreach ($session_settings as $var_name => $session_setting) {
223 223
                 // set values for class properties
224
-                $var_name          = '_' . $var_name;
224
+                $var_name          = '_'.$var_name;
225 225
                 $this->{$var_name} = $session_setting;
226 226
             }
227 227
         }
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
     public function open_session()
269 269
     {
270 270
         // check for existing session and retrieve it from db
271
-        if (! $this->_espresso_session()) {
271
+        if ( ! $this->_espresso_session()) {
272 272
             // or just start a new one
273 273
             $this->_create_espresso_session();
274 274
         }
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
      */
321 321
     public function extend_expiration($time = 0)
322 322
     {
323
-        $time              = $time ? $time : $this->extension();
323
+        $time = $time ? $time : $this->extension();
324 324
         $this->_expiration += absint($time);
325 325
     }
326 326
 
@@ -347,9 +347,9 @@  discard block
 block discarded – undo
347 347
         // set some defaults
348 348
         foreach ($this->_default_session_vars as $key => $default_var) {
349 349
             if (is_array($default_var)) {
350
-                $this->_session_data[ $key ] = array();
350
+                $this->_session_data[$key] = array();
351 351
             } else {
352
-                $this->_session_data[ $key ] = '';
352
+                $this->_session_data[$key] = '';
353 353
             }
354 354
         }
355 355
     }
@@ -490,8 +490,8 @@  discard block
 block discarded – undo
490 490
             $this->reset_checkout();
491 491
             $this->reset_transaction();
492 492
         }
493
-        if (! empty($key)) {
494
-            return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null;
493
+        if ( ! empty($key)) {
494
+            return isset($this->_session_data[$key]) ? $this->_session_data[$key] : null;
495 495
         }
496 496
         return $this->_session_data;
497 497
     }
@@ -513,12 +513,12 @@  discard block
 block discarded – undo
513 513
             return false;
514 514
         }
515 515
         foreach ($data as $key => $value) {
516
-            if (isset($this->_default_session_vars[ $key ])) {
516
+            if (isset($this->_default_session_vars[$key])) {
517 517
                 EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.',
518 518
                     'event_espresso'), $key), __FILE__, __FUNCTION__, __LINE__);
519 519
                 return false;
520 520
             }
521
-            $this->_session_data[ $key ] = $value;
521
+            $this->_session_data[$key] = $value;
522 522
         }
523 523
         return true;
524 524
     }
@@ -552,7 +552,7 @@  discard block
 block discarded – undo
552 552
         $this->_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? esc_attr($_SERVER['HTTP_USER_AGENT']) : false;
553 553
         // now let's retrieve what's in the db
554 554
         $session_data = $this->_retrieve_session_data();
555
-        if (! empty($session_data)) {
555
+        if ( ! empty($session_data)) {
556 556
             // get the current time in UTC
557 557
             $this->_time = $this->_time !== null ? $this->_time : time();
558 558
             // and reset the session expiration
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
             // set initial site access time and the session expiration
564 564
             $this->_set_init_access_and_expiration();
565 565
             // set referer
566
-            $this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = isset($_SERVER['HTTP_REFERER'])
566
+            $this->_session_data['pages_visited'][$this->_session_data['init_access']] = isset($_SERVER['HTTP_REFERER'])
567 567
                 ? esc_attr($_SERVER['HTTP_REFERER'])
568 568
                 : '';
569 569
             // no previous session = go back and create one (on top of the data above)
@@ -601,7 +601,7 @@  discard block
 block discarded – undo
601 601
      */
602 602
     protected function _retrieve_session_data()
603 603
     {
604
-        $ssn_key = EE_Session::session_id_prefix . $this->_sid;
604
+        $ssn_key = EE_Session::session_id_prefix.$this->_sid;
605 605
         try {
606 606
             // we're using WP's Transient API to store session data using the PHP session ID as the option name
607 607
             $session_data = $this->cache_storage->get($ssn_key, false);
@@ -610,7 +610,7 @@  discard block
 block discarded – undo
610 610
             }
611 611
             if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
612 612
                 $hash_check = $this->cache_storage->get(
613
-                    EE_Session::hash_check_prefix . $this->_sid,
613
+                    EE_Session::hash_check_prefix.$this->_sid,
614 614
                     false
615 615
                 );
616 616
                 if ($hash_check && $hash_check !== md5($session_data)) {
@@ -620,7 +620,7 @@  discard block
 block discarded – undo
620 620
                                 'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.',
621 621
                                 'event_espresso'
622 622
                             ),
623
-                            EE_Session::session_id_prefix . $this->_sid
623
+                            EE_Session::session_id_prefix.$this->_sid
624 624
                         ),
625 625
                         __FILE__, __FUNCTION__, __LINE__
626 626
                     );
@@ -629,21 +629,21 @@  discard block
 block discarded – undo
629 629
         } catch (Exception $e) {
630 630
             // let's just eat that error for now and attempt to correct any corrupted data
631 631
             global $wpdb;
632
-            $row          = $wpdb->get_row(
632
+            $row = $wpdb->get_row(
633 633
                 $wpdb->prepare(
634 634
                     "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1",
635
-                    '_transient_' . $ssn_key
635
+                    '_transient_'.$ssn_key
636 636
                 )
637 637
             );
638 638
             $session_data = is_object($row) ? $row->option_value : null;
639 639
             if ($session_data) {
640 640
                 $session_data = preg_replace_callback(
641 641
                     '!s:(d+):"(.*?)";!',
642
-                    function ($match)
642
+                    function($match)
643 643
                     {
644 644
                         return $match[1] === strlen($match[2])
645 645
                             ? $match[0]
646
-                            : 's:' . strlen($match[2]) . ':"' . $match[2] . '";';
646
+                            : 's:'.strlen($match[2]).':"'.$match[2].'";';
647 647
                     },
648 648
                     $session_data
649 649
                 );
@@ -654,7 +654,7 @@  discard block
 block discarded – undo
654 654
         $session_data = $this->encryption instanceof EE_Encryption
655 655
             ? $this->encryption->base64_string_decode($session_data)
656 656
             : $session_data;
657
-        if (! is_array($session_data)) {
657
+        if ( ! is_array($session_data)) {
658 658
             try {
659 659
                 $session_data = maybe_unserialize($session_data);
660 660
             } catch (Exception $e) {
@@ -668,21 +668,21 @@  discard block
 block discarded – undo
668 668
                       . '</pre><br>'
669 669
                       . $this->find_serialize_error($session_data)
670 670
                     : '';
671
-                $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
671
+                $this->cache_storage->delete(EE_Session::session_id_prefix.$this->_sid);
672 672
                 throw new InvalidSessionDataException($msg, 0, $e);
673 673
             }
674 674
         }
675 675
         // just a check to make sure the session array is indeed an array
676
-        if (! is_array($session_data)) {
676
+        if ( ! is_array($session_data)) {
677 677
             // no?!?! then something is wrong
678 678
             $msg = esc_html__(
679 679
                 'The session data is missing, invalid, or corrupted.',
680 680
                 'event_espresso'
681 681
             );
682 682
             $msg .= WP_DEBUG
683
-                ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data)
683
+                ? '<br><pre>'.print_r($session_data, true).'</pre><br>'.$this->find_serialize_error($session_data)
684 684
                 : '';
685
-            $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid);
685
+            $this->cache_storage->delete(EE_Session::session_id_prefix.$this->_sid);
686 686
             throw new InvalidSessionDataException($msg);
687 687
         }
688 688
         if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) {
@@ -710,7 +710,7 @@  discard block
 block discarded – undo
710 710
         if (isset($_REQUEST['EESID'])) {
711 711
             $session_id = sanitize_text_field($_REQUEST['EESID']);
712 712
         } else {
713
-            $session_id = md5(session_id() . get_current_blog_id() . $this->_get_sid_salt());
713
+            $session_id = md5(session_id().get_current_blog_id().$this->_get_sid_salt());
714 714
         }
715 715
         return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id);
716 716
     }
@@ -818,19 +818,19 @@  discard block
 block discarded – undo
818 818
                     $page_visit = $this->_get_page_visit();
819 819
                     if ($page_visit) {
820 820
                         // set pages visited where the first will be the http referrer
821
-                        $this->_session_data['pages_visited'][ $this->_time ] = $page_visit;
821
+                        $this->_session_data['pages_visited'][$this->_time] = $page_visit;
822 822
                         // we'll only save the last 10 page visits.
823 823
                         $session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10);
824 824
                     }
825 825
                     break;
826 826
                 default :
827 827
                     // carry any other data over
828
-                    $session_data[ $key ] = $this->_session_data[ $key ];
828
+                    $session_data[$key] = $this->_session_data[$key];
829 829
             }
830 830
         }
831 831
         $this->_session_data = $session_data;
832 832
         // creating a new session does not require saving to the db just yet
833
-        if (! $new_session) {
833
+        if ( ! $new_session) {
834 834
             // ready? let's save
835 835
             if ($this->_save_session_to_db()) {
836 836
                 return true;
@@ -874,12 +874,12 @@  discard block
 block discarded – undo
874 874
     private function _save_session_to_db($clear_session = false)
875 875
     {
876 876
         // unless we're deleting the session data, don't save anything if there isn't a cart
877
-        if (! $clear_session && ! $this->cart() instanceof EE_Cart) {
877
+        if ( ! $clear_session && ! $this->cart() instanceof EE_Cart) {
878 878
             return false;
879 879
         }
880 880
         $transaction = $this->transaction();
881 881
         if ($transaction instanceof EE_Transaction) {
882
-            if (! $transaction->ID()) {
882
+            if ( ! $transaction->ID()) {
883 883
                 $transaction->save();
884 884
             }
885 885
             $this->_session_data['transaction'] = $transaction->ID();
@@ -893,14 +893,14 @@  discard block
 block discarded – undo
893 893
         // maybe save hash check
894 894
         if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) {
895 895
             $this->cache_storage->add(
896
-                EE_Session::hash_check_prefix . $this->_sid,
896
+                EE_Session::hash_check_prefix.$this->_sid,
897 897
                 md5($session_data),
898 898
                 $this->_lifespan
899 899
             );
900 900
         }
901 901
         // we're using the Transient API for storing session data,
902 902
         return $this->cache_storage->add(
903
-            EE_Session::session_id_prefix . $this->_sid,
903
+            EE_Session::session_id_prefix.$this->_sid,
904 904
             $session_data,
905 905
             $this->_lifespan
906 906
         );
@@ -929,8 +929,8 @@  discard block
 block discarded – undo
929 929
             'REMOTE_ADDR',
930 930
         );
931 931
         foreach ($server_keys as $key) {
932
-            if (isset($_SERVER[ $key ])) {
933
-                foreach (array_map('trim', explode(',', $_SERVER[ $key ])) as $ip) {
932
+            if (isset($_SERVER[$key])) {
933
+                foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) {
934 934
                     if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
935 935
                         $visitor_ip = $ip;
936 936
                     }
@@ -949,7 +949,7 @@  discard block
 block discarded – undo
949 949
      */
950 950
     public function _get_page_visit()
951 951
     {
952
-        $page_visit = home_url('/') . 'wp-admin/admin-ajax.php';
952
+        $page_visit = home_url('/').'wp-admin/admin-ajax.php';
953 953
         // check for request url
954 954
         if (isset($_SERVER['REQUEST_URI'])) {
955 955
             $http_host   = '';
@@ -965,14 +965,14 @@  discard block
 block discarded – undo
965 965
             // check for page_id in SERVER REQUEST
966 966
             if (isset($_REQUEST['page_id'])) {
967 967
                 // rebuild $e_reg without any of the extra parameters
968
-                $page_id = '?page_id=' . esc_attr($_REQUEST['page_id']) . '&amp;';
968
+                $page_id = '?page_id='.esc_attr($_REQUEST['page_id']).'&amp;';
969 969
             }
970 970
             // check for $e_reg in SERVER REQUEST
971 971
             if (isset($_REQUEST['ee'])) {
972 972
                 // rebuild $e_reg without any of the extra parameters
973
-                $e_reg = 'ee=' . esc_attr($_REQUEST['ee']);
973
+                $e_reg = 'ee='.esc_attr($_REQUEST['ee']);
974 974
             }
975
-            $page_visit = rtrim($http_host . $request_uri . $page_id . $e_reg, '?');
975
+            $page_visit = rtrim($http_host.$request_uri.$page_id.$e_reg, '?');
976 976
         }
977 977
         return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : '';
978 978
     }
@@ -1008,7 +1008,7 @@  discard block
 block discarded – undo
1008 1008
     public function clear_session($class = '', $function = '')
1009 1009
     {
1010 1010
         //echo '<h3 style="color:#999;line-height:.9em;"><span style="color:#2EA2CC">' . __CLASS__ . '</span>::<span style="color:#E76700">' . __FUNCTION__ . '( ' . $class . '::' . $function . '() )</span><br/><span style="font-size:9px;font-weight:normal;">' . __FILE__ . '</span>    <b style="font-size:10px;">  ' . __LINE__ . ' </b></h3>';
1011
-        do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()');
1011
+        do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : '.$class.'::'.$function.'()');
1012 1012
         $this->reset_cart();
1013 1013
         $this->reset_checkout();
1014 1014
         $this->reset_transaction();
@@ -1030,7 +1030,7 @@  discard block
 block discarded – undo
1030 1030
     public function reset_data($data_to_reset = array(), $show_all_notices = false)
1031 1031
     {
1032 1032
         // if $data_to_reset is not in an array, then put it in one
1033
-        if (! is_array($data_to_reset)) {
1033
+        if ( ! is_array($data_to_reset)) {
1034 1034
             $data_to_reset = array($data_to_reset);
1035 1035
         }
1036 1036
         // nothing ??? go home!
@@ -1044,11 +1044,11 @@  discard block
 block discarded – undo
1044 1044
         foreach ($data_to_reset as $reset) {
1045 1045
 
1046 1046
             // first check to make sure it is a valid session var
1047
-            if (isset($this->_session_data[ $reset ])) {
1047
+            if (isset($this->_session_data[$reset])) {
1048 1048
                 // then check to make sure it is not a default var
1049
-                if (! array_key_exists($reset, $this->_default_session_vars)) {
1049
+                if ( ! array_key_exists($reset, $this->_default_session_vars)) {
1050 1050
                     // remove session var
1051
-                    unset($this->_session_data[ $reset ]);
1051
+                    unset($this->_session_data[$reset]);
1052 1052
                     if ($show_all_notices) {
1053 1053
                         EE_Error::add_success(sprintf(__('The session variable %s was removed.', 'event_espresso'),
1054 1054
                             $reset), __FILE__, __FUNCTION__, __LINE__);
@@ -1128,7 +1128,7 @@  discard block
 block discarded – undo
1128 1128
             // or use that for the new transient cleanup query limit
1129 1129
             add_filter(
1130 1130
                 'FHEE__TransientCacheStorage__clearExpiredTransients__limit',
1131
-                function () use ($expired_session_transient_delete_query_limit)
1131
+                function() use ($expired_session_transient_delete_query_limit)
1132 1132
                 {
1133 1133
                     return $expired_session_transient_delete_query_limit;
1134 1134
                 }
@@ -1148,7 +1148,7 @@  discard block
 block discarded – undo
1148 1148
         $error = '<pre>';
1149 1149
         $data2 = preg_replace_callback(
1150 1150
             '!s:(\d+):"(.*?)";!',
1151
-            function ($match)
1151
+            function($match)
1152 1152
             {
1153 1153
                 return ($match[1] === strlen($match[2]))
1154 1154
                     ? $match[0]
@@ -1160,14 +1160,14 @@  discard block
 block discarded – undo
1160 1160
             },
1161 1161
             $data1
1162 1162
         );
1163
-        $max   = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2);
1164
-        $error .= $data1 . PHP_EOL;
1165
-        $error .= $data2 . PHP_EOL;
1163
+        $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2);
1164
+        $error .= $data1.PHP_EOL;
1165
+        $error .= $data2.PHP_EOL;
1166 1166
         for ($i = 0; $i < $max; $i++) {
1167
-            if (@$data1[ $i ] !== @$data2[ $i ]) {
1168
-                $error  .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL;
1169
-                $error  .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL;
1170
-                $error  .= "\t-> Line Number = $i" . PHP_EOL;
1167
+            if (@$data1[$i] !== @$data2[$i]) {
1168
+                $error  .= 'Difference '.@$data1[$i].' != '.@$data2[$i].PHP_EOL;
1169
+                $error  .= "\t-> ORD number ".ord(@$data1[$i]).' != '.ord(@$data2[$i]).PHP_EOL;
1170
+                $error  .= "\t-> Line Number = $i".PHP_EOL;
1171 1171
                 $start  = ($i - 20);
1172 1172
                 $start  = ($start < 0) ? 0 : $start;
1173 1173
                 $length = 40;
@@ -1182,7 +1182,7 @@  discard block
 block discarded – undo
1182 1182
                 $error .= "\t-> Section Data1  = ";
1183 1183
                 $error .= substr_replace(
1184 1184
                     substr($data1, $start, $length),
1185
-                    "<b style=\"color:green\">{$data1[ $i ]}</b>",
1185
+                    "<b style=\"color:green\">{$data1[$i]}</b>",
1186 1186
                     $rpoint,
1187 1187
                     $rlength
1188 1188
                 );
@@ -1190,7 +1190,7 @@  discard block
 block discarded – undo
1190 1190
                 $error .= "\t-> Section Data2  = ";
1191 1191
                 $error .= substr_replace(
1192 1192
                     substr($data2, $start, $length),
1193
-                    "<b style=\"color:red\">{$data2[ $i ]}</b>",
1193
+                    "<b style=\"color:red\">{$data2[$i]}</b>",
1194 1194
                     $rpoint,
1195 1195
                     $rlength
1196 1196
                 );
@@ -1221,7 +1221,7 @@  discard block
 block discarded – undo
1221 1221
     public function garbageCollection()
1222 1222
     {
1223 1223
         // only perform during regular requests if last garbage collection was over an hour ago
1224
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) {
1224
+        if ( ! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) {
1225 1225
             $this->_last_gc = time();
1226 1226
             $this->updateSessionSettings(array('last_gc' => $this->_last_gc));
1227 1227
             /** @type WPDB $wpdb */
@@ -1256,7 +1256,7 @@  discard block
 block discarded – undo
1256 1256
                 // AND option_value < 1508368198 LIMIT 50
1257 1257
                 $expired_sessions = $wpdb->get_col($SQL);
1258 1258
                 // valid results?
1259
-                if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) {
1259
+                if ( ! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) {
1260 1260
                     $this->cache_storage->deleteMany($expired_sessions, true);
1261 1261
                 }
1262 1262
             }
Please login to merge, or discard this patch.
core/EE_Error.core.php 2 patches
Indentation   +1128 added lines, -1128 removed lines patch added patch discarded remove patch
@@ -11,8 +11,8 @@  discard block
 block discarded – undo
11 11
 // if you're a dev and want to receive all errors via email
12 12
 // add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE );
13 13
 if (defined('WP_DEBUG') && WP_DEBUG === true && defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS === true) {
14
-    set_error_handler(array('EE_Error', 'error_handler'));
15
-    register_shutdown_function(array('EE_Error', 'fatal_error_handler'));
14
+	set_error_handler(array('EE_Error', 'error_handler'));
15
+	register_shutdown_function(array('EE_Error', 'fatal_error_handler'));
16 16
 }
17 17
 
18 18
 
@@ -27,258 +27,258 @@  discard block
 block discarded – undo
27 27
 class EE_Error extends Exception
28 28
 {
29 29
 
30
-    const OPTIONS_KEY_NOTICES = 'ee_notices';
31
-
32
-
33
-    /**
34
-     * name of the file to log exceptions to
35
-     *
36
-     * @var string
37
-     */
38
-    private static $_exception_log_file = 'espresso_error_log.txt';
39
-
40
-    /**
41
-     *    stores details for all exception
42
-     *
43
-     * @var array
44
-     */
45
-    private static $_all_exceptions = array();
46
-
47
-    /**
48
-     *    tracks number of errors
49
-     *
50
-     * @var int
51
-     */
52
-    private static $_error_count = 0;
53
-
54
-    /**
55
-     * @var array $_espresso_notices
56
-     */
57
-    private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false);
58
-
59
-
60
-
61
-    /**
62
-     * @override default exception handling
63
-     * @param string         $message
64
-     * @param int            $code
65
-     * @param Exception|null $previous
66
-     */
67
-    public function __construct($message, $code = 0, Exception $previous = null)
68
-    {
69
-        if (version_compare(PHP_VERSION, '5.3.0', '<')) {
70
-            parent::__construct($message, $code);
71
-        } else {
72
-            parent::__construct($message, $code, $previous);
73
-        }
74
-    }
75
-
76
-
77
-    /**
78
-     *    error_handler
79
-     *
80
-     * @param $code
81
-     * @param $message
82
-     * @param $file
83
-     * @param $line
84
-     * @return void
85
-     */
86
-    public static function error_handler($code, $message, $file, $line)
87
-    {
88
-        $type = EE_Error::error_type($code);
89
-        $site = site_url();
90
-        switch ($site) {
91
-            case 'http://ee4.eventespresso.com/' :
92
-            case 'http://ee4decaf.eventespresso.com/' :
93
-            case 'http://ee4hf.eventespresso.com/' :
94
-            case 'http://ee4a.eventespresso.com/' :
95
-            case 'http://ee4ad.eventespresso.com/' :
96
-            case 'http://ee4b.eventespresso.com/' :
97
-            case 'http://ee4bd.eventespresso.com/' :
98
-            case 'http://ee4d.eventespresso.com/' :
99
-            case 'http://ee4dd.eventespresso.com/' :
100
-                $to = '[email protected]';
101
-                break;
102
-            default :
103
-                $to = get_option('admin_email');
104
-        }
105
-        $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
106
-        $msg = EE_Error::_format_error($type, $message, $file, $line);
107
-        if (function_exists('wp_mail')) {
108
-            add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
109
-            wp_mail($to, $subject, $msg);
110
-        }
111
-        echo '<div id="message" class="espresso-notices error"><p>';
112
-        echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line;
113
-        echo '<br /></p></div>';
114
-    }
115
-
116
-
117
-
118
-    /**
119
-     * error_type
120
-     * http://www.php.net/manual/en/errorfunc.constants.php#109430
121
-     *
122
-     * @param $code
123
-     * @return string
124
-     */
125
-    public static function error_type($code)
126
-    {
127
-        switch ($code) {
128
-            case E_ERROR: // 1 //
129
-                return 'E_ERROR';
130
-            case E_WARNING: // 2 //
131
-                return 'E_WARNING';
132
-            case E_PARSE: // 4 //
133
-                return 'E_PARSE';
134
-            case E_NOTICE: // 8 //
135
-                return 'E_NOTICE';
136
-            case E_CORE_ERROR: // 16 //
137
-                return 'E_CORE_ERROR';
138
-            case E_CORE_WARNING: // 32 //
139
-                return 'E_CORE_WARNING';
140
-            case E_COMPILE_ERROR: // 64 //
141
-                return 'E_COMPILE_ERROR';
142
-            case E_COMPILE_WARNING: // 128 //
143
-                return 'E_COMPILE_WARNING';
144
-            case E_USER_ERROR: // 256 //
145
-                return 'E_USER_ERROR';
146
-            case E_USER_WARNING: // 512 //
147
-                return 'E_USER_WARNING';
148
-            case E_USER_NOTICE: // 1024 //
149
-                return 'E_USER_NOTICE';
150
-            case E_STRICT: // 2048 //
151
-                return 'E_STRICT';
152
-            case E_RECOVERABLE_ERROR: // 4096 //
153
-                return 'E_RECOVERABLE_ERROR';
154
-            case E_DEPRECATED: // 8192 //
155
-                return 'E_DEPRECATED';
156
-            case E_USER_DEPRECATED: // 16384 //
157
-                return 'E_USER_DEPRECATED';
158
-            case E_ALL: // 16384 //
159
-                return 'E_ALL';
160
-        }
161
-        return '';
162
-    }
163
-
164
-
165
-
166
-    /**
167
-     *    fatal_error_handler
168
-     *
169
-     * @return void
170
-     */
171
-    public static function fatal_error_handler()
172
-    {
173
-        $last_error = error_get_last();
174
-        if ($last_error['type'] === E_ERROR) {
175
-            EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
176
-        }
177
-    }
178
-
179
-
180
-
181
-    /**
182
-     * _format_error
183
-     *
184
-     * @param $code
185
-     * @param $message
186
-     * @param $file
187
-     * @param $line
188
-     * @return string
189
-     */
190
-    private static function _format_error($code, $message, $file, $line)
191
-    {
192
-        $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>";
193
-        $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>";
194
-        $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>";
195
-        $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>";
196
-        $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>";
197
-        $html .= '</tbody></table>';
198
-        return $html;
199
-    }
200
-
201
-
202
-
203
-    /**
204
-     * set_content_type
205
-     *
206
-     * @param $content_type
207
-     * @return string
208
-     */
209
-    public static function set_content_type($content_type)
210
-    {
211
-        return 'text/html';
212
-    }
213
-
214
-
215
-
216
-    /**
217
-     * @return void
218
-     * @throws EE_Error
219
-     * @throws ReflectionException
220
-     */
221
-    public function get_error()
222
-    {
223
-        if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) {
224
-            throw $this;
225
-        }
226
-        // get separate user and developer messages if they exist
227
-        $msg = explode('||', $this->getMessage());
228
-        $user_msg = $msg[0];
229
-        $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
230
-        $msg = WP_DEBUG ? $dev_msg : $user_msg;
231
-        // add details to _all_exceptions array
232
-        $x_time = time();
233
-        self::$_all_exceptions[$x_time]['name'] = get_class($this);
234
-        self::$_all_exceptions[$x_time]['file'] = $this->getFile();
235
-        self::$_all_exceptions[$x_time]['line'] = $this->getLine();
236
-        self::$_all_exceptions[$x_time]['msg'] = $msg;
237
-        self::$_all_exceptions[$x_time]['code'] = $this->getCode();
238
-        self::$_all_exceptions[$x_time]['trace'] = $this->getTrace();
239
-        self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString();
240
-        self::$_error_count++;
241
-        //add_action( 'shutdown', array( $this, 'display_errors' ));
242
-        $this->display_errors();
243
-    }
244
-
245
-
246
-    /**
247
-     * @param bool   $check_stored
248
-     * @param string $type_to_check
249
-     * @return bool
250
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
251
-     * @throws \InvalidArgumentException
252
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
253
-     * @throws InvalidInterfaceException
254
-     */
255
-    public static function has_error($check_stored = false, $type_to_check = 'errors')
256
-    {
257
-        $has_error = isset(self::$_espresso_notices[$type_to_check])
258
-                     && ! empty(self::$_espresso_notices[$type_to_check])
259
-            ? true
260
-            : false;
261
-        if ($check_stored && ! $has_error) {
262
-            $notices = EE_Error::getStoredNotices();
263
-            foreach ($notices as $type => $notice) {
264
-                if ($type === $type_to_check && $notice) {
265
-                    return true;
266
-                }
267
-            }
268
-        }
269
-        return $has_error;
270
-    }
271
-
272
-
273
-
274
-    /**
275
-     * @echo string
276
-     * @throws \ReflectionException
277
-     */
278
-    public function display_errors()
279
-    {
280
-        $trace_details = '';
281
-        $output = '
30
+	const OPTIONS_KEY_NOTICES = 'ee_notices';
31
+
32
+
33
+	/**
34
+	 * name of the file to log exceptions to
35
+	 *
36
+	 * @var string
37
+	 */
38
+	private static $_exception_log_file = 'espresso_error_log.txt';
39
+
40
+	/**
41
+	 *    stores details for all exception
42
+	 *
43
+	 * @var array
44
+	 */
45
+	private static $_all_exceptions = array();
46
+
47
+	/**
48
+	 *    tracks number of errors
49
+	 *
50
+	 * @var int
51
+	 */
52
+	private static $_error_count = 0;
53
+
54
+	/**
55
+	 * @var array $_espresso_notices
56
+	 */
57
+	private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false);
58
+
59
+
60
+
61
+	/**
62
+	 * @override default exception handling
63
+	 * @param string         $message
64
+	 * @param int            $code
65
+	 * @param Exception|null $previous
66
+	 */
67
+	public function __construct($message, $code = 0, Exception $previous = null)
68
+	{
69
+		if (version_compare(PHP_VERSION, '5.3.0', '<')) {
70
+			parent::__construct($message, $code);
71
+		} else {
72
+			parent::__construct($message, $code, $previous);
73
+		}
74
+	}
75
+
76
+
77
+	/**
78
+	 *    error_handler
79
+	 *
80
+	 * @param $code
81
+	 * @param $message
82
+	 * @param $file
83
+	 * @param $line
84
+	 * @return void
85
+	 */
86
+	public static function error_handler($code, $message, $file, $line)
87
+	{
88
+		$type = EE_Error::error_type($code);
89
+		$site = site_url();
90
+		switch ($site) {
91
+			case 'http://ee4.eventespresso.com/' :
92
+			case 'http://ee4decaf.eventespresso.com/' :
93
+			case 'http://ee4hf.eventespresso.com/' :
94
+			case 'http://ee4a.eventespresso.com/' :
95
+			case 'http://ee4ad.eventespresso.com/' :
96
+			case 'http://ee4b.eventespresso.com/' :
97
+			case 'http://ee4bd.eventespresso.com/' :
98
+			case 'http://ee4d.eventespresso.com/' :
99
+			case 'http://ee4dd.eventespresso.com/' :
100
+				$to = '[email protected]';
101
+				break;
102
+			default :
103
+				$to = get_option('admin_email');
104
+		}
105
+		$subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
106
+		$msg = EE_Error::_format_error($type, $message, $file, $line);
107
+		if (function_exists('wp_mail')) {
108
+			add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
109
+			wp_mail($to, $subject, $msg);
110
+		}
111
+		echo '<div id="message" class="espresso-notices error"><p>';
112
+		echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line;
113
+		echo '<br /></p></div>';
114
+	}
115
+
116
+
117
+
118
+	/**
119
+	 * error_type
120
+	 * http://www.php.net/manual/en/errorfunc.constants.php#109430
121
+	 *
122
+	 * @param $code
123
+	 * @return string
124
+	 */
125
+	public static function error_type($code)
126
+	{
127
+		switch ($code) {
128
+			case E_ERROR: // 1 //
129
+				return 'E_ERROR';
130
+			case E_WARNING: // 2 //
131
+				return 'E_WARNING';
132
+			case E_PARSE: // 4 //
133
+				return 'E_PARSE';
134
+			case E_NOTICE: // 8 //
135
+				return 'E_NOTICE';
136
+			case E_CORE_ERROR: // 16 //
137
+				return 'E_CORE_ERROR';
138
+			case E_CORE_WARNING: // 32 //
139
+				return 'E_CORE_WARNING';
140
+			case E_COMPILE_ERROR: // 64 //
141
+				return 'E_COMPILE_ERROR';
142
+			case E_COMPILE_WARNING: // 128 //
143
+				return 'E_COMPILE_WARNING';
144
+			case E_USER_ERROR: // 256 //
145
+				return 'E_USER_ERROR';
146
+			case E_USER_WARNING: // 512 //
147
+				return 'E_USER_WARNING';
148
+			case E_USER_NOTICE: // 1024 //
149
+				return 'E_USER_NOTICE';
150
+			case E_STRICT: // 2048 //
151
+				return 'E_STRICT';
152
+			case E_RECOVERABLE_ERROR: // 4096 //
153
+				return 'E_RECOVERABLE_ERROR';
154
+			case E_DEPRECATED: // 8192 //
155
+				return 'E_DEPRECATED';
156
+			case E_USER_DEPRECATED: // 16384 //
157
+				return 'E_USER_DEPRECATED';
158
+			case E_ALL: // 16384 //
159
+				return 'E_ALL';
160
+		}
161
+		return '';
162
+	}
163
+
164
+
165
+
166
+	/**
167
+	 *    fatal_error_handler
168
+	 *
169
+	 * @return void
170
+	 */
171
+	public static function fatal_error_handler()
172
+	{
173
+		$last_error = error_get_last();
174
+		if ($last_error['type'] === E_ERROR) {
175
+			EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']);
176
+		}
177
+	}
178
+
179
+
180
+
181
+	/**
182
+	 * _format_error
183
+	 *
184
+	 * @param $code
185
+	 * @param $message
186
+	 * @param $file
187
+	 * @param $line
188
+	 * @return string
189
+	 */
190
+	private static function _format_error($code, $message, $file, $line)
191
+	{
192
+		$html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>";
193
+		$html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>";
194
+		$html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>";
195
+		$html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>";
196
+		$html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>";
197
+		$html .= '</tbody></table>';
198
+		return $html;
199
+	}
200
+
201
+
202
+
203
+	/**
204
+	 * set_content_type
205
+	 *
206
+	 * @param $content_type
207
+	 * @return string
208
+	 */
209
+	public static function set_content_type($content_type)
210
+	{
211
+		return 'text/html';
212
+	}
213
+
214
+
215
+
216
+	/**
217
+	 * @return void
218
+	 * @throws EE_Error
219
+	 * @throws ReflectionException
220
+	 */
221
+	public function get_error()
222
+	{
223
+		if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) {
224
+			throw $this;
225
+		}
226
+		// get separate user and developer messages if they exist
227
+		$msg = explode('||', $this->getMessage());
228
+		$user_msg = $msg[0];
229
+		$dev_msg = isset($msg[1]) ? $msg[1] : $msg[0];
230
+		$msg = WP_DEBUG ? $dev_msg : $user_msg;
231
+		// add details to _all_exceptions array
232
+		$x_time = time();
233
+		self::$_all_exceptions[$x_time]['name'] = get_class($this);
234
+		self::$_all_exceptions[$x_time]['file'] = $this->getFile();
235
+		self::$_all_exceptions[$x_time]['line'] = $this->getLine();
236
+		self::$_all_exceptions[$x_time]['msg'] = $msg;
237
+		self::$_all_exceptions[$x_time]['code'] = $this->getCode();
238
+		self::$_all_exceptions[$x_time]['trace'] = $this->getTrace();
239
+		self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString();
240
+		self::$_error_count++;
241
+		//add_action( 'shutdown', array( $this, 'display_errors' ));
242
+		$this->display_errors();
243
+	}
244
+
245
+
246
+	/**
247
+	 * @param bool   $check_stored
248
+	 * @param string $type_to_check
249
+	 * @return bool
250
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
251
+	 * @throws \InvalidArgumentException
252
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
253
+	 * @throws InvalidInterfaceException
254
+	 */
255
+	public static function has_error($check_stored = false, $type_to_check = 'errors')
256
+	{
257
+		$has_error = isset(self::$_espresso_notices[$type_to_check])
258
+					 && ! empty(self::$_espresso_notices[$type_to_check])
259
+			? true
260
+			: false;
261
+		if ($check_stored && ! $has_error) {
262
+			$notices = EE_Error::getStoredNotices();
263
+			foreach ($notices as $type => $notice) {
264
+				if ($type === $type_to_check && $notice) {
265
+					return true;
266
+				}
267
+			}
268
+		}
269
+		return $has_error;
270
+	}
271
+
272
+
273
+
274
+	/**
275
+	 * @echo string
276
+	 * @throws \ReflectionException
277
+	 */
278
+	public function display_errors()
279
+	{
280
+		$trace_details = '';
281
+		$output = '
282 282
 <style type="text/css">
283 283
 	#ee-error-message {
284 284
 		max-width:90% !important;
@@ -334,21 +334,21 @@  discard block
 block discarded – undo
334 334
 	}
335 335
 </style>
336 336
 <div id="ee-error-message" class="error">';
337
-        if (! WP_DEBUG) {
338
-            $output .= '
337
+		if (! WP_DEBUG) {
338
+			$output .= '
339 339
 	<p>';
340
-        }
341
-        // cycle thru errors
342
-        foreach (self::$_all_exceptions as $time => $ex) {
343
-            $error_code = '';
344
-            // process trace info
345
-            if (empty($ex['trace'])) {
346
-                $trace_details .= __(
347
-                    'Sorry, but no trace information was available for this exception.',
348
-                    'event_espresso'
349
-                );
350
-            } else {
351
-                $trace_details .= '
340
+		}
341
+		// cycle thru errors
342
+		foreach (self::$_all_exceptions as $time => $ex) {
343
+			$error_code = '';
344
+			// process trace info
345
+			if (empty($ex['trace'])) {
346
+				$trace_details .= __(
347
+					'Sorry, but no trace information was available for this exception.',
348
+					'event_espresso'
349
+				);
350
+			} else {
351
+				$trace_details .= '
352 352
 			<div id="ee-trace-details">
353 353
 			<table width="100%" border="0" cellpadding="5" cellspacing="0">
354 354
 				<tr>
@@ -358,43 +358,43 @@  discard block
 block discarded – undo
358 358
 					<th scope="col" align="left">Class</th>
359 359
 					<th scope="col" align="left">Method( arguments )</th>
360 360
 				</tr>';
361
-                $last_on_stack = count($ex['trace']) - 1;
362
-                // reverse array so that stack is in proper chronological order
363
-                $sorted_trace = array_reverse($ex['trace']);
364
-                foreach ($sorted_trace as $nmbr => $trace) {
365
-                    $file = isset($trace['file']) ? $trace['file'] : '';
366
-                    $class = isset($trace['class']) ? $trace['class'] : '';
367
-                    $type = isset($trace['type']) ? $trace['type'] : '';
368
-                    $function = isset($trace['function']) ? $trace['function'] : '';
369
-                    $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
370
-                    $line = isset($trace['line']) ? $trace['line'] : '';
371
-                    $zebra = ($nmbr % 2) ? ' odd' : '';
372
-                    if (empty($file) && ! empty($class)) {
373
-                        $a = new ReflectionClass($class);
374
-                        $file = $a->getFileName();
375
-                        if (empty($line) && ! empty($function)) {
376
-                            try {
377
-                                //if $function is a closure, this throws an exception
378
-                                $b = new ReflectionMethod($class, $function);
379
-                                $line = $b->getStartLine();
380
-                            } catch (Exception $closure_exception) {
381
-                                $line = 'unknown';
382
-                            }
383
-                        }
384
-                    }
385
-                    if ($nmbr === $last_on_stack) {
386
-                        $file = $ex['file'] !== '' ? $ex['file'] : $file;
387
-                        $line = $ex['line'] !== '' ? $ex['line'] : $line;
388
-                        $error_code = self::generate_error_code($file, $trace['function'], $line);
389
-                    }
390
-                    $nmbr_dsply = ! empty($nmbr) ? $nmbr : '&nbsp;';
391
-                    $line_dsply = ! empty($line) ? $line : '&nbsp;';
392
-                    $file_dsply = ! empty($file) ? $file : '&nbsp;';
393
-                    $class_dsply = ! empty($class) ? $class : '&nbsp;';
394
-                    $type_dsply = ! empty($type) ? $type : '&nbsp;';
395
-                    $function_dsply = ! empty($function) ? $function : '&nbsp;';
396
-                    $args_dsply = ! empty($args) ? '( ' . $args . ' )' : '';
397
-                    $trace_details .= '
361
+				$last_on_stack = count($ex['trace']) - 1;
362
+				// reverse array so that stack is in proper chronological order
363
+				$sorted_trace = array_reverse($ex['trace']);
364
+				foreach ($sorted_trace as $nmbr => $trace) {
365
+					$file = isset($trace['file']) ? $trace['file'] : '';
366
+					$class = isset($trace['class']) ? $trace['class'] : '';
367
+					$type = isset($trace['type']) ? $trace['type'] : '';
368
+					$function = isset($trace['function']) ? $trace['function'] : '';
369
+					$args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : '';
370
+					$line = isset($trace['line']) ? $trace['line'] : '';
371
+					$zebra = ($nmbr % 2) ? ' odd' : '';
372
+					if (empty($file) && ! empty($class)) {
373
+						$a = new ReflectionClass($class);
374
+						$file = $a->getFileName();
375
+						if (empty($line) && ! empty($function)) {
376
+							try {
377
+								//if $function is a closure, this throws an exception
378
+								$b = new ReflectionMethod($class, $function);
379
+								$line = $b->getStartLine();
380
+							} catch (Exception $closure_exception) {
381
+								$line = 'unknown';
382
+							}
383
+						}
384
+					}
385
+					if ($nmbr === $last_on_stack) {
386
+						$file = $ex['file'] !== '' ? $ex['file'] : $file;
387
+						$line = $ex['line'] !== '' ? $ex['line'] : $line;
388
+						$error_code = self::generate_error_code($file, $trace['function'], $line);
389
+					}
390
+					$nmbr_dsply = ! empty($nmbr) ? $nmbr : '&nbsp;';
391
+					$line_dsply = ! empty($line) ? $line : '&nbsp;';
392
+					$file_dsply = ! empty($file) ? $file : '&nbsp;';
393
+					$class_dsply = ! empty($class) ? $class : '&nbsp;';
394
+					$type_dsply = ! empty($type) ? $type : '&nbsp;';
395
+					$function_dsply = ! empty($function) ? $function : '&nbsp;';
396
+					$args_dsply = ! empty($args) ? '( ' . $args . ' )' : '';
397
+					$trace_details .= '
398 398
 					<tr>
399 399
 						<td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td>
400 400
 						<td align="right" class="' . $zebra . '">' . $line_dsply . '</td>
@@ -402,619 +402,619 @@  discard block
 block discarded – undo
402 402
 						<td align="left" class="' . $zebra . '">' . $class_dsply . '</td>
403 403
 						<td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td>
404 404
 					</tr>';
405
-                }
406
-                $trace_details .= '
405
+				}
406
+				$trace_details .= '
407 407
 			 </table>
408 408
 			</div>';
409
-            }
410
-            $ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
411
-            // add generic non-identifying messages for non-privileged users
412
-            if (! WP_DEBUG) {
413
-                $output .= '<span class="ee-error-user-msg-spn">'
414
-                           . trim($ex['msg'])
415
-                           . '</span> &nbsp; <sup>'
416
-                           . $ex['code']
417
-                           . '</sup><br />';
418
-            } else {
419
-                // or helpful developer messages if debugging is on
420
-                $output .= '
409
+			}
410
+			$ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
411
+			// add generic non-identifying messages for non-privileged users
412
+			if (! WP_DEBUG) {
413
+				$output .= '<span class="ee-error-user-msg-spn">'
414
+						   . trim($ex['msg'])
415
+						   . '</span> &nbsp; <sup>'
416
+						   . $ex['code']
417
+						   . '</sup><br />';
418
+			} else {
419
+				// or helpful developer messages if debugging is on
420
+				$output .= '
421 421
 		<div class="ee-error-dev-msg-dv">
422 422
 			<p class="ee-error-dev-msg-pg">
423 423
 				<strong class="ee-error-dev-msg-str">An '
424
-                           . $ex['name']
425
-                           . ' exception was thrown!</strong>  &nbsp; <span>code: '
426
-                           . $ex['code']
427
-                           . '</span><br />
424
+						   . $ex['name']
425
+						   . ' exception was thrown!</strong>  &nbsp; <span>code: '
426
+						   . $ex['code']
427
+						   . '</span><br />
428 428
 				<span class="big-text">"'
429
-                           . trim($ex['msg'])
430
-                           . '"</span><br/>
429
+						   . trim($ex['msg'])
430
+						   . '"</span><br/>
431 431
 				<a id="display-ee-error-trace-'
432
-                           . self::$_error_count
433
-                           . $time
434
-                           . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-'
435
-                           . self::$_error_count
436
-                           . $time
437
-                           . '">
432
+						   . self::$_error_count
433
+						   . $time
434
+						   . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-'
435
+						   . self::$_error_count
436
+						   . $time
437
+						   . '">
438 438
 					'
439
-                           . __('click to view backtrace and class/method details', 'event_espresso')
440
-                           . '
439
+						   . __('click to view backtrace and class/method details', 'event_espresso')
440
+						   . '
441 441
 				</a><br />
442 442
 				<span class="small-text lt-grey-text">'
443
-                           . $ex['file']
444
-                           . ' &nbsp; ( line no: '
445
-                           . $ex['line']
446
-                           . ' )</span>
443
+						   . $ex['file']
444
+						   . ' &nbsp; ( line no: '
445
+						   . $ex['line']
446
+						   . ' )</span>
447 447
 			</p>
448 448
 			<div id="ee-error-trace-'
449
-                           . self::$_error_count
450
-                           . $time
451
-                           . '-dv" class="ee-error-trace-dv" style="display: none;">
449
+						   . self::$_error_count
450
+						   . $time
451
+						   . '-dv" class="ee-error-trace-dv" style="display: none;">
452 452
 				'
453
-                           . $trace_details;
454
-                if (! empty($class)) {
455
-                    $output .= '
453
+						   . $trace_details;
454
+				if (! empty($class)) {
455
+					$output .= '
456 456
 				<div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;">
457 457
 					<div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;">
458 458
 						<h3>Class Details</h3>';
459
-                    $a = new ReflectionClass($class);
460
-                    $output .= '
459
+					$a = new ReflectionClass($class);
460
+					$output .= '
461 461
 						<pre>' . $a . '</pre>
462 462
 					</div>
463 463
 				</div>';
464
-                }
465
-                $output .= '
464
+				}
465
+				$output .= '
466 466
 			</div>
467 467
 		</div>
468 468
 		<br />';
469
-            }
470
-            $this->write_to_error_log($time, $ex);
471
-        }
472
-        // remove last linebreak
473
-        $output = substr($output, 0, -6);
474
-        if (! WP_DEBUG) {
475
-            $output .= '
469
+			}
470
+			$this->write_to_error_log($time, $ex);
471
+		}
472
+		// remove last linebreak
473
+		$output = substr($output, 0, -6);
474
+		if (! WP_DEBUG) {
475
+			$output .= '
476 476
 	</p>';
477
-        }
478
-        $output .= '
477
+		}
478
+		$output .= '
479 479
 </div>';
480
-        $output .= self::_print_scripts(true);
481
-        if (defined('DOING_AJAX')) {
482
-            echo wp_json_encode(array('error' => $output));
483
-            exit();
484
-        }
485
-        echo $output;
486
-        die();
487
-    }
488
-
489
-
490
-
491
-    /**
492
-     *    generate string from exception trace args
493
-     *
494
-     * @param array $arguments
495
-     * @param bool  $array
496
-     * @return string
497
-     */
498
-    private function _convert_args_to_string($arguments = array(), $array = false)
499
-    {
500
-        $arg_string = '';
501
-        if (! empty($arguments)) {
502
-            $args = array();
503
-            foreach ($arguments as $arg) {
504
-                if (! empty($arg)) {
505
-                    if (is_string($arg)) {
506
-                        $args[] = " '" . $arg . "'";
507
-                    } elseif (is_array($arg)) {
508
-                        $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true);
509
-                    } elseif ($arg === null) {
510
-                        $args[] = ' NULL';
511
-                    } elseif (is_bool($arg)) {
512
-                        $args[] = ($arg) ? ' TRUE' : ' FALSE';
513
-                    } elseif (is_object($arg)) {
514
-                        $args[] = ' OBJECT ' . get_class($arg);
515
-                    } elseif (is_resource($arg)) {
516
-                        $args[] = get_resource_type($arg);
517
-                    } else {
518
-                        $args[] = $arg;
519
-                    }
520
-                }
521
-            }
522
-            $arg_string = implode(', ', $args);
523
-        }
524
-        if ($array) {
525
-            $arg_string .= ' )';
526
-        }
527
-        return $arg_string;
528
-    }
529
-
530
-
531
-
532
-    /**
533
-     *    add error message
534
-     *
535
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
536
-     *                            separate messages for user || dev
537
-     * @param        string $file the file that the error occurred in - just use __FILE__
538
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
539
-     * @param        string $line the line number where the error occurred - just use __LINE__
540
-     * @return        void
541
-     */
542
-    public static function add_error($msg = null, $file = null, $func = null, $line = null)
543
-    {
544
-        self::_add_notice('errors', $msg, $file, $func, $line);
545
-        self::$_error_count++;
546
-    }
547
-
548
-
549
-
550
-    /**
551
-     * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just
552
-     * adds an error
553
-     *
554
-     * @param string $msg
555
-     * @param string $file
556
-     * @param string $func
557
-     * @param string $line
558
-     * @throws EE_Error
559
-     */
560
-    public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null)
561
-    {
562
-        if (WP_DEBUG) {
563
-            throw new EE_Error($msg);
564
-        }
565
-        EE_Error::add_error($msg, $file, $func, $line);
566
-    }
567
-
568
-
569
-
570
-    /**
571
-     *    add success message
572
-     *
573
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
574
-     *                            separate messages for user || dev
575
-     * @param        string $file the file that the error occurred in - just use __FILE__
576
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
577
-     * @param        string $line the line number where the error occurred - just use __LINE__
578
-     * @return        void
579
-     */
580
-    public static function add_success($msg = null, $file = null, $func = null, $line = null)
581
-    {
582
-        self::_add_notice('success', $msg, $file, $func, $line);
583
-    }
584
-
585
-
586
-
587
-    /**
588
-     *    add attention message
589
-     *
590
-     * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
591
-     *                            separate messages for user || dev
592
-     * @param        string $file the file that the error occurred in - just use __FILE__
593
-     * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
594
-     * @param        string $line the line number where the error occurred - just use __LINE__
595
-     * @return        void
596
-     */
597
-    public static function add_attention($msg = null, $file = null, $func = null, $line = null)
598
-    {
599
-        self::_add_notice('attention', $msg, $file, $func, $line);
600
-    }
601
-
602
-
603
-
604
-    /**
605
-     * @param string $type whether the message is for a success or error notification
606
-     * @param string $msg the message to display to users or developers
607
-     *                    - adding a double pipe || (OR) creates separate messages for user || dev
608
-     * @param string $file the file that the error occurred in - just use __FILE__
609
-     * @param string $func the function/method that the error occurred in - just use __FUNCTION__
610
-     * @param string $line the line number where the error occurred - just use __LINE__
611
-     * @return void
612
-     */
613
-    private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '')
614
-    {
615
-        if (empty($msg)) {
616
-            EE_Error::doing_it_wrong(
617
-                'EE_Error::add_' . $type . '()',
618
-                sprintf(
619
-                    __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d',
620
-                        'event_espresso'),
621
-                    $type,
622
-                    $file,
623
-                    $line
624
-                ),
625
-                EVENT_ESPRESSO_VERSION
626
-            );
627
-        }
628
-        if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) {
629
-            EE_Error::doing_it_wrong(
630
-                'EE_Error::add_error()',
631
-                __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.',
632
-                    'event_espresso'),
633
-                EVENT_ESPRESSO_VERSION
634
-            );
635
-        }
636
-        // get separate user and developer messages if they exist
637
-        $msg      = explode('||', $msg);
638
-        $user_msg = $msg[0];
639
-        $dev_msg  = isset($msg[1]) ? $msg[1] : $msg[0];
640
-        /**
641
-         * Do an action so other code can be triggered when a notice is created
642
-         *
643
-         * @param string $type     can be 'errors', 'attention', or 'success'
644
-         * @param string $user_msg message displayed to user when WP_DEBUG is off
645
-         * @param string $user_msg message displayed to user when WP_DEBUG is on
646
-         * @param string $file     file where error was generated
647
-         * @param string $func     function where error was generated
648
-         * @param string $line     line where error was generated
649
-         */
650
-        do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
651
-        $msg = WP_DEBUG ? $dev_msg : $user_msg;
652
-        // add notice if message exists
653
-        if (! empty($msg)) {
654
-            // get error code
655
-            $notice_code = EE_Error::generate_error_code($file, $func, $line);
656
-            if (WP_DEBUG && $type === 'errors') {
657
-                $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
658
-            }
659
-            // add notice. Index by code if it's not blank
660
-            if ($notice_code) {
661
-                self::$_espresso_notices[$type][$notice_code] = $msg;
662
-            } else {
663
-                self::$_espresso_notices[$type][] = $msg;
664
-            }
665
-            add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1);
666
-        }
667
-    }
668
-
669
-
670
-    /**
671
-     * in some case it may be necessary to overwrite the existing success messages
672
-     *
673
-     * @return        void
674
-     */
675
-    public static function overwrite_success()
676
-    {
677
-        self::$_espresso_notices['success'] = false;
678
-    }
679
-
680
-
681
-
682
-    /**
683
-     * in some case it may be necessary to overwrite the existing attention messages
684
-     *
685
-     * @return void
686
-     */
687
-    public static function overwrite_attention()
688
-    {
689
-        self::$_espresso_notices['attention'] = false;
690
-    }
691
-
692
-
693
-
694
-    /**
695
-     * in some case it may be necessary to overwrite the existing error messages
696
-     *
697
-     * @return void
698
-     */
699
-    public static function overwrite_errors()
700
-    {
701
-        self::$_espresso_notices['errors'] = false;
702
-    }
703
-
704
-
705
-
706
-    /**
707
-     * @return void
708
-     */
709
-    public static function reset_notices()
710
-    {
711
-        self::$_espresso_notices['success']   = false;
712
-        self::$_espresso_notices['attention'] = false;
713
-        self::$_espresso_notices['errors']    = false;
714
-    }
715
-
716
-
717
-
718
-    /**
719
-     * @return int
720
-     */
721
-    public static function has_notices()
722
-    {
723
-        $has_notices = 0;
724
-        // check for success messages
725
-        $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])
726
-            ? 3
727
-            : $has_notices;
728
-        // check for attention messages
729
-        $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])
730
-            ? 2
731
-            : $has_notices;
732
-        // check for error messages
733
-        $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])
734
-            ? 1
735
-            : $has_notices;
736
-        return $has_notices;
737
-    }
738
-
739
-
740
-    /**
741
-     * This simply returns non formatted error notices as they were sent into the EE_Error object.
742
-     *
743
-     * @since 4.9.0
744
-     * @return array
745
-     */
746
-    public static function get_vanilla_notices()
747
-    {
748
-        return array(
749
-            'success'   => isset(self::$_espresso_notices['success'])
750
-                ? self::$_espresso_notices['success']
751
-                : array(),
752
-            'attention' => isset(self::$_espresso_notices['attention'])
753
-                ? self::$_espresso_notices['attention']
754
-                : array(),
755
-            'errors'    => isset(self::$_espresso_notices['errors'])
756
-                ? self::$_espresso_notices['errors']
757
-                : array(),
758
-        );
759
-    }
760
-
761
-
762
-    /**
763
-     * @return array
764
-     * @throws InvalidArgumentException
765
-     * @throws InvalidDataTypeException
766
-     * @throws InvalidInterfaceException
767
-     */
768
-    public static function getStoredNotices()
769
-    {
770
-        if ($user_id = get_current_user_id()) {
771
-            // get notices for logged in user
772
-            $notices = get_user_option(EE_Error::OPTIONS_KEY_NOTICES, $user_id);
773
-            return is_array($notices) ? $notices : array();
774
-        }
775
-        if (EE_Session::instance()->isActive()) {
776
-            // get notices for user currently engaged in a session
777
-            $session_data = EE_Session::instance()->get_session_data(EE_Error::OPTIONS_KEY_NOTICES);
778
-            return is_array($session_data) ? $session_data : array();
779
-        }
780
-        // get global notices and hope they apply to the current site visitor
781
-        $notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array());
782
-        return is_array($notices) ? $notices : array();
783
-    }
784
-
785
-
786
-    /**
787
-     * @param array $notices
788
-     * @return bool
789
-     * @throws InvalidArgumentException
790
-     * @throws InvalidDataTypeException
791
-     * @throws InvalidInterfaceException
792
-     */
793
-    public static function storeNotices(array $notices)
794
-    {
795
-        if ($user_id = get_current_user_id()) {
796
-            // store notices for logged in user
797
-            return (bool) update_user_option(
798
-                EE_Error::OPTIONS_KEY_NOTICES,
799
-                $user_id,
800
-                $notices
801
-            );
802
-        }
803
-        if (EE_Session::instance()->isActive()) {
804
-            // store notices for user currently engaged in a session
805
-            return EE_Session::instance()->set_session_data(
806
-                array(EE_Error::OPTIONS_KEY_NOTICES => $notices)
807
-            );
808
-        }
809
-        // store global notices and hope they apply to the same site visitor on the next request
810
-        return update_option(EE_Error::OPTIONS_KEY_NOTICES, $notices);
811
-    }
812
-
813
-
814
-    /**
815
-     * @return bool|TRUE
816
-     * @throws InvalidArgumentException
817
-     * @throws InvalidDataTypeException
818
-     * @throws InvalidInterfaceException
819
-     */
820
-    public static function clearNotices()
821
-    {
822
-        if ($user_id = get_current_user_id()) {
823
-            // clear notices for logged in user
824
-            return (bool) update_user_option(
825
-                EE_Error::OPTIONS_KEY_NOTICES,
826
-                $user_id,
827
-                array()
828
-            );
829
-        }
830
-        if (EE_Session::instance()->isActive()) {
831
-            // clear notices for user currently engaged in a session
832
-            return EE_Session::instance()->reset_data(EE_Error::OPTIONS_KEY_NOTICES);
833
-        }
834
-        // clear global notices and hope none belonged to some for some other site visitor
835
-        return update_option(EE_Error::OPTIONS_KEY_NOTICES, array());
836
-    }
837
-
838
-
839
-    /**
840
-     * compile all error or success messages into one string
841
-     *
842
-     * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them
843
-     * @param boolean $format_output            whether or not to format the messages for display in the WP admin
844
-     * @param boolean $save_to_transient        whether or not to save notices to the db for retrieval on next request
845
-     *                                          - ONLY do this just before redirecting
846
-     * @param boolean $remove_empty             whether or not to unset empty messages
847
-     * @return array
848
-     * @throws InvalidArgumentException
849
-     * @throws InvalidDataTypeException
850
-     * @throws InvalidInterfaceException
851
-     */
852
-    public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true)
853
-    {
854
-        $success_messages   = '';
855
-        $attention_messages = '';
856
-        $error_messages     = '';
857
-        // either save notices to the db
858
-        if ($save_to_transient || isset($_REQUEST['activate-selected'])) {
859
-            self::$_espresso_notices = array_merge(
860
-                EE_Error::getStoredNotices(),
861
-                self::$_espresso_notices
862
-            );
863
-            EE_Error::storeNotices(self::$_espresso_notices);
864
-            return array();
865
-        }
866
-        $print_scripts = EE_Error::combineExistingAndNewNotices();
867
-        // check for success messages
868
-        if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) {
869
-            // combine messages
870
-            $success_messages .= implode(self::$_espresso_notices['success'], '<br />');
871
-            $print_scripts    = true;
872
-        }
873
-        // check for attention messages
874
-        if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) {
875
-            // combine messages
876
-            $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />');
877
-            $print_scripts      = true;
878
-        }
879
-        // check for error messages
880
-        if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) {
881
-            $error_messages .= count(self::$_espresso_notices['errors']) > 1
882
-                ? __('The following errors have occurred:<br />', 'event_espresso')
883
-                : __('An error has occurred:<br />', 'event_espresso');
884
-            // combine messages
885
-            $error_messages .= implode(self::$_espresso_notices['errors'], '<br />');
886
-            $print_scripts  = true;
887
-        }
888
-        if ($format_output) {
889
-            $notices = EE_Error::formatNoticesOutput(
890
-                $success_messages,
891
-                $attention_messages,
892
-                $error_messages
893
-            );
894
-        } else {
895
-            $notices = array(
896
-                'success'   => $success_messages,
897
-                'attention' => $attention_messages,
898
-                'errors'    => $error_messages,
899
-            );
900
-            if ($remove_empty) {
901
-                // remove empty notices
902
-                foreach ($notices as $type => $notice) {
903
-                    if (empty($notice)) {
904
-                        unset($notices[$type]);
905
-                    }
906
-                }
907
-            }
908
-        }
909
-        if ($print_scripts) {
910
-            self::_print_scripts();
911
-        }
912
-        return $notices;
913
-    }
914
-
915
-
916
-    /**
917
-     * @return bool
918
-     * @throws InvalidArgumentException
919
-     * @throws InvalidDataTypeException
920
-     * @throws InvalidInterfaceException
921
-     */
922
-    private static function combineExistingAndNewNotices()
923
-    {
924
-        $print_scripts = false;
925
-        // grab any notices that have been previously saved
926
-        $notices = EE_Error::getStoredNotices();
927
-        if (! empty($notices)) {
928
-            foreach ($notices as $type => $notice) {
929
-                if (is_array($notice) && ! empty($notice)) {
930
-                    // make sure that existing notice type is an array
931
-                    self::$_espresso_notices[ $type ] = is_array(self::$_espresso_notices[ $type ])
932
-                                                        && ! empty(self::$_espresso_notices[ $type ])
933
-                        ? self::$_espresso_notices[ $type ]
934
-                        : array();
935
-                    // add newly created notices to existing ones
936
-                    self::$_espresso_notices[ $type ] += $notice;
937
-                    $print_scripts = true;
938
-                }
939
-            }
940
-            // now clear any stored notices
941
-            EE_Error::clearNotices();
942
-        }
943
-        return $print_scripts;
944
-    }
945
-
946
-
947
-    /**
948
-     * @param string $success_messages
949
-     * @param string $attention_messages
950
-     * @param string $error_messages
951
-     * @return string
952
-     */
953
-    private static function formatNoticesOutput($success_messages, $attention_messages, $error_messages)
954
-    {
955
-        $notices = '<div id="espresso-notices">';
956
-        $close   = is_admin()
957
-            ? ''
958
-            : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"/></a>';
959
-        if ($success_messages !== '') {
960
-            $css_id    = is_admin() ? 'message' : 'espresso-notices-success';
961
-            $css_class = is_admin() ? 'updated fade' : 'success fade-away';
962
-            //showMessage( $success_messages );
963
-            $notices .= '<div id="' . $css_id . '" '
964
-                        . 'class="espresso-notices ' . $css_class . '" '
965
-                        . 'style="display:none;">'
966
-                        . '<p>' . $success_messages . '</p>'
967
-                        . $close
968
-                        . '</div>';
969
-        }
970
-        if ($attention_messages !== '') {
971
-            $css_id    = is_admin() ? 'message' : 'espresso-notices-attention';
972
-            $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away';
973
-            //showMessage( $error_messages, TRUE );
974
-            $notices .= '<div id="' . $css_id . '" '
975
-                        . 'class="espresso-notices ' . $css_class . '" '
976
-                        . 'style="display:none;">'
977
-                        . '<p>' . $attention_messages . '</p>'
978
-                        . $close
979
-                        . '</div>';
980
-        }
981
-        if ($error_messages !== '') {
982
-            $css_id    = is_admin() ? 'message' : 'espresso-notices-error';
983
-            $css_class = is_admin() ? 'error' : 'error fade-away';
984
-            //showMessage( $error_messages, TRUE );
985
-            $notices .= '<div id="' . $css_id . '" '
986
-                        . 'class="espresso-notices ' . $css_class . '" '
987
-                        . 'style="display:none;">'
988
-                        . '<p>' . $error_messages . '</p>'
989
-                        . $close
990
-                        . '</div>';
991
-        }
992
-        $notices .= '</div>';
993
-        return $notices;
994
-    }
995
-
996
-
997
-
998
-    /**
999
-     * _print_scripts
1000
-     *
1001
-     * @param    bool $force_print
1002
-     * @return    string
1003
-     */
1004
-    private static function _print_scripts($force_print = false)
1005
-    {
1006
-        if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1007
-            if (wp_script_is('ee_error_js', 'enqueued')) {
1008
-                return '';
1009
-            }
1010
-            if (wp_script_is('ee_error_js', 'registered')) {
1011
-                wp_enqueue_style('espresso_default');
1012
-                wp_enqueue_style('espresso_custom_css');
1013
-                wp_enqueue_script('ee_error_js');
1014
-                wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG));
1015
-            }
1016
-        } else {
1017
-            return '
480
+		$output .= self::_print_scripts(true);
481
+		if (defined('DOING_AJAX')) {
482
+			echo wp_json_encode(array('error' => $output));
483
+			exit();
484
+		}
485
+		echo $output;
486
+		die();
487
+	}
488
+
489
+
490
+
491
+	/**
492
+	 *    generate string from exception trace args
493
+	 *
494
+	 * @param array $arguments
495
+	 * @param bool  $array
496
+	 * @return string
497
+	 */
498
+	private function _convert_args_to_string($arguments = array(), $array = false)
499
+	{
500
+		$arg_string = '';
501
+		if (! empty($arguments)) {
502
+			$args = array();
503
+			foreach ($arguments as $arg) {
504
+				if (! empty($arg)) {
505
+					if (is_string($arg)) {
506
+						$args[] = " '" . $arg . "'";
507
+					} elseif (is_array($arg)) {
508
+						$args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true);
509
+					} elseif ($arg === null) {
510
+						$args[] = ' NULL';
511
+					} elseif (is_bool($arg)) {
512
+						$args[] = ($arg) ? ' TRUE' : ' FALSE';
513
+					} elseif (is_object($arg)) {
514
+						$args[] = ' OBJECT ' . get_class($arg);
515
+					} elseif (is_resource($arg)) {
516
+						$args[] = get_resource_type($arg);
517
+					} else {
518
+						$args[] = $arg;
519
+					}
520
+				}
521
+			}
522
+			$arg_string = implode(', ', $args);
523
+		}
524
+		if ($array) {
525
+			$arg_string .= ' )';
526
+		}
527
+		return $arg_string;
528
+	}
529
+
530
+
531
+
532
+	/**
533
+	 *    add error message
534
+	 *
535
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
536
+	 *                            separate messages for user || dev
537
+	 * @param        string $file the file that the error occurred in - just use __FILE__
538
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
539
+	 * @param        string $line the line number where the error occurred - just use __LINE__
540
+	 * @return        void
541
+	 */
542
+	public static function add_error($msg = null, $file = null, $func = null, $line = null)
543
+	{
544
+		self::_add_notice('errors', $msg, $file, $func, $line);
545
+		self::$_error_count++;
546
+	}
547
+
548
+
549
+
550
+	/**
551
+	 * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just
552
+	 * adds an error
553
+	 *
554
+	 * @param string $msg
555
+	 * @param string $file
556
+	 * @param string $func
557
+	 * @param string $line
558
+	 * @throws EE_Error
559
+	 */
560
+	public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null)
561
+	{
562
+		if (WP_DEBUG) {
563
+			throw new EE_Error($msg);
564
+		}
565
+		EE_Error::add_error($msg, $file, $func, $line);
566
+	}
567
+
568
+
569
+
570
+	/**
571
+	 *    add success message
572
+	 *
573
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
574
+	 *                            separate messages for user || dev
575
+	 * @param        string $file the file that the error occurred in - just use __FILE__
576
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
577
+	 * @param        string $line the line number where the error occurred - just use __LINE__
578
+	 * @return        void
579
+	 */
580
+	public static function add_success($msg = null, $file = null, $func = null, $line = null)
581
+	{
582
+		self::_add_notice('success', $msg, $file, $func, $line);
583
+	}
584
+
585
+
586
+
587
+	/**
588
+	 *    add attention message
589
+	 *
590
+	 * @param        string $msg  the message to display to users or developers - adding a double pipe || (OR) creates
591
+	 *                            separate messages for user || dev
592
+	 * @param        string $file the file that the error occurred in - just use __FILE__
593
+	 * @param        string $func the function/method that the error occurred in - just use __FUNCTION__
594
+	 * @param        string $line the line number where the error occurred - just use __LINE__
595
+	 * @return        void
596
+	 */
597
+	public static function add_attention($msg = null, $file = null, $func = null, $line = null)
598
+	{
599
+		self::_add_notice('attention', $msg, $file, $func, $line);
600
+	}
601
+
602
+
603
+
604
+	/**
605
+	 * @param string $type whether the message is for a success or error notification
606
+	 * @param string $msg the message to display to users or developers
607
+	 *                    - adding a double pipe || (OR) creates separate messages for user || dev
608
+	 * @param string $file the file that the error occurred in - just use __FILE__
609
+	 * @param string $func the function/method that the error occurred in - just use __FUNCTION__
610
+	 * @param string $line the line number where the error occurred - just use __LINE__
611
+	 * @return void
612
+	 */
613
+	private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '')
614
+	{
615
+		if (empty($msg)) {
616
+			EE_Error::doing_it_wrong(
617
+				'EE_Error::add_' . $type . '()',
618
+				sprintf(
619
+					__('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d',
620
+						'event_espresso'),
621
+					$type,
622
+					$file,
623
+					$line
624
+				),
625
+				EVENT_ESPRESSO_VERSION
626
+			);
627
+		}
628
+		if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) {
629
+			EE_Error::doing_it_wrong(
630
+				'EE_Error::add_error()',
631
+				__('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.',
632
+					'event_espresso'),
633
+				EVENT_ESPRESSO_VERSION
634
+			);
635
+		}
636
+		// get separate user and developer messages if they exist
637
+		$msg      = explode('||', $msg);
638
+		$user_msg = $msg[0];
639
+		$dev_msg  = isset($msg[1]) ? $msg[1] : $msg[0];
640
+		/**
641
+		 * Do an action so other code can be triggered when a notice is created
642
+		 *
643
+		 * @param string $type     can be 'errors', 'attention', or 'success'
644
+		 * @param string $user_msg message displayed to user when WP_DEBUG is off
645
+		 * @param string $user_msg message displayed to user when WP_DEBUG is on
646
+		 * @param string $file     file where error was generated
647
+		 * @param string $func     function where error was generated
648
+		 * @param string $line     line where error was generated
649
+		 */
650
+		do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
651
+		$msg = WP_DEBUG ? $dev_msg : $user_msg;
652
+		// add notice if message exists
653
+		if (! empty($msg)) {
654
+			// get error code
655
+			$notice_code = EE_Error::generate_error_code($file, $func, $line);
656
+			if (WP_DEBUG && $type === 'errors') {
657
+				$msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
658
+			}
659
+			// add notice. Index by code if it's not blank
660
+			if ($notice_code) {
661
+				self::$_espresso_notices[$type][$notice_code] = $msg;
662
+			} else {
663
+				self::$_espresso_notices[$type][] = $msg;
664
+			}
665
+			add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1);
666
+		}
667
+	}
668
+
669
+
670
+	/**
671
+	 * in some case it may be necessary to overwrite the existing success messages
672
+	 *
673
+	 * @return        void
674
+	 */
675
+	public static function overwrite_success()
676
+	{
677
+		self::$_espresso_notices['success'] = false;
678
+	}
679
+
680
+
681
+
682
+	/**
683
+	 * in some case it may be necessary to overwrite the existing attention messages
684
+	 *
685
+	 * @return void
686
+	 */
687
+	public static function overwrite_attention()
688
+	{
689
+		self::$_espresso_notices['attention'] = false;
690
+	}
691
+
692
+
693
+
694
+	/**
695
+	 * in some case it may be necessary to overwrite the existing error messages
696
+	 *
697
+	 * @return void
698
+	 */
699
+	public static function overwrite_errors()
700
+	{
701
+		self::$_espresso_notices['errors'] = false;
702
+	}
703
+
704
+
705
+
706
+	/**
707
+	 * @return void
708
+	 */
709
+	public static function reset_notices()
710
+	{
711
+		self::$_espresso_notices['success']   = false;
712
+		self::$_espresso_notices['attention'] = false;
713
+		self::$_espresso_notices['errors']    = false;
714
+	}
715
+
716
+
717
+
718
+	/**
719
+	 * @return int
720
+	 */
721
+	public static function has_notices()
722
+	{
723
+		$has_notices = 0;
724
+		// check for success messages
725
+		$has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])
726
+			? 3
727
+			: $has_notices;
728
+		// check for attention messages
729
+		$has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])
730
+			? 2
731
+			: $has_notices;
732
+		// check for error messages
733
+		$has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])
734
+			? 1
735
+			: $has_notices;
736
+		return $has_notices;
737
+	}
738
+
739
+
740
+	/**
741
+	 * This simply returns non formatted error notices as they were sent into the EE_Error object.
742
+	 *
743
+	 * @since 4.9.0
744
+	 * @return array
745
+	 */
746
+	public static function get_vanilla_notices()
747
+	{
748
+		return array(
749
+			'success'   => isset(self::$_espresso_notices['success'])
750
+				? self::$_espresso_notices['success']
751
+				: array(),
752
+			'attention' => isset(self::$_espresso_notices['attention'])
753
+				? self::$_espresso_notices['attention']
754
+				: array(),
755
+			'errors'    => isset(self::$_espresso_notices['errors'])
756
+				? self::$_espresso_notices['errors']
757
+				: array(),
758
+		);
759
+	}
760
+
761
+
762
+	/**
763
+	 * @return array
764
+	 * @throws InvalidArgumentException
765
+	 * @throws InvalidDataTypeException
766
+	 * @throws InvalidInterfaceException
767
+	 */
768
+	public static function getStoredNotices()
769
+	{
770
+		if ($user_id = get_current_user_id()) {
771
+			// get notices for logged in user
772
+			$notices = get_user_option(EE_Error::OPTIONS_KEY_NOTICES, $user_id);
773
+			return is_array($notices) ? $notices : array();
774
+		}
775
+		if (EE_Session::instance()->isActive()) {
776
+			// get notices for user currently engaged in a session
777
+			$session_data = EE_Session::instance()->get_session_data(EE_Error::OPTIONS_KEY_NOTICES);
778
+			return is_array($session_data) ? $session_data : array();
779
+		}
780
+		// get global notices and hope they apply to the current site visitor
781
+		$notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array());
782
+		return is_array($notices) ? $notices : array();
783
+	}
784
+
785
+
786
+	/**
787
+	 * @param array $notices
788
+	 * @return bool
789
+	 * @throws InvalidArgumentException
790
+	 * @throws InvalidDataTypeException
791
+	 * @throws InvalidInterfaceException
792
+	 */
793
+	public static function storeNotices(array $notices)
794
+	{
795
+		if ($user_id = get_current_user_id()) {
796
+			// store notices for logged in user
797
+			return (bool) update_user_option(
798
+				EE_Error::OPTIONS_KEY_NOTICES,
799
+				$user_id,
800
+				$notices
801
+			);
802
+		}
803
+		if (EE_Session::instance()->isActive()) {
804
+			// store notices for user currently engaged in a session
805
+			return EE_Session::instance()->set_session_data(
806
+				array(EE_Error::OPTIONS_KEY_NOTICES => $notices)
807
+			);
808
+		}
809
+		// store global notices and hope they apply to the same site visitor on the next request
810
+		return update_option(EE_Error::OPTIONS_KEY_NOTICES, $notices);
811
+	}
812
+
813
+
814
+	/**
815
+	 * @return bool|TRUE
816
+	 * @throws InvalidArgumentException
817
+	 * @throws InvalidDataTypeException
818
+	 * @throws InvalidInterfaceException
819
+	 */
820
+	public static function clearNotices()
821
+	{
822
+		if ($user_id = get_current_user_id()) {
823
+			// clear notices for logged in user
824
+			return (bool) update_user_option(
825
+				EE_Error::OPTIONS_KEY_NOTICES,
826
+				$user_id,
827
+				array()
828
+			);
829
+		}
830
+		if (EE_Session::instance()->isActive()) {
831
+			// clear notices for user currently engaged in a session
832
+			return EE_Session::instance()->reset_data(EE_Error::OPTIONS_KEY_NOTICES);
833
+		}
834
+		// clear global notices and hope none belonged to some for some other site visitor
835
+		return update_option(EE_Error::OPTIONS_KEY_NOTICES, array());
836
+	}
837
+
838
+
839
+	/**
840
+	 * compile all error or success messages into one string
841
+	 *
842
+	 * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them
843
+	 * @param boolean $format_output            whether or not to format the messages for display in the WP admin
844
+	 * @param boolean $save_to_transient        whether or not to save notices to the db for retrieval on next request
845
+	 *                                          - ONLY do this just before redirecting
846
+	 * @param boolean $remove_empty             whether or not to unset empty messages
847
+	 * @return array
848
+	 * @throws InvalidArgumentException
849
+	 * @throws InvalidDataTypeException
850
+	 * @throws InvalidInterfaceException
851
+	 */
852
+	public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true)
853
+	{
854
+		$success_messages   = '';
855
+		$attention_messages = '';
856
+		$error_messages     = '';
857
+		// either save notices to the db
858
+		if ($save_to_transient || isset($_REQUEST['activate-selected'])) {
859
+			self::$_espresso_notices = array_merge(
860
+				EE_Error::getStoredNotices(),
861
+				self::$_espresso_notices
862
+			);
863
+			EE_Error::storeNotices(self::$_espresso_notices);
864
+			return array();
865
+		}
866
+		$print_scripts = EE_Error::combineExistingAndNewNotices();
867
+		// check for success messages
868
+		if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) {
869
+			// combine messages
870
+			$success_messages .= implode(self::$_espresso_notices['success'], '<br />');
871
+			$print_scripts    = true;
872
+		}
873
+		// check for attention messages
874
+		if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) {
875
+			// combine messages
876
+			$attention_messages .= implode(self::$_espresso_notices['attention'], '<br />');
877
+			$print_scripts      = true;
878
+		}
879
+		// check for error messages
880
+		if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) {
881
+			$error_messages .= count(self::$_espresso_notices['errors']) > 1
882
+				? __('The following errors have occurred:<br />', 'event_espresso')
883
+				: __('An error has occurred:<br />', 'event_espresso');
884
+			// combine messages
885
+			$error_messages .= implode(self::$_espresso_notices['errors'], '<br />');
886
+			$print_scripts  = true;
887
+		}
888
+		if ($format_output) {
889
+			$notices = EE_Error::formatNoticesOutput(
890
+				$success_messages,
891
+				$attention_messages,
892
+				$error_messages
893
+			);
894
+		} else {
895
+			$notices = array(
896
+				'success'   => $success_messages,
897
+				'attention' => $attention_messages,
898
+				'errors'    => $error_messages,
899
+			);
900
+			if ($remove_empty) {
901
+				// remove empty notices
902
+				foreach ($notices as $type => $notice) {
903
+					if (empty($notice)) {
904
+						unset($notices[$type]);
905
+					}
906
+				}
907
+			}
908
+		}
909
+		if ($print_scripts) {
910
+			self::_print_scripts();
911
+		}
912
+		return $notices;
913
+	}
914
+
915
+
916
+	/**
917
+	 * @return bool
918
+	 * @throws InvalidArgumentException
919
+	 * @throws InvalidDataTypeException
920
+	 * @throws InvalidInterfaceException
921
+	 */
922
+	private static function combineExistingAndNewNotices()
923
+	{
924
+		$print_scripts = false;
925
+		// grab any notices that have been previously saved
926
+		$notices = EE_Error::getStoredNotices();
927
+		if (! empty($notices)) {
928
+			foreach ($notices as $type => $notice) {
929
+				if (is_array($notice) && ! empty($notice)) {
930
+					// make sure that existing notice type is an array
931
+					self::$_espresso_notices[ $type ] = is_array(self::$_espresso_notices[ $type ])
932
+														&& ! empty(self::$_espresso_notices[ $type ])
933
+						? self::$_espresso_notices[ $type ]
934
+						: array();
935
+					// add newly created notices to existing ones
936
+					self::$_espresso_notices[ $type ] += $notice;
937
+					$print_scripts = true;
938
+				}
939
+			}
940
+			// now clear any stored notices
941
+			EE_Error::clearNotices();
942
+		}
943
+		return $print_scripts;
944
+	}
945
+
946
+
947
+	/**
948
+	 * @param string $success_messages
949
+	 * @param string $attention_messages
950
+	 * @param string $error_messages
951
+	 * @return string
952
+	 */
953
+	private static function formatNoticesOutput($success_messages, $attention_messages, $error_messages)
954
+	{
955
+		$notices = '<div id="espresso-notices">';
956
+		$close   = is_admin()
957
+			? ''
958
+			: '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"/></a>';
959
+		if ($success_messages !== '') {
960
+			$css_id    = is_admin() ? 'message' : 'espresso-notices-success';
961
+			$css_class = is_admin() ? 'updated fade' : 'success fade-away';
962
+			//showMessage( $success_messages );
963
+			$notices .= '<div id="' . $css_id . '" '
964
+						. 'class="espresso-notices ' . $css_class . '" '
965
+						. 'style="display:none;">'
966
+						. '<p>' . $success_messages . '</p>'
967
+						. $close
968
+						. '</div>';
969
+		}
970
+		if ($attention_messages !== '') {
971
+			$css_id    = is_admin() ? 'message' : 'espresso-notices-attention';
972
+			$css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away';
973
+			//showMessage( $error_messages, TRUE );
974
+			$notices .= '<div id="' . $css_id . '" '
975
+						. 'class="espresso-notices ' . $css_class . '" '
976
+						. 'style="display:none;">'
977
+						. '<p>' . $attention_messages . '</p>'
978
+						. $close
979
+						. '</div>';
980
+		}
981
+		if ($error_messages !== '') {
982
+			$css_id    = is_admin() ? 'message' : 'espresso-notices-error';
983
+			$css_class = is_admin() ? 'error' : 'error fade-away';
984
+			//showMessage( $error_messages, TRUE );
985
+			$notices .= '<div id="' . $css_id . '" '
986
+						. 'class="espresso-notices ' . $css_class . '" '
987
+						. 'style="display:none;">'
988
+						. '<p>' . $error_messages . '</p>'
989
+						. $close
990
+						. '</div>';
991
+		}
992
+		$notices .= '</div>';
993
+		return $notices;
994
+	}
995
+
996
+
997
+
998
+	/**
999
+	 * _print_scripts
1000
+	 *
1001
+	 * @param    bool $force_print
1002
+	 * @return    string
1003
+	 */
1004
+	private static function _print_scripts($force_print = false)
1005
+	{
1006
+		if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1007
+			if (wp_script_is('ee_error_js', 'enqueued')) {
1008
+				return '';
1009
+			}
1010
+			if (wp_script_is('ee_error_js', 'registered')) {
1011
+				wp_enqueue_style('espresso_default');
1012
+				wp_enqueue_style('espresso_custom_css');
1013
+				wp_enqueue_script('ee_error_js');
1014
+				wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG));
1015
+			}
1016
+		} else {
1017
+			return '
1018 1018
 <script>
1019 1019
 /* <![CDATA[ */
1020 1020
 const ee_settings = {"wp_debug":"' . WP_DEBUG . '"};
@@ -1024,223 +1024,223 @@  discard block
 block discarded – undo
1024 1024
 <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1025 1025
 <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1026 1026
 ';
1027
-        }
1028
-        return '';
1029
-    }
1030
-
1031
-
1032
-
1033
-    /**
1034
-     * @return void
1035
-     */
1036
-    public static function enqueue_error_scripts()
1037
-    {
1038
-        self::_print_scripts();
1039
-    }
1040
-
1041
-
1042
-
1043
-    /**
1044
-     * create error code from filepath, function name,
1045
-     * and line number where exception or error was thrown
1046
-     *
1047
-     * @param string $file
1048
-     * @param string $func
1049
-     * @param string $line
1050
-     * @return string
1051
-     */
1052
-    public static function generate_error_code($file = '', $func = '', $line = '')
1053
-    {
1054
-        $file       = explode('.', basename($file));
1055
-        $error_code = ! empty($file[0]) ? $file[0] : '';
1056
-        $error_code .= ! empty($func) ? ' - ' . $func : '';
1057
-        $error_code .= ! empty($line) ? ' - ' . $line : '';
1058
-        return $error_code;
1059
-    }
1060
-
1061
-
1062
-
1063
-    /**
1064
-     * write exception details to log file
1065
-     * Since 4.9.53.rc.006 this writes to the standard PHP log file, not EE's custom log file
1066
-     *
1067
-     * @param int   $time
1068
-     * @param array $ex
1069
-     * @param bool  $clear
1070
-     * @return void
1071
-     */
1072
-    public function write_to_error_log($time = 0, $ex = array(), $clear = false)
1073
-    {
1074
-        if (empty($ex)) {
1075
-            return;
1076
-        }
1077
-        if (! $time) {
1078
-            $time = time();
1079
-        }
1080
-        $exception_log = '----------------------------------------------------------------------------------------'
1081
-                         . PHP_EOL;
1082
-        $exception_log .= '[' . date('Y-m-d H:i:s', $time) . ']  Exception Details' . PHP_EOL;
1083
-        $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
1084
-        $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL;
1085
-        $exception_log .= 'File: ' . $ex['file'] . PHP_EOL;
1086
-        $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
1087
-        $exception_log .= 'Stack trace: ' . PHP_EOL;
1088
-        $exception_log .= $ex['string'] . PHP_EOL;
1089
-        $exception_log .= '----------------------------------------------------------------------------------------'
1090
-                          . PHP_EOL;
1091
-        try {
1092
-            error_log($exception_log);
1093
-        } catch (EE_Error $e) {
1094
-            EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s',
1095
-                'event_espresso'), $e->getMessage()));
1096
-        }
1097
-    }
1098
-
1099
-
1100
-
1101
-    /**
1102
-     * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method.
1103
-     * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown,
1104
-     * but the code execution is done in a manner that could lead to unexpected results
1105
-     * (i.e. running to early, or too late in WP or EE loading process).
1106
-     * A good test for knowing whether to use this method is:
1107
-     * 1. Is there going to be a PHP error if something isn't setup/used correctly?
1108
-     * Yes -> use EE_Error::add_error() or throw new EE_Error()
1109
-     * 2. If this is loaded before something else, it won't break anything,
1110
-     * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong()
1111
-     *
1112
-     * @uses   constant WP_DEBUG test if wp_debug is on or not
1113
-     * @param string $function      The function that was called
1114
-     * @param string $message       A message explaining what has been done incorrectly
1115
-     * @param string $version       The version of Event Espresso where the error was added
1116
-     * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
1117
-     *                              for a deprecated function. This allows deprecation to occur during one version,
1118
-     *                              but not have any notices appear until a later version. This allows developers
1119
-     *                              extra time to update their code before notices appear.
1120
-     * @param int    $error_type
1121
-     */
1122
-    public static function doing_it_wrong(
1123
-        $function,
1124
-        $message,
1125
-        $version,
1126
-        $applies_when = '',
1127
-        $error_type = null
1128
-    ) {
1129
-        if (defined('WP_DEBUG') && WP_DEBUG) {
1130
-            EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type);
1131
-        }
1132
-    }
1133
-
1134
-
1135
-
1136
-    /**
1137
-     * Like get_notices, but returns an array of all the notices of the given type.
1138
-     *
1139
-     * @return array {
1140
-     *  @type array $success   all the success messages
1141
-     *  @type array $errors    all the error messages
1142
-     *  @type array $attention all the attention messages
1143
-     * }
1144
-     */
1145
-    public static function get_raw_notices()
1146
-    {
1147
-        return self::$_espresso_notices;
1148
-    }
1149
-
1150
-
1151
-
1152
-    /**
1153
-     * @deprecated 4.9.27
1154
-     * @param string $pan_name     the name, or key of the Persistent Admin Notice to be stored
1155
-     * @param string $pan_message  the message to be stored persistently until dismissed
1156
-     * @param bool   $force_update allows one to enforce the reappearance of a persistent message.
1157
-     * @return void
1158
-     * @throws InvalidDataTypeException
1159
-     */
1160
-    public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false)
1161
-    {
1162
-        new PersistentAdminNotice(
1163
-            $pan_name,
1164
-            $pan_message,
1165
-            $force_update
1166
-        );
1167
-        EE_Error::doing_it_wrong(
1168
-            __METHOD__,
1169
-            sprintf(
1170
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1171
-                '\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice'
1172
-            ),
1173
-            '4.9.27'
1174
-        );
1175
-    }
1176
-
1177
-
1178
-
1179
-    /**
1180
-     * @deprecated 4.9.27
1181
-     * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed
1182
-     * @param bool   $purge
1183
-     * @param bool   $return
1184
-     * @throws DomainException
1185
-     * @throws InvalidInterfaceException
1186
-     * @throws InvalidDataTypeException
1187
-     * @throws ServiceNotFoundException
1188
-     * @throws InvalidArgumentException
1189
-     */
1190
-    public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false)
1191
-    {
1192
-        /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */
1193
-        $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
1194
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1195
-        );
1196
-        $persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return);
1197
-        EE_Error::doing_it_wrong(
1198
-            __METHOD__,
1199
-            sprintf(
1200
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1201
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1202
-            ),
1203
-            '4.9.27'
1204
-        );
1205
-    }
1206
-
1207
-
1208
-
1209
-    /**
1210
-     * @deprecated 4.9.27
1211
-     * @param  string $pan_name    the name, or key of the Persistent Admin Notice to be stored
1212
-     * @param  string $pan_message the message to be stored persistently until dismissed
1213
-     * @param  string $return_url  URL to go back to after nag notice is dismissed
1214
-     */
1215
-    public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '')
1216
-    {
1217
-        EE_Error::doing_it_wrong(
1218
-            __METHOD__,
1219
-            sprintf(
1220
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1221
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1222
-            ),
1223
-            '4.9.27'
1224
-        );
1225
-    }
1226
-
1227
-
1228
-
1229
-    /**
1230
-     * @deprecated 4.9.27
1231
-     * @param string $return_url
1232
-     */
1233
-    public static function get_persistent_admin_notices($return_url = '')
1234
-    {
1235
-        EE_Error::doing_it_wrong(
1236
-            __METHOD__,
1237
-            sprintf(
1238
-                __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1239
-                '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1240
-            ),
1241
-            '4.9.27'
1242
-        );
1243
-    }
1027
+		}
1028
+		return '';
1029
+	}
1030
+
1031
+
1032
+
1033
+	/**
1034
+	 * @return void
1035
+	 */
1036
+	public static function enqueue_error_scripts()
1037
+	{
1038
+		self::_print_scripts();
1039
+	}
1040
+
1041
+
1042
+
1043
+	/**
1044
+	 * create error code from filepath, function name,
1045
+	 * and line number where exception or error was thrown
1046
+	 *
1047
+	 * @param string $file
1048
+	 * @param string $func
1049
+	 * @param string $line
1050
+	 * @return string
1051
+	 */
1052
+	public static function generate_error_code($file = '', $func = '', $line = '')
1053
+	{
1054
+		$file       = explode('.', basename($file));
1055
+		$error_code = ! empty($file[0]) ? $file[0] : '';
1056
+		$error_code .= ! empty($func) ? ' - ' . $func : '';
1057
+		$error_code .= ! empty($line) ? ' - ' . $line : '';
1058
+		return $error_code;
1059
+	}
1060
+
1061
+
1062
+
1063
+	/**
1064
+	 * write exception details to log file
1065
+	 * Since 4.9.53.rc.006 this writes to the standard PHP log file, not EE's custom log file
1066
+	 *
1067
+	 * @param int   $time
1068
+	 * @param array $ex
1069
+	 * @param bool  $clear
1070
+	 * @return void
1071
+	 */
1072
+	public function write_to_error_log($time = 0, $ex = array(), $clear = false)
1073
+	{
1074
+		if (empty($ex)) {
1075
+			return;
1076
+		}
1077
+		if (! $time) {
1078
+			$time = time();
1079
+		}
1080
+		$exception_log = '----------------------------------------------------------------------------------------'
1081
+						 . PHP_EOL;
1082
+		$exception_log .= '[' . date('Y-m-d H:i:s', $time) . ']  Exception Details' . PHP_EOL;
1083
+		$exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
1084
+		$exception_log .= 'Code: ' . $ex['code'] . PHP_EOL;
1085
+		$exception_log .= 'File: ' . $ex['file'] . PHP_EOL;
1086
+		$exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
1087
+		$exception_log .= 'Stack trace: ' . PHP_EOL;
1088
+		$exception_log .= $ex['string'] . PHP_EOL;
1089
+		$exception_log .= '----------------------------------------------------------------------------------------'
1090
+						  . PHP_EOL;
1091
+		try {
1092
+			error_log($exception_log);
1093
+		} catch (EE_Error $e) {
1094
+			EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s',
1095
+				'event_espresso'), $e->getMessage()));
1096
+		}
1097
+	}
1098
+
1099
+
1100
+
1101
+	/**
1102
+	 * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method.
1103
+	 * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown,
1104
+	 * but the code execution is done in a manner that could lead to unexpected results
1105
+	 * (i.e. running to early, or too late in WP or EE loading process).
1106
+	 * A good test for knowing whether to use this method is:
1107
+	 * 1. Is there going to be a PHP error if something isn't setup/used correctly?
1108
+	 * Yes -> use EE_Error::add_error() or throw new EE_Error()
1109
+	 * 2. If this is loaded before something else, it won't break anything,
1110
+	 * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong()
1111
+	 *
1112
+	 * @uses   constant WP_DEBUG test if wp_debug is on or not
1113
+	 * @param string $function      The function that was called
1114
+	 * @param string $message       A message explaining what has been done incorrectly
1115
+	 * @param string $version       The version of Event Espresso where the error was added
1116
+	 * @param string $applies_when  a version string for when you want the doing_it_wrong notice to begin appearing
1117
+	 *                              for a deprecated function. This allows deprecation to occur during one version,
1118
+	 *                              but not have any notices appear until a later version. This allows developers
1119
+	 *                              extra time to update their code before notices appear.
1120
+	 * @param int    $error_type
1121
+	 */
1122
+	public static function doing_it_wrong(
1123
+		$function,
1124
+		$message,
1125
+		$version,
1126
+		$applies_when = '',
1127
+		$error_type = null
1128
+	) {
1129
+		if (defined('WP_DEBUG') && WP_DEBUG) {
1130
+			EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type);
1131
+		}
1132
+	}
1133
+
1134
+
1135
+
1136
+	/**
1137
+	 * Like get_notices, but returns an array of all the notices of the given type.
1138
+	 *
1139
+	 * @return array {
1140
+	 *  @type array $success   all the success messages
1141
+	 *  @type array $errors    all the error messages
1142
+	 *  @type array $attention all the attention messages
1143
+	 * }
1144
+	 */
1145
+	public static function get_raw_notices()
1146
+	{
1147
+		return self::$_espresso_notices;
1148
+	}
1149
+
1150
+
1151
+
1152
+	/**
1153
+	 * @deprecated 4.9.27
1154
+	 * @param string $pan_name     the name, or key of the Persistent Admin Notice to be stored
1155
+	 * @param string $pan_message  the message to be stored persistently until dismissed
1156
+	 * @param bool   $force_update allows one to enforce the reappearance of a persistent message.
1157
+	 * @return void
1158
+	 * @throws InvalidDataTypeException
1159
+	 */
1160
+	public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false)
1161
+	{
1162
+		new PersistentAdminNotice(
1163
+			$pan_name,
1164
+			$pan_message,
1165
+			$force_update
1166
+		);
1167
+		EE_Error::doing_it_wrong(
1168
+			__METHOD__,
1169
+			sprintf(
1170
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1171
+				'\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice'
1172
+			),
1173
+			'4.9.27'
1174
+		);
1175
+	}
1176
+
1177
+
1178
+
1179
+	/**
1180
+	 * @deprecated 4.9.27
1181
+	 * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed
1182
+	 * @param bool   $purge
1183
+	 * @param bool   $return
1184
+	 * @throws DomainException
1185
+	 * @throws InvalidInterfaceException
1186
+	 * @throws InvalidDataTypeException
1187
+	 * @throws ServiceNotFoundException
1188
+	 * @throws InvalidArgumentException
1189
+	 */
1190
+	public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false)
1191
+	{
1192
+		/** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */
1193
+		$persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
1194
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1195
+		);
1196
+		$persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return);
1197
+		EE_Error::doing_it_wrong(
1198
+			__METHOD__,
1199
+			sprintf(
1200
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1201
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1202
+			),
1203
+			'4.9.27'
1204
+		);
1205
+	}
1206
+
1207
+
1208
+
1209
+	/**
1210
+	 * @deprecated 4.9.27
1211
+	 * @param  string $pan_name    the name, or key of the Persistent Admin Notice to be stored
1212
+	 * @param  string $pan_message the message to be stored persistently until dismissed
1213
+	 * @param  string $return_url  URL to go back to after nag notice is dismissed
1214
+	 */
1215
+	public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '')
1216
+	{
1217
+		EE_Error::doing_it_wrong(
1218
+			__METHOD__,
1219
+			sprintf(
1220
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1221
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1222
+			),
1223
+			'4.9.27'
1224
+		);
1225
+	}
1226
+
1227
+
1228
+
1229
+	/**
1230
+	 * @deprecated 4.9.27
1231
+	 * @param string $return_url
1232
+	 */
1233
+	public static function get_persistent_admin_notices($return_url = '')
1234
+	{
1235
+		EE_Error::doing_it_wrong(
1236
+			__METHOD__,
1237
+			sprintf(
1238
+				__('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'),
1239
+				'\EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
1240
+			),
1241
+			'4.9.27'
1242
+		);
1243
+	}
1244 1244
 
1245 1245
 
1246 1246
 
@@ -1255,27 +1255,27 @@  discard block
 block discarded – undo
1255 1255
  */
1256 1256
 function espresso_error_enqueue_scripts()
1257 1257
 {
1258
-    // js for error handling
1259
-    wp_register_script(
1260
-        'espresso_core',
1261
-        EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1262
-        array('jquery'),
1263
-        EVENT_ESPRESSO_VERSION,
1264
-        false
1265
-    );
1266
-    wp_register_script(
1267
-        'ee_error_js',
1268
-        EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1269
-        array('espresso_core'),
1270
-        EVENT_ESPRESSO_VERSION,
1271
-        false
1272
-    );
1258
+	// js for error handling
1259
+	wp_register_script(
1260
+		'espresso_core',
1261
+		EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1262
+		array('jquery'),
1263
+		EVENT_ESPRESSO_VERSION,
1264
+		false
1265
+	);
1266
+	wp_register_script(
1267
+		'ee_error_js',
1268
+		EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1269
+		array('espresso_core'),
1270
+		EVENT_ESPRESSO_VERSION,
1271
+		false
1272
+	);
1273 1273
 }
1274 1274
 
1275 1275
 if (is_admin()) {
1276
-    add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1276
+	add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1277 1277
 } else {
1278
-    add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1278
+	add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2);
1279 1279
 }
1280 1280
 
1281 1281
 
Please login to merge, or discard this patch.
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -102,14 +102,14 @@  discard block
 block discarded – undo
102 102
             default :
103 103
                 $to = get_option('admin_email');
104 104
         }
105
-        $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url();
105
+        $subject = $type.' '.$message.' in '.EVENT_ESPRESSO_VERSION.' on '.site_url();
106 106
         $msg = EE_Error::_format_error($type, $message, $file, $line);
107 107
         if (function_exists('wp_mail')) {
108 108
             add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type'));
109 109
             wp_mail($to, $subject, $msg);
110 110
         }
111 111
         echo '<div id="message" class="espresso-notices error"><p>';
112
-        echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line;
112
+        echo $type.': '.$message.'<br />'.$file.' line '.$line;
113 113
         echo '<br /></p></div>';
114 114
     }
115 115
 
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
 	}
335 335
 </style>
336 336
 <div id="ee-error-message" class="error">';
337
-        if (! WP_DEBUG) {
337
+        if ( ! WP_DEBUG) {
338 338
             $output .= '
339 339
 	<p>';
340 340
         }
@@ -393,14 +393,14 @@  discard block
 block discarded – undo
393 393
                     $class_dsply = ! empty($class) ? $class : '&nbsp;';
394 394
                     $type_dsply = ! empty($type) ? $type : '&nbsp;';
395 395
                     $function_dsply = ! empty($function) ? $function : '&nbsp;';
396
-                    $args_dsply = ! empty($args) ? '( ' . $args . ' )' : '';
396
+                    $args_dsply = ! empty($args) ? '( '.$args.' )' : '';
397 397
                     $trace_details .= '
398 398
 					<tr>
399
-						<td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td>
400
-						<td align="right" class="' . $zebra . '">' . $line_dsply . '</td>
401
-						<td align="left" class="' . $zebra . '">' . $file_dsply . '</td>
402
-						<td align="left" class="' . $zebra . '">' . $class_dsply . '</td>
403
-						<td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td>
399
+						<td align="right" class="' . $zebra.'">'.$nmbr_dsply.'</td>
400
+						<td align="right" class="' . $zebra.'">'.$line_dsply.'</td>
401
+						<td align="left" class="' . $zebra.'">'.$file_dsply.'</td>
402
+						<td align="left" class="' . $zebra.'">'.$class_dsply.'</td>
403
+						<td align="left" class="' . $zebra.'">'.$type_dsply.$function_dsply.$args_dsply.'</td>
404 404
 					</tr>';
405 405
                 }
406 406
                 $trace_details .= '
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
409 409
             }
410 410
             $ex['code'] = $ex['code'] ? $ex['code'] : $error_code;
411 411
             // add generic non-identifying messages for non-privileged users
412
-            if (! WP_DEBUG) {
412
+            if ( ! WP_DEBUG) {
413 413
                 $output .= '<span class="ee-error-user-msg-spn">'
414 414
                            . trim($ex['msg'])
415 415
                            . '</span> &nbsp; <sup>'
@@ -451,14 +451,14 @@  discard block
 block discarded – undo
451 451
                            . '-dv" class="ee-error-trace-dv" style="display: none;">
452 452
 				'
453 453
                            . $trace_details;
454
-                if (! empty($class)) {
454
+                if ( ! empty($class)) {
455 455
                     $output .= '
456 456
 				<div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;">
457 457
 					<div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;">
458 458
 						<h3>Class Details</h3>';
459 459
                     $a = new ReflectionClass($class);
460 460
                     $output .= '
461
-						<pre>' . $a . '</pre>
461
+						<pre>' . $a.'</pre>
462 462
 					</div>
463 463
 				</div>';
464 464
                 }
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
         }
472 472
         // remove last linebreak
473 473
         $output = substr($output, 0, -6);
474
-        if (! WP_DEBUG) {
474
+        if ( ! WP_DEBUG) {
475 475
             $output .= '
476 476
 	</p>';
477 477
         }
@@ -498,20 +498,20 @@  discard block
 block discarded – undo
498 498
     private function _convert_args_to_string($arguments = array(), $array = false)
499 499
     {
500 500
         $arg_string = '';
501
-        if (! empty($arguments)) {
501
+        if ( ! empty($arguments)) {
502 502
             $args = array();
503 503
             foreach ($arguments as $arg) {
504
-                if (! empty($arg)) {
504
+                if ( ! empty($arg)) {
505 505
                     if (is_string($arg)) {
506
-                        $args[] = " '" . $arg . "'";
506
+                        $args[] = " '".$arg."'";
507 507
                     } elseif (is_array($arg)) {
508
-                        $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true);
508
+                        $args[] = 'ARRAY('.$this->_convert_args_to_string($arg, true);
509 509
                     } elseif ($arg === null) {
510 510
                         $args[] = ' NULL';
511 511
                     } elseif (is_bool($arg)) {
512 512
                         $args[] = ($arg) ? ' TRUE' : ' FALSE';
513 513
                     } elseif (is_object($arg)) {
514
-                        $args[] = ' OBJECT ' . get_class($arg);
514
+                        $args[] = ' OBJECT '.get_class($arg);
515 515
                     } elseif (is_resource($arg)) {
516 516
                         $args[] = get_resource_type($arg);
517 517
                     } else {
@@ -614,7 +614,7 @@  discard block
 block discarded – undo
614 614
     {
615 615
         if (empty($msg)) {
616 616
             EE_Error::doing_it_wrong(
617
-                'EE_Error::add_' . $type . '()',
617
+                'EE_Error::add_'.$type.'()',
618 618
                 sprintf(
619 619
                     __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d',
620 620
                         'event_espresso'),
@@ -650,11 +650,11 @@  discard block
 block discarded – undo
650 650
         do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line);
651 651
         $msg = WP_DEBUG ? $dev_msg : $user_msg;
652 652
         // add notice if message exists
653
-        if (! empty($msg)) {
653
+        if ( ! empty($msg)) {
654 654
             // get error code
655 655
             $notice_code = EE_Error::generate_error_code($file, $func, $line);
656 656
             if (WP_DEBUG && $type === 'errors') {
657
-                $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>';
657
+                $msg .= '<br/><span class="tiny-text">'.$notice_code.'</span>';
658 658
             }
659 659
             // add notice. Index by code if it's not blank
660 660
             if ($notice_code) {
@@ -868,13 +868,13 @@  discard block
 block discarded – undo
868 868
         if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) {
869 869
             // combine messages
870 870
             $success_messages .= implode(self::$_espresso_notices['success'], '<br />');
871
-            $print_scripts    = true;
871
+            $print_scripts = true;
872 872
         }
873 873
         // check for attention messages
874 874
         if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) {
875 875
             // combine messages
876 876
             $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />');
877
-            $print_scripts      = true;
877
+            $print_scripts = true;
878 878
         }
879 879
         // check for error messages
880 880
         if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) {
@@ -883,7 +883,7 @@  discard block
 block discarded – undo
883 883
                 : __('An error has occurred:<br />', 'event_espresso');
884 884
             // combine messages
885 885
             $error_messages .= implode(self::$_espresso_notices['errors'], '<br />');
886
-            $print_scripts  = true;
886
+            $print_scripts = true;
887 887
         }
888 888
         if ($format_output) {
889 889
             $notices = EE_Error::formatNoticesOutput(
@@ -924,16 +924,16 @@  discard block
 block discarded – undo
924 924
         $print_scripts = false;
925 925
         // grab any notices that have been previously saved
926 926
         $notices = EE_Error::getStoredNotices();
927
-        if (! empty($notices)) {
927
+        if ( ! empty($notices)) {
928 928
             foreach ($notices as $type => $notice) {
929 929
                 if (is_array($notice) && ! empty($notice)) {
930 930
                     // make sure that existing notice type is an array
931
-                    self::$_espresso_notices[ $type ] = is_array(self::$_espresso_notices[ $type ])
932
-                                                        && ! empty(self::$_espresso_notices[ $type ])
933
-                        ? self::$_espresso_notices[ $type ]
931
+                    self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type])
932
+                                                        && ! empty(self::$_espresso_notices[$type])
933
+                        ? self::$_espresso_notices[$type]
934 934
                         : array();
935 935
                     // add newly created notices to existing ones
936
-                    self::$_espresso_notices[ $type ] += $notice;
936
+                    self::$_espresso_notices[$type] += $notice;
937 937
                     $print_scripts = true;
938 938
                 }
939 939
             }
@@ -960,10 +960,10 @@  discard block
 block discarded – undo
960 960
             $css_id    = is_admin() ? 'message' : 'espresso-notices-success';
961 961
             $css_class = is_admin() ? 'updated fade' : 'success fade-away';
962 962
             //showMessage( $success_messages );
963
-            $notices .= '<div id="' . $css_id . '" '
964
-                        . 'class="espresso-notices ' . $css_class . '" '
963
+            $notices .= '<div id="'.$css_id.'" '
964
+                        . 'class="espresso-notices '.$css_class.'" '
965 965
                         . 'style="display:none;">'
966
-                        . '<p>' . $success_messages . '</p>'
966
+                        . '<p>'.$success_messages.'</p>'
967 967
                         . $close
968 968
                         . '</div>';
969 969
         }
@@ -971,10 +971,10 @@  discard block
 block discarded – undo
971 971
             $css_id    = is_admin() ? 'message' : 'espresso-notices-attention';
972 972
             $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away';
973 973
             //showMessage( $error_messages, TRUE );
974
-            $notices .= '<div id="' . $css_id . '" '
975
-                        . 'class="espresso-notices ' . $css_class . '" '
974
+            $notices .= '<div id="'.$css_id.'" '
975
+                        . 'class="espresso-notices '.$css_class.'" '
976 976
                         . 'style="display:none;">'
977
-                        . '<p>' . $attention_messages . '</p>'
977
+                        . '<p>'.$attention_messages.'</p>'
978 978
                         . $close
979 979
                         . '</div>';
980 980
         }
@@ -982,10 +982,10 @@  discard block
 block discarded – undo
982 982
             $css_id    = is_admin() ? 'message' : 'espresso-notices-error';
983 983
             $css_class = is_admin() ? 'error' : 'error fade-away';
984 984
             //showMessage( $error_messages, TRUE );
985
-            $notices .= '<div id="' . $css_id . '" '
986
-                        . 'class="espresso-notices ' . $css_class . '" '
985
+            $notices .= '<div id="'.$css_id.'" '
986
+                        . 'class="espresso-notices '.$css_class.'" '
987 987
                         . 'style="display:none;">'
988
-                        . '<p>' . $error_messages . '</p>'
988
+                        . '<p>'.$error_messages.'</p>'
989 989
                         . $close
990 990
                         . '</div>';
991 991
         }
@@ -1003,7 +1003,7 @@  discard block
 block discarded – undo
1003 1003
      */
1004 1004
     private static function _print_scripts($force_print = false)
1005 1005
     {
1006
-        if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1006
+        if ( ! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) {
1007 1007
             if (wp_script_is('ee_error_js', 'enqueued')) {
1008 1008
                 return '';
1009 1009
             }
@@ -1017,12 +1017,12 @@  discard block
 block discarded – undo
1017 1017
             return '
1018 1018
 <script>
1019 1019
 /* <![CDATA[ */
1020
-const ee_settings = {"wp_debug":"' . WP_DEBUG . '"};
1020
+const ee_settings = {"wp_debug":"' . WP_DEBUG.'"};
1021 1021
 /* ]]> */
1022 1022
 </script>
1023
-<script src="' . includes_url() . 'js/jquery/jquery.js" type="text/javascript"></script>
1024
-<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1025
-<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script>
1023
+<script src="' . includes_url().'js/jquery/jquery.js" type="text/javascript"></script>
1024
+<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js'.'?ver='.espresso_version().'" type="text/javascript"></script>
1025
+<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js'.'?ver='.espresso_version().'" type="text/javascript"></script>
1026 1026
 ';
1027 1027
         }
1028 1028
         return '';
@@ -1053,8 +1053,8 @@  discard block
 block discarded – undo
1053 1053
     {
1054 1054
         $file       = explode('.', basename($file));
1055 1055
         $error_code = ! empty($file[0]) ? $file[0] : '';
1056
-        $error_code .= ! empty($func) ? ' - ' . $func : '';
1057
-        $error_code .= ! empty($line) ? ' - ' . $line : '';
1056
+        $error_code .= ! empty($func) ? ' - '.$func : '';
1057
+        $error_code .= ! empty($line) ? ' - '.$line : '';
1058 1058
         return $error_code;
1059 1059
     }
1060 1060
 
@@ -1074,18 +1074,18 @@  discard block
 block discarded – undo
1074 1074
         if (empty($ex)) {
1075 1075
             return;
1076 1076
         }
1077
-        if (! $time) {
1077
+        if ( ! $time) {
1078 1078
             $time = time();
1079 1079
         }
1080 1080
         $exception_log = '----------------------------------------------------------------------------------------'
1081 1081
                          . PHP_EOL;
1082
-        $exception_log .= '[' . date('Y-m-d H:i:s', $time) . ']  Exception Details' . PHP_EOL;
1083
-        $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL;
1084
-        $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL;
1085
-        $exception_log .= 'File: ' . $ex['file'] . PHP_EOL;
1086
-        $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL;
1087
-        $exception_log .= 'Stack trace: ' . PHP_EOL;
1088
-        $exception_log .= $ex['string'] . PHP_EOL;
1082
+        $exception_log .= '['.date('Y-m-d H:i:s', $time).']  Exception Details'.PHP_EOL;
1083
+        $exception_log .= 'Message: '.$ex['msg'].PHP_EOL;
1084
+        $exception_log .= 'Code: '.$ex['code'].PHP_EOL;
1085
+        $exception_log .= 'File: '.$ex['file'].PHP_EOL;
1086
+        $exception_log .= 'Line No: '.$ex['line'].PHP_EOL;
1087
+        $exception_log .= 'Stack trace: '.PHP_EOL;
1088
+        $exception_log .= $ex['string'].PHP_EOL;
1089 1089
         $exception_log .= '----------------------------------------------------------------------------------------'
1090 1090
                           . PHP_EOL;
1091 1091
         try {
@@ -1258,14 +1258,14 @@  discard block
 block discarded – undo
1258 1258
     // js for error handling
1259 1259
     wp_register_script(
1260 1260
         'espresso_core',
1261
-        EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
1261
+        EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js',
1262 1262
         array('jquery'),
1263 1263
         EVENT_ESPRESSO_VERSION,
1264 1264
         false
1265 1265
     );
1266 1266
     wp_register_script(
1267 1267
         'ee_error_js',
1268
-        EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
1268
+        EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js',
1269 1269
         array('espresso_core'),
1270 1270
         EVENT_ESPRESSO_VERSION,
1271 1271
         false
Please login to merge, or discard this patch.