Completed
Branch FET/rest-relation-endpoints (00c747)
by
unknown
26:56 queued 18:24
created
core/services/request/Request.php 1 patch
Indentation   +602 added lines, -602 removed lines patch added patch discarded remove patch
@@ -17,606 +17,606 @@
 block discarded – undo
17 17
 class Request implements InterminableInterface, RequestInterface, ReservedInstanceInterface
18 18
 {
19 19
 
20
-    /**
21
-     * $_GET parameters
22
-     *
23
-     * @var array $get
24
-     */
25
-    private $get;
26
-
27
-    /**
28
-     * $_POST parameters
29
-     *
30
-     * @var array $post
31
-     */
32
-    private $post;
33
-
34
-    /**
35
-     * $_COOKIE parameters
36
-     *
37
-     * @var array $cookie
38
-     */
39
-    private $cookie;
40
-
41
-    /**
42
-     * $_SERVER parameters
43
-     *
44
-     * @var array $server
45
-     */
46
-    private $server;
47
-
48
-    /**
49
-     * $_REQUEST parameters
50
-     *
51
-     * @var array $request
52
-     */
53
-    private $request;
54
-
55
-    /**
56
-     * @var RequestTypeContextCheckerInterface
57
-     */
58
-    private $request_type;
59
-
60
-    /**
61
-     * IP address for request
62
-     *
63
-     * @var string $ip_address
64
-     */
65
-    private $ip_address;
66
-
67
-    /**
68
-     * @var string $user_agent
69
-     */
70
-    private $user_agent;
71
-
72
-    /**
73
-     * true if current user appears to be some kind of bot
74
-     *
75
-     * @var bool $is_bot
76
-     */
77
-    private $is_bot;
78
-
79
-
80
-    /**
81
-     * @param array $get
82
-     * @param array $post
83
-     * @param array $cookie
84
-     * @param array $server
85
-     */
86
-    public function __construct(array $get, array $post, array $cookie, array $server)
87
-    {
88
-        // grab request vars
89
-        $this->get = $get;
90
-        $this->post = $post;
91
-        $this->cookie = $cookie;
92
-        $this->server = $server;
93
-        $this->request = array_merge($this->get, $this->post);
94
-        $this->ip_address = $this->visitorIp();
95
-    }
96
-
97
-
98
-    /**
99
-     * @param RequestTypeContextCheckerInterface $type
100
-     */
101
-    public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type)
102
-    {
103
-        $this->request_type = $type;
104
-    }
105
-
106
-
107
-    /**
108
-     * @return array
109
-     */
110
-    public function getParams()
111
-    {
112
-        return $this->get;
113
-    }
114
-
115
-
116
-    /**
117
-     * @return array
118
-     */
119
-    public function postParams()
120
-    {
121
-        return $this->post;
122
-    }
123
-
124
-
125
-    /**
126
-     * @return array
127
-     */
128
-    public function cookieParams()
129
-    {
130
-        return $this->cookie;
131
-    }
132
-
133
-
134
-    /**
135
-     * @return array
136
-     */
137
-    public function serverParams()
138
-    {
139
-        return $this->server;
140
-    }
141
-
142
-
143
-    /**
144
-     * returns contents of $_REQUEST
145
-     *
146
-     * @return array
147
-     */
148
-    public function requestParams()
149
-    {
150
-        return $this->request;
151
-    }
152
-
153
-
154
-    /**
155
-     * @param      $key
156
-     * @param      $value
157
-     * @param bool $override_ee
158
-     * @return    void
159
-     */
160
-    public function setRequestParam($key, $value, $override_ee = false)
161
-    {
162
-        // don't allow "ee" to be overwritten unless explicitly instructed to do so
163
-        if ($key !== 'ee'
164
-            || ($key === 'ee' && empty($this->request['ee']))
165
-            || ($key === 'ee' && ! empty($this->request['ee']) && $override_ee)
166
-        ) {
167
-            $this->request[ $key ] = $value;
168
-        }
169
-    }
170
-
171
-
172
-    /**
173
-     * returns   the value for a request param if the given key exists
174
-     *
175
-     * @param       $key
176
-     * @param null  $default
177
-     * @return mixed
178
-     */
179
-    public function getRequestParam($key, $default = null)
180
-    {
181
-        return $this->requestParameterDrillDown($key, $default, 'get');
182
-    }
183
-
184
-
185
-    /**
186
-     * check if param exists
187
-     *
188
-     * @param       $key
189
-     * @return bool
190
-     */
191
-    public function requestParamIsSet($key)
192
-    {
193
-        return $this->requestParameterDrillDown($key);
194
-    }
195
-
196
-
197
-    /**
198
-     * check if a request parameter exists whose key that matches the supplied wildcard pattern
199
-     * and return the value for the first match found
200
-     * wildcards can be either of the following:
201
-     *      ? to represent a single character of any type
202
-     *      * to represent one or more characters of any type
203
-     *
204
-     * @param string     $pattern
205
-     * @param null|mixed $default
206
-     * @return mixed
207
-     */
208
-    public function getMatch($pattern, $default = null)
209
-    {
210
-        return $this->requestParameterDrillDown($pattern, $default, 'match');
211
-    }
212
-
213
-
214
-    /**
215
-     * check if a request parameter exists whose key matches the supplied wildcard pattern
216
-     * wildcards can be either of the following:
217
-     *      ? to represent a single character of any type
218
-     *      * to represent one or more characters of any type
219
-     * returns true if a match is found or false if not
220
-     *
221
-     * @param string $pattern
222
-     * @return bool
223
-     */
224
-    public function matches($pattern)
225
-    {
226
-        return $this->requestParameterDrillDown($pattern, null, 'match') !== null;
227
-    }
228
-
229
-
230
-    /**
231
-     * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard
232
-     * @param string $pattern               A string including wildcards to be converted to a regex pattern
233
-     *                                      and used to search through the current request's parameter keys
234
-     * @param array  $request_params        The array of request parameters to search through
235
-     * @param mixed  $default               [optional] The value to be returned if no match is found.
236
-     *                                      Default is null
237
-     * @param string $return                [optional] Controls what kind of value is returned.
238
-     *                                      Options are:
239
-     *                                      'bool' will return true or false if match is found or not
240
-     *                                      'key' will return the first key found that matches the supplied pattern
241
-     *                                      'value' will return the value for the first request parameter
242
-     *                                      whose key matches the supplied pattern
243
-     *                                      Default is 'value'
244
-     * @return boolean|string
245
-     */
246
-    private function match($pattern, array $request_params, $default = null, $return = 'value')
247
-    {
248
-        $return = in_array($return, array('bool', 'key', 'value'), true)
249
-            ? $return
250
-            : 'is_set';
251
-        // replace wildcard chars with regex chars
252
-        $pattern = str_replace(
253
-            array("\*", "\?"),
254
-            array('.*', '.'),
255
-            preg_quote($pattern, '/')
256
-        );
257
-        foreach ($request_params as $key => $request_param) {
258
-            if (preg_match('/^' . $pattern . '$/is', $key)) {
259
-                // return value for request param
260
-                if ($return === 'value') {
261
-                    return $request_params[ $key ];
262
-                }
263
-                // or actual key or true just to indicate it was found
264
-                return $return === 'key' ? $key : true;
265
-            }
266
-        }
267
-        // match not found so return default value or false
268
-        return $return === 'value' ? $default : false;
269
-    }
270
-
271
-
272
-    /**
273
-     * the supplied key can be a simple string to represent a "top-level" request parameter
274
-     * or represent a key for a request parameter that is nested deeper within the request parameter array,
275
-     * by using square brackets to surround keys for deeper array elements.
276
-     * For example :
277
-     * if the supplied $key was: "first[second][third]"
278
-     * then this will attempt to drill down into the request parameter array to find a value.
279
-     * Given the following request parameters:
280
-     *  array(
281
-     *      'first' => array(
282
-     *          'second' => array(
283
-     *              'third' => 'has a value'
284
-     *          )
285
-     *      )
286
-     *  )
287
-     * would return true if default parameters were set
288
-     *
289
-     * @param string $callback
290
-     * @param        $key
291
-     * @param null   $default
292
-     * @param array  $request_params
293
-     * @return bool|mixed|null
294
-     */
295
-    private function requestParameterDrillDown(
296
-        $key,
297
-        $default = null,
298
-        $callback = 'is_set',
299
-        array $request_params = array()
300
-    ) {
301
-        $callback = in_array($callback, array('is_set', 'get', 'match'), true)
302
-            ? $callback
303
-            : 'is_set';
304
-        $request_params = ! empty($request_params)
305
-            ? $request_params
306
-            : $this->request;
307
-        // does incoming key represent an array like 'first[second][third]'  ?
308
-        if (strpos($key, '[') !== false) {
309
-            // turn it into an actual array
310
-            $key = str_replace(']', '', $key);
311
-            $keys = explode('[', $key);
312
-            $key = array_shift($keys);
313
-            if ($callback === 'match') {
314
-                $real_key = $this->match($key, $request_params, $default, 'key');
315
-                $key = $real_key ? $real_key : $key;
316
-            }
317
-            // check if top level key exists
318
-            if (isset($request_params[ $key ])) {
319
-                // build a new key to pass along like: 'second[third]'
320
-                // or just 'second' depending on depth of keys
321
-                $key_string = array_shift($keys);
322
-                if (! empty($keys)) {
323
-                    $key_string .= '[' . implode('][', $keys) . ']';
324
-                }
325
-                return $this->requestParameterDrillDown(
326
-                    $key_string,
327
-                    $default,
328
-                    $callback,
329
-                    $request_params[ $key ]
330
-                );
331
-            }
332
-        }
333
-        if ($callback === 'is_set') {
334
-            return isset($request_params[ $key ]);
335
-        }
336
-        if ($callback === 'match') {
337
-            return $this->match($key, $request_params, $default);
338
-        }
339
-        return isset($request_params[ $key ])
340
-            ? $request_params[ $key ]
341
-            : $default;
342
-    }
343
-
344
-
345
-    /**
346
-     * remove param
347
-     *
348
-     * @param      $key
349
-     * @param bool $unset_from_global_too
350
-     */
351
-    public function unSetRequestParam($key, $unset_from_global_too = false)
352
-    {
353
-        unset($this->request[ $key ]);
354
-        if ($unset_from_global_too) {
355
-            unset($_REQUEST[ $key ]);
356
-        }
357
-    }
358
-
359
-
360
-    /**
361
-     * @return string
362
-     */
363
-    public function ipAddress()
364
-    {
365
-        return $this->ip_address;
366
-    }
367
-
368
-
369
-    /**
370
-     * attempt to get IP address of current visitor from server
371
-     * plz see: http://stackoverflow.com/a/2031935/1475279
372
-     *
373
-     * @access public
374
-     * @return string
375
-     */
376
-    private function visitorIp()
377
-    {
378
-        $visitor_ip = '0.0.0.0';
379
-        $server_keys = array(
380
-            'HTTP_CLIENT_IP',
381
-            'HTTP_X_FORWARDED_FOR',
382
-            'HTTP_X_FORWARDED',
383
-            'HTTP_X_CLUSTER_CLIENT_IP',
384
-            'HTTP_FORWARDED_FOR',
385
-            'HTTP_FORWARDED',
386
-            'REMOTE_ADDR',
387
-        );
388
-        foreach ($server_keys as $key) {
389
-            if (isset($this->server[ $key ])) {
390
-                foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) {
391
-                    if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
392
-                        $visitor_ip = $ip;
393
-                    }
394
-                }
395
-            }
396
-        }
397
-        return $visitor_ip;
398
-    }
399
-
400
-
401
-    /**
402
-     * @return string
403
-     */
404
-    public function requestUri()
405
-    {
406
-        $request_uri = filter_input(
407
-            INPUT_SERVER,
408
-            'REQUEST_URI',
409
-            FILTER_SANITIZE_URL,
410
-            FILTER_NULL_ON_FAILURE
411
-        );
412
-        if (empty($request_uri)) {
413
-            // fallback sanitization if the above fails
414
-            $request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']);
415
-        }
416
-        return $request_uri;
417
-    }
418
-
419
-
420
-    /**
421
-     * @return string
422
-     */
423
-    public function userAgent()
424
-    {
425
-        return $this->user_agent;
426
-    }
427
-
428
-
429
-    /**
430
-     * @param string $user_agent
431
-     */
432
-    public function setUserAgent($user_agent = '')
433
-    {
434
-        if ($user_agent === '' || ! is_string($user_agent)) {
435
-            $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : '';
436
-        }
437
-        $this->user_agent = $user_agent;
438
-    }
439
-
440
-
441
-    /**
442
-     * @return bool
443
-     */
444
-    public function isBot()
445
-    {
446
-        return $this->is_bot;
447
-    }
448
-
449
-
450
-    /**
451
-     * @param bool $is_bot
452
-     */
453
-    public function setIsBot($is_bot)
454
-    {
455
-        $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN);
456
-    }
457
-
458
-
459
-    /**
460
-     * @return bool
461
-     */
462
-    public function isActivation()
463
-    {
464
-        return $this->request_type->isActivation();
465
-    }
466
-
467
-
468
-    /**
469
-     * @param $is_activation
470
-     * @return bool
471
-     */
472
-    public function setIsActivation($is_activation)
473
-    {
474
-        return $this->request_type->setIsActivation($is_activation);
475
-    }
476
-
477
-
478
-    /**
479
-     * @return bool
480
-     */
481
-    public function isAdmin()
482
-    {
483
-        return $this->request_type->isAdmin();
484
-    }
485
-
486
-
487
-    /**
488
-     * @return bool
489
-     */
490
-    public function isAdminAjax()
491
-    {
492
-        return $this->request_type->isAdminAjax();
493
-    }
494
-
495
-
496
-    /**
497
-     * @return bool
498
-     */
499
-    public function isAjax()
500
-    {
501
-        return $this->request_type->isAjax();
502
-    }
503
-
504
-
505
-    /**
506
-     * @return bool
507
-     */
508
-    public function isEeAjax()
509
-    {
510
-        return $this->request_type->isEeAjax();
511
-    }
512
-
513
-
514
-    /**
515
-     * @return bool
516
-     */
517
-    public function isOtherAjax()
518
-    {
519
-        return $this->request_type->isOtherAjax();
520
-    }
521
-
522
-
523
-    /**
524
-     * @return bool
525
-     */
526
-    public function isApi()
527
-    {
528
-        return $this->request_type->isApi();
529
-    }
530
-
531
-
532
-    /**
533
-     * @return bool
534
-     */
535
-    public function isCli()
536
-    {
537
-        return $this->request_type->isCli();
538
-    }
539
-
540
-
541
-    /**
542
-     * @return bool
543
-     */
544
-    public function isCron()
545
-    {
546
-        return $this->request_type->isCron();
547
-    }
548
-
549
-
550
-    /**
551
-     * @return bool
552
-     */
553
-    public function isFeed()
554
-    {
555
-        return $this->request_type->isFeed();
556
-    }
557
-
558
-
559
-    /**
560
-     * @return bool
561
-     */
562
-    public function isFrontend()
563
-    {
564
-        return $this->request_type->isFrontend();
565
-    }
566
-
567
-
568
-    /**
569
-     * @return bool
570
-     */
571
-    public function isFrontAjax()
572
-    {
573
-        return $this->request_type->isFrontAjax();
574
-    }
575
-
576
-
577
-    /**
578
-     * @return bool
579
-     */
580
-    public function isIframe()
581
-    {
582
-        return $this->request_type->isIframe();
583
-    }
584
-
585
-
586
-    /**
587
-     * @return bool
588
-     */
589
-    public function isWordPressApi()
590
-    {
591
-        return $this->request_type->isWordPressApi();
592
-    }
593
-
594
-
595
-
596
-    /**
597
-     * @return bool
598
-     */
599
-    public function isWordPressHeartbeat()
600
-    {
601
-        return $this->request_type->isWordPressHeartbeat();
602
-    }
603
-
604
-
605
-
606
-    /**
607
-     * @return bool
608
-     */
609
-    public function isWordPressScrape()
610
-    {
611
-        return $this->request_type->isWordPressScrape();
612
-    }
613
-
614
-
615
-    /**
616
-     * @return string
617
-     */
618
-    public function slug()
619
-    {
620
-        return $this->request_type->slug();
621
-    }
20
+	/**
21
+	 * $_GET parameters
22
+	 *
23
+	 * @var array $get
24
+	 */
25
+	private $get;
26
+
27
+	/**
28
+	 * $_POST parameters
29
+	 *
30
+	 * @var array $post
31
+	 */
32
+	private $post;
33
+
34
+	/**
35
+	 * $_COOKIE parameters
36
+	 *
37
+	 * @var array $cookie
38
+	 */
39
+	private $cookie;
40
+
41
+	/**
42
+	 * $_SERVER parameters
43
+	 *
44
+	 * @var array $server
45
+	 */
46
+	private $server;
47
+
48
+	/**
49
+	 * $_REQUEST parameters
50
+	 *
51
+	 * @var array $request
52
+	 */
53
+	private $request;
54
+
55
+	/**
56
+	 * @var RequestTypeContextCheckerInterface
57
+	 */
58
+	private $request_type;
59
+
60
+	/**
61
+	 * IP address for request
62
+	 *
63
+	 * @var string $ip_address
64
+	 */
65
+	private $ip_address;
66
+
67
+	/**
68
+	 * @var string $user_agent
69
+	 */
70
+	private $user_agent;
71
+
72
+	/**
73
+	 * true if current user appears to be some kind of bot
74
+	 *
75
+	 * @var bool $is_bot
76
+	 */
77
+	private $is_bot;
78
+
79
+
80
+	/**
81
+	 * @param array $get
82
+	 * @param array $post
83
+	 * @param array $cookie
84
+	 * @param array $server
85
+	 */
86
+	public function __construct(array $get, array $post, array $cookie, array $server)
87
+	{
88
+		// grab request vars
89
+		$this->get = $get;
90
+		$this->post = $post;
91
+		$this->cookie = $cookie;
92
+		$this->server = $server;
93
+		$this->request = array_merge($this->get, $this->post);
94
+		$this->ip_address = $this->visitorIp();
95
+	}
96
+
97
+
98
+	/**
99
+	 * @param RequestTypeContextCheckerInterface $type
100
+	 */
101
+	public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type)
102
+	{
103
+		$this->request_type = $type;
104
+	}
105
+
106
+
107
+	/**
108
+	 * @return array
109
+	 */
110
+	public function getParams()
111
+	{
112
+		return $this->get;
113
+	}
114
+
115
+
116
+	/**
117
+	 * @return array
118
+	 */
119
+	public function postParams()
120
+	{
121
+		return $this->post;
122
+	}
123
+
124
+
125
+	/**
126
+	 * @return array
127
+	 */
128
+	public function cookieParams()
129
+	{
130
+		return $this->cookie;
131
+	}
132
+
133
+
134
+	/**
135
+	 * @return array
136
+	 */
137
+	public function serverParams()
138
+	{
139
+		return $this->server;
140
+	}
141
+
142
+
143
+	/**
144
+	 * returns contents of $_REQUEST
145
+	 *
146
+	 * @return array
147
+	 */
148
+	public function requestParams()
149
+	{
150
+		return $this->request;
151
+	}
152
+
153
+
154
+	/**
155
+	 * @param      $key
156
+	 * @param      $value
157
+	 * @param bool $override_ee
158
+	 * @return    void
159
+	 */
160
+	public function setRequestParam($key, $value, $override_ee = false)
161
+	{
162
+		// don't allow "ee" to be overwritten unless explicitly instructed to do so
163
+		if ($key !== 'ee'
164
+			|| ($key === 'ee' && empty($this->request['ee']))
165
+			|| ($key === 'ee' && ! empty($this->request['ee']) && $override_ee)
166
+		) {
167
+			$this->request[ $key ] = $value;
168
+		}
169
+	}
170
+
171
+
172
+	/**
173
+	 * returns   the value for a request param if the given key exists
174
+	 *
175
+	 * @param       $key
176
+	 * @param null  $default
177
+	 * @return mixed
178
+	 */
179
+	public function getRequestParam($key, $default = null)
180
+	{
181
+		return $this->requestParameterDrillDown($key, $default, 'get');
182
+	}
183
+
184
+
185
+	/**
186
+	 * check if param exists
187
+	 *
188
+	 * @param       $key
189
+	 * @return bool
190
+	 */
191
+	public function requestParamIsSet($key)
192
+	{
193
+		return $this->requestParameterDrillDown($key);
194
+	}
195
+
196
+
197
+	/**
198
+	 * check if a request parameter exists whose key that matches the supplied wildcard pattern
199
+	 * and return the value for the first match found
200
+	 * wildcards can be either of the following:
201
+	 *      ? to represent a single character of any type
202
+	 *      * to represent one or more characters of any type
203
+	 *
204
+	 * @param string     $pattern
205
+	 * @param null|mixed $default
206
+	 * @return mixed
207
+	 */
208
+	public function getMatch($pattern, $default = null)
209
+	{
210
+		return $this->requestParameterDrillDown($pattern, $default, 'match');
211
+	}
212
+
213
+
214
+	/**
215
+	 * check if a request parameter exists whose key matches the supplied wildcard pattern
216
+	 * wildcards can be either of the following:
217
+	 *      ? to represent a single character of any type
218
+	 *      * to represent one or more characters of any type
219
+	 * returns true if a match is found or false if not
220
+	 *
221
+	 * @param string $pattern
222
+	 * @return bool
223
+	 */
224
+	public function matches($pattern)
225
+	{
226
+		return $this->requestParameterDrillDown($pattern, null, 'match') !== null;
227
+	}
228
+
229
+
230
+	/**
231
+	 * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard
232
+	 * @param string $pattern               A string including wildcards to be converted to a regex pattern
233
+	 *                                      and used to search through the current request's parameter keys
234
+	 * @param array  $request_params        The array of request parameters to search through
235
+	 * @param mixed  $default               [optional] The value to be returned if no match is found.
236
+	 *                                      Default is null
237
+	 * @param string $return                [optional] Controls what kind of value is returned.
238
+	 *                                      Options are:
239
+	 *                                      'bool' will return true or false if match is found or not
240
+	 *                                      'key' will return the first key found that matches the supplied pattern
241
+	 *                                      'value' will return the value for the first request parameter
242
+	 *                                      whose key matches the supplied pattern
243
+	 *                                      Default is 'value'
244
+	 * @return boolean|string
245
+	 */
246
+	private function match($pattern, array $request_params, $default = null, $return = 'value')
247
+	{
248
+		$return = in_array($return, array('bool', 'key', 'value'), true)
249
+			? $return
250
+			: 'is_set';
251
+		// replace wildcard chars with regex chars
252
+		$pattern = str_replace(
253
+			array("\*", "\?"),
254
+			array('.*', '.'),
255
+			preg_quote($pattern, '/')
256
+		);
257
+		foreach ($request_params as $key => $request_param) {
258
+			if (preg_match('/^' . $pattern . '$/is', $key)) {
259
+				// return value for request param
260
+				if ($return === 'value') {
261
+					return $request_params[ $key ];
262
+				}
263
+				// or actual key or true just to indicate it was found
264
+				return $return === 'key' ? $key : true;
265
+			}
266
+		}
267
+		// match not found so return default value or false
268
+		return $return === 'value' ? $default : false;
269
+	}
270
+
271
+
272
+	/**
273
+	 * the supplied key can be a simple string to represent a "top-level" request parameter
274
+	 * or represent a key for a request parameter that is nested deeper within the request parameter array,
275
+	 * by using square brackets to surround keys for deeper array elements.
276
+	 * For example :
277
+	 * if the supplied $key was: "first[second][third]"
278
+	 * then this will attempt to drill down into the request parameter array to find a value.
279
+	 * Given the following request parameters:
280
+	 *  array(
281
+	 *      'first' => array(
282
+	 *          'second' => array(
283
+	 *              'third' => 'has a value'
284
+	 *          )
285
+	 *      )
286
+	 *  )
287
+	 * would return true if default parameters were set
288
+	 *
289
+	 * @param string $callback
290
+	 * @param        $key
291
+	 * @param null   $default
292
+	 * @param array  $request_params
293
+	 * @return bool|mixed|null
294
+	 */
295
+	private function requestParameterDrillDown(
296
+		$key,
297
+		$default = null,
298
+		$callback = 'is_set',
299
+		array $request_params = array()
300
+	) {
301
+		$callback = in_array($callback, array('is_set', 'get', 'match'), true)
302
+			? $callback
303
+			: 'is_set';
304
+		$request_params = ! empty($request_params)
305
+			? $request_params
306
+			: $this->request;
307
+		// does incoming key represent an array like 'first[second][third]'  ?
308
+		if (strpos($key, '[') !== false) {
309
+			// turn it into an actual array
310
+			$key = str_replace(']', '', $key);
311
+			$keys = explode('[', $key);
312
+			$key = array_shift($keys);
313
+			if ($callback === 'match') {
314
+				$real_key = $this->match($key, $request_params, $default, 'key');
315
+				$key = $real_key ? $real_key : $key;
316
+			}
317
+			// check if top level key exists
318
+			if (isset($request_params[ $key ])) {
319
+				// build a new key to pass along like: 'second[third]'
320
+				// or just 'second' depending on depth of keys
321
+				$key_string = array_shift($keys);
322
+				if (! empty($keys)) {
323
+					$key_string .= '[' . implode('][', $keys) . ']';
324
+				}
325
+				return $this->requestParameterDrillDown(
326
+					$key_string,
327
+					$default,
328
+					$callback,
329
+					$request_params[ $key ]
330
+				);
331
+			}
332
+		}
333
+		if ($callback === 'is_set') {
334
+			return isset($request_params[ $key ]);
335
+		}
336
+		if ($callback === 'match') {
337
+			return $this->match($key, $request_params, $default);
338
+		}
339
+		return isset($request_params[ $key ])
340
+			? $request_params[ $key ]
341
+			: $default;
342
+	}
343
+
344
+
345
+	/**
346
+	 * remove param
347
+	 *
348
+	 * @param      $key
349
+	 * @param bool $unset_from_global_too
350
+	 */
351
+	public function unSetRequestParam($key, $unset_from_global_too = false)
352
+	{
353
+		unset($this->request[ $key ]);
354
+		if ($unset_from_global_too) {
355
+			unset($_REQUEST[ $key ]);
356
+		}
357
+	}
358
+
359
+
360
+	/**
361
+	 * @return string
362
+	 */
363
+	public function ipAddress()
364
+	{
365
+		return $this->ip_address;
366
+	}
367
+
368
+
369
+	/**
370
+	 * attempt to get IP address of current visitor from server
371
+	 * plz see: http://stackoverflow.com/a/2031935/1475279
372
+	 *
373
+	 * @access public
374
+	 * @return string
375
+	 */
376
+	private function visitorIp()
377
+	{
378
+		$visitor_ip = '0.0.0.0';
379
+		$server_keys = array(
380
+			'HTTP_CLIENT_IP',
381
+			'HTTP_X_FORWARDED_FOR',
382
+			'HTTP_X_FORWARDED',
383
+			'HTTP_X_CLUSTER_CLIENT_IP',
384
+			'HTTP_FORWARDED_FOR',
385
+			'HTTP_FORWARDED',
386
+			'REMOTE_ADDR',
387
+		);
388
+		foreach ($server_keys as $key) {
389
+			if (isset($this->server[ $key ])) {
390
+				foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) {
391
+					if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) {
392
+						$visitor_ip = $ip;
393
+					}
394
+				}
395
+			}
396
+		}
397
+		return $visitor_ip;
398
+	}
399
+
400
+
401
+	/**
402
+	 * @return string
403
+	 */
404
+	public function requestUri()
405
+	{
406
+		$request_uri = filter_input(
407
+			INPUT_SERVER,
408
+			'REQUEST_URI',
409
+			FILTER_SANITIZE_URL,
410
+			FILTER_NULL_ON_FAILURE
411
+		);
412
+		if (empty($request_uri)) {
413
+			// fallback sanitization if the above fails
414
+			$request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']);
415
+		}
416
+		return $request_uri;
417
+	}
418
+
419
+
420
+	/**
421
+	 * @return string
422
+	 */
423
+	public function userAgent()
424
+	{
425
+		return $this->user_agent;
426
+	}
427
+
428
+
429
+	/**
430
+	 * @param string $user_agent
431
+	 */
432
+	public function setUserAgent($user_agent = '')
433
+	{
434
+		if ($user_agent === '' || ! is_string($user_agent)) {
435
+			$user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : '';
436
+		}
437
+		$this->user_agent = $user_agent;
438
+	}
439
+
440
+
441
+	/**
442
+	 * @return bool
443
+	 */
444
+	public function isBot()
445
+	{
446
+		return $this->is_bot;
447
+	}
448
+
449
+
450
+	/**
451
+	 * @param bool $is_bot
452
+	 */
453
+	public function setIsBot($is_bot)
454
+	{
455
+		$this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN);
456
+	}
457
+
458
+
459
+	/**
460
+	 * @return bool
461
+	 */
462
+	public function isActivation()
463
+	{
464
+		return $this->request_type->isActivation();
465
+	}
466
+
467
+
468
+	/**
469
+	 * @param $is_activation
470
+	 * @return bool
471
+	 */
472
+	public function setIsActivation($is_activation)
473
+	{
474
+		return $this->request_type->setIsActivation($is_activation);
475
+	}
476
+
477
+
478
+	/**
479
+	 * @return bool
480
+	 */
481
+	public function isAdmin()
482
+	{
483
+		return $this->request_type->isAdmin();
484
+	}
485
+
486
+
487
+	/**
488
+	 * @return bool
489
+	 */
490
+	public function isAdminAjax()
491
+	{
492
+		return $this->request_type->isAdminAjax();
493
+	}
494
+
495
+
496
+	/**
497
+	 * @return bool
498
+	 */
499
+	public function isAjax()
500
+	{
501
+		return $this->request_type->isAjax();
502
+	}
503
+
504
+
505
+	/**
506
+	 * @return bool
507
+	 */
508
+	public function isEeAjax()
509
+	{
510
+		return $this->request_type->isEeAjax();
511
+	}
512
+
513
+
514
+	/**
515
+	 * @return bool
516
+	 */
517
+	public function isOtherAjax()
518
+	{
519
+		return $this->request_type->isOtherAjax();
520
+	}
521
+
522
+
523
+	/**
524
+	 * @return bool
525
+	 */
526
+	public function isApi()
527
+	{
528
+		return $this->request_type->isApi();
529
+	}
530
+
531
+
532
+	/**
533
+	 * @return bool
534
+	 */
535
+	public function isCli()
536
+	{
537
+		return $this->request_type->isCli();
538
+	}
539
+
540
+
541
+	/**
542
+	 * @return bool
543
+	 */
544
+	public function isCron()
545
+	{
546
+		return $this->request_type->isCron();
547
+	}
548
+
549
+
550
+	/**
551
+	 * @return bool
552
+	 */
553
+	public function isFeed()
554
+	{
555
+		return $this->request_type->isFeed();
556
+	}
557
+
558
+
559
+	/**
560
+	 * @return bool
561
+	 */
562
+	public function isFrontend()
563
+	{
564
+		return $this->request_type->isFrontend();
565
+	}
566
+
567
+
568
+	/**
569
+	 * @return bool
570
+	 */
571
+	public function isFrontAjax()
572
+	{
573
+		return $this->request_type->isFrontAjax();
574
+	}
575
+
576
+
577
+	/**
578
+	 * @return bool
579
+	 */
580
+	public function isIframe()
581
+	{
582
+		return $this->request_type->isIframe();
583
+	}
584
+
585
+
586
+	/**
587
+	 * @return bool
588
+	 */
589
+	public function isWordPressApi()
590
+	{
591
+		return $this->request_type->isWordPressApi();
592
+	}
593
+
594
+
595
+
596
+	/**
597
+	 * @return bool
598
+	 */
599
+	public function isWordPressHeartbeat()
600
+	{
601
+		return $this->request_type->isWordPressHeartbeat();
602
+	}
603
+
604
+
605
+
606
+	/**
607
+	 * @return bool
608
+	 */
609
+	public function isWordPressScrape()
610
+	{
611
+		return $this->request_type->isWordPressScrape();
612
+	}
613
+
614
+
615
+	/**
616
+	 * @return string
617
+	 */
618
+	public function slug()
619
+	{
620
+		return $this->request_type->slug();
621
+	}
622 622
 }
Please login to merge, or discard this patch.
core/domain/services/admin/ajax/WordpressHeartbeat.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -17,50 +17,50 @@
 block discarded – undo
17 17
 class WordpressHeartbeat
18 18
 {
19 19
 
20
-    /**
21
-     * @var LoaderInterface $loader
22
-     */
23
-    protected $loader;
20
+	/**
21
+	 * @var LoaderInterface $loader
22
+	 */
23
+	protected $loader;
24 24
 
25
-    /**
26
-     * @var RequestInterface $request
27
-     */
28
-    protected $request;
25
+	/**
26
+	 * @var RequestInterface $request
27
+	 */
28
+	protected $request;
29 29
 
30 30
 
31
-    /**
32
-     * WordpressHeartbeat constructor.
33
-     *
34
-     * @param LoaderInterface  $loader
35
-     * @param RequestInterface $request
36
-     */
37
-    public function __construct(
38
-        LoaderInterface $loader,
39
-        RequestInterface $request
40
-    ) {
41
-        $this->loader = $loader;
42
-        $this->request = $request;
43
-        do_action('AHEE__EventEspresso_core_domain_services_admin_ajax_WordpressHeartbeat__constructor', $this);
44
-        add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'resolveRoutes'));
45
-    }
31
+	/**
32
+	 * WordpressHeartbeat constructor.
33
+	 *
34
+	 * @param LoaderInterface  $loader
35
+	 * @param RequestInterface $request
36
+	 */
37
+	public function __construct(
38
+		LoaderInterface $loader,
39
+		RequestInterface $request
40
+	) {
41
+		$this->loader = $loader;
42
+		$this->request = $request;
43
+		do_action('AHEE__EventEspresso_core_domain_services_admin_ajax_WordpressHeartbeat__constructor', $this);
44
+		add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'resolveRoutes'));
45
+	}
46 46
 
47 47
 
48
-    /**
49
-     * @since $VID:$
50
-     * @throws InvalidClassException
51
-     */
52
-    public function resolveRoutes()
53
-    {
54
-        $screenID = $this->request->getRequestParam('screen_id');
55
-        $heartbeat_data = $this->request->getRequestParam('data', []);
56
-        if ($screenID === 'espresso_events') {
57
-            $this->loader->getShared(
58
-                'EventEspresso\core\domain\services\admin\ajax\EventEditorHeartbeat'
59
-            );
60
-        } elseif ($screenID === 'front' && ! empty($heartbeat_data['espresso_thank_you_page'])) {
61
-            $this->loader->getShared(
62
-                'EventEspresso\core\domain\services\admin\ajax\ThankYouPageIpnMonitor'
63
-            );
64
-        }
65
-    }
48
+	/**
49
+	 * @since $VID:$
50
+	 * @throws InvalidClassException
51
+	 */
52
+	public function resolveRoutes()
53
+	{
54
+		$screenID = $this->request->getRequestParam('screen_id');
55
+		$heartbeat_data = $this->request->getRequestParam('data', []);
56
+		if ($screenID === 'espresso_events') {
57
+			$this->loader->getShared(
58
+				'EventEspresso\core\domain\services\admin\ajax\EventEditorHeartbeat'
59
+			);
60
+		} elseif ($screenID === 'front' && ! empty($heartbeat_data['espresso_thank_you_page'])) {
61
+			$this->loader->getShared(
62
+				'EventEspresso\core\domain\services\admin\ajax\ThankYouPageIpnMonitor'
63
+			);
64
+		}
65
+	}
66 66
 }
Please login to merge, or discard this patch.
core/domain/services/admin/ajax/EventEditorHeartbeat.php 2 patches
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -16,52 +16,52 @@
 block discarded – undo
16 16
 class EventEditorHeartbeat
17 17
 {
18 18
 
19
-    /**
20
-     * @var Domain $domain
21
-     */
22
-    protected $domain;
19
+	/**
20
+	 * @var Domain $domain
21
+	 */
22
+	protected $domain;
23 23
 
24
-    /**
25
-     * @var EE_Environment_Config $environment
26
-     */
27
-    protected $environment;
24
+	/**
25
+	 * @var EE_Environment_Config $environment
26
+	 */
27
+	protected $environment;
28 28
 
29 29
 
30
-    /**
31
-     * EventEditorHeartbeat constructor.
32
-     *
33
-     * @param Domain                $domain
34
-     * @param EE_Environment_Config $environment
35
-     */
36
-    public function __construct(Domain $domain, EE_Environment_Config $environment)
37
-    {
38
-        $this->domain = $domain;
39
-        $this->environment = $environment;
40
-        if ($this->domain->isCaffeinated()) {
41
-            add_filter('heartbeat_received', array($this, 'heartbeatResponse'), 10, 2);
42
-        }
43
-    }
30
+	/**
31
+	 * EventEditorHeartbeat constructor.
32
+	 *
33
+	 * @param Domain                $domain
34
+	 * @param EE_Environment_Config $environment
35
+	 */
36
+	public function __construct(Domain $domain, EE_Environment_Config $environment)
37
+	{
38
+		$this->domain = $domain;
39
+		$this->environment = $environment;
40
+		if ($this->domain->isCaffeinated()) {
41
+			add_filter('heartbeat_received', array($this, 'heartbeatResponse'), 10, 2);
42
+		}
43
+	}
44 44
 
45 45
 
46
-    /**
47
-     * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle
48
-     * accordingly.
49
-     *
50
-     * @param array $response The existing heartbeat response array.
51
-     * @param array $data     The incoming data package.
52
-     * @return array  possibly appended response.
53
-     */
54
-    public function heartbeatResponse($response, $data)
55
-    {
56
-        /**
57
-         * check whether count of tickets is approaching the potential
58
-         * limits for the server.
59
-         */
60
-        if (! empty($data['input_count'])) {
61
-            $response['max_input_vars_check'] = $this->environment->max_input_vars_limit_check(
62
-                $data['input_count']
63
-            );
64
-        }
65
-        return $response;
66
-    }
46
+	/**
47
+	 * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle
48
+	 * accordingly.
49
+	 *
50
+	 * @param array $response The existing heartbeat response array.
51
+	 * @param array $data     The incoming data package.
52
+	 * @return array  possibly appended response.
53
+	 */
54
+	public function heartbeatResponse($response, $data)
55
+	{
56
+		/**
57
+		 * check whether count of tickets is approaching the potential
58
+		 * limits for the server.
59
+		 */
60
+		if (! empty($data['input_count'])) {
61
+			$response['max_input_vars_check'] = $this->environment->max_input_vars_limit_check(
62
+				$data['input_count']
63
+			);
64
+		}
65
+		return $response;
66
+	}
67 67
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@
 block discarded – undo
57 57
          * check whether count of tickets is approaching the potential
58 58
          * limits for the server.
59 59
          */
60
-        if (! empty($data['input_count'])) {
60
+        if ( ! empty($data['input_count'])) {
61 61
             $response['max_input_vars_check'] = $this->environment->max_input_vars_limit_check(
62 62
                 $data['input_count']
63 63
             );
Please login to merge, or discard this patch.
core/domain/services/admin/ajax/ThankYouPageIpnMonitor.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -59,11 +59,11 @@  discard block
 block discarded – undo
59 59
     public function heartbeatResponse($response = array(), $data = array())
60 60
     {
61 61
         // does this heartbeat contain our data ?
62
-        if (! isset($data['espresso_thank_you_page'])) {
62
+        if ( ! isset($data['espresso_thank_you_page'])) {
63 63
             return $response;
64 64
         }
65 65
         // check for reg_url_link in the incoming heartbeat data
66
-        if (! isset($data['espresso_thank_you_page']['e_reg_url_link'])) {
66
+        if ( ! isset($data['espresso_thank_you_page']['e_reg_url_link'])) {
67 67
             $response['espresso_thank_you_page'] = array(
68 68
                 'errors' => ! empty($notices['errors'])
69 69
                     ? $notices['errors']
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
      */
110 110
     private function initializeThankYouPageAndTransaction($response, $data)
111 111
     {
112
-        require_once EE_MODULES . 'thank_you_page/EED_Thank_You_Page.module.php';
112
+        require_once EE_MODULES.'thank_you_page/EED_Thank_You_Page.module.php';
113 113
         // set_definitions, instantiate the thank you page class, and get the ball rolling
114 114
         EED_Thank_You_Page::set_definitions();
115 115
         $this->thank_you_page = EED_Thank_You_Page::instance();
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
         // get TXN
120 120
         $transaction = $this->thank_you_page->get_txn();
121 121
         // no TXN? then get out
122
-        if (! $transaction instanceof EE_Transaction) {
122
+        if ( ! $transaction instanceof EE_Transaction) {
123 123
             $notices = EE_Error::get_notices();
124 124
             $response['espresso_thank_you_page'] = array(
125 125
                 'errors' => ! empty($notices['errors'])
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
         // then check for payments
187 187
         $payments = $this->thank_you_page->get_txn_payments($since);
188 188
         // has a payment been processed ?
189
-        if (! empty($payments) || $this->thank_you_page->isOfflinePaymentMethod()) {
189
+        if ( ! empty($payments) || $this->thank_you_page->isOfflinePaymentMethod()) {
190 190
             if ($since) {
191 191
                 $response['espresso_thank_you_page'] = array(
192 192
                     'new_payments'        => $this->thank_you_page->get_new_payments($payments),
Please login to merge, or discard this patch.
Indentation   +202 added lines, -202 removed lines patch added patch discarded remove patch
@@ -21,206 +21,206 @@
 block discarded – undo
21 21
 class ThankYouPageIpnMonitor
22 22
 {
23 23
 
24
-    /**
25
-     * @var EED_Thank_You_Page $thank_you_page
26
-     */
27
-    private $thank_you_page;
28
-
29
-    /**
30
-     * @var EE_Transaction $transaction
31
-     */
32
-    private $transaction;
33
-
34
-
35
-    /**
36
-     * EventEditorHeartbeat constructor.
37
-     */
38
-    public function __construct()
39
-    {
40
-        add_filter('heartbeat_received', array($this, 'heartbeatResponse'), 10, 3);
41
-        add_filter('heartbeat_nopriv_received', array($this, 'heartbeatResponse'), 10, 3);
42
-    }
43
-
44
-
45
-    /**
46
-     * thank_you_page_IPN_monitor
47
-     * this basically just pulls the TXN based on the reg_url_link sent from the server,
48
-     * then checks that the TXN status is not failed, and that no other errors have been generated.
49
-     * it also calculates the IPN wait time since the Thank You page was first loaded
50
-     *
51
-     * @param array $response
52
-     * @param array $data
53
-     * @return array
54
-     * @throws EE_Error
55
-     * @throws InvalidDataTypeException
56
-     * @throws InvalidInterfaceException
57
-     * @throws InvalidArgumentException
58
-     */
59
-    public function heartbeatResponse($response = array(), $data = array())
60
-    {
61
-        // does this heartbeat contain our data ?
62
-        if (! isset($data['espresso_thank_you_page'])) {
63
-            return $response;
64
-        }
65
-        // check for reg_url_link in the incoming heartbeat data
66
-        if (! isset($data['espresso_thank_you_page']['e_reg_url_link'])) {
67
-            $response['espresso_thank_you_page'] = array(
68
-                'errors' => ! empty($notices['errors'])
69
-                    ? $notices['errors']
70
-                    : __(
71
-                        'No transaction information could be retrieved because the registration URL link is missing or invalid.',
72
-                        'event_espresso'
73
-                    ),
74
-            );
75
-            return $response;
76
-        }
77
-        // kk heartbeat has our data
78
-        $response = $this->initializeThankYouPageAndTransaction($response, $data);
79
-        // if something went wrong...
80
-        if (isset($response['espresso_thank_you_page']['errors'])) {
81
-            return $response;
82
-        }
83
-        // grab transient of Transaction's status
84
-        $txn_status = isset($data['espresso_thank_you_page']['txn_status'])
85
-            ? $data['espresso_thank_you_page']['txn_status']
86
-            : null;
87
-        $response = $this->getTransactionDetails($txn_status, $response, $data);
88
-        // no payment data yet?
89
-        if (isset($response['espresso_thank_you_page']['still_waiting'])) {
90
-            return $response;
91
-        }
92
-        // TXN is happening so let's get the payments now
93
-        // if we've already gotten payments then the heartbeat data will contain the timestamp of the last time we checked
94
-        $since = isset($data['espresso_thank_you_page']['get_payments_since'])
95
-            ? $data['espresso_thank_you_page']['get_payments_since']
96
-            : 0;
97
-        return $this->paymentDetails($since);
98
-    }
99
-
100
-
101
-    /**
102
-     * @param array $response
103
-     * @param array $data
104
-     * @return array
105
-     * @throws EE_Error
106
-     * @throws InvalidArgumentException
107
-     * @throws InvalidDataTypeException
108
-     * @throws InvalidInterfaceException
109
-     */
110
-    private function initializeThankYouPageAndTransaction($response, $data)
111
-    {
112
-        require_once EE_MODULES . 'thank_you_page/EED_Thank_You_Page.module.php';
113
-        // set_definitions, instantiate the thank you page class, and get the ball rolling
114
-        EED_Thank_You_Page::set_definitions();
115
-        $this->thank_you_page = EED_Thank_You_Page::instance();
116
-        $this->thank_you_page->set_reg_url_link($data['espresso_thank_you_page']['e_reg_url_link']);
117
-        $this->thank_you_page->init();
118
-        $response['espresso_thank_you_page'] = array();
119
-        // get TXN
120
-        $transaction = $this->thank_you_page->get_txn();
121
-        // no TXN? then get out
122
-        if (! $transaction instanceof EE_Transaction) {
123
-            $notices = EE_Error::get_notices();
124
-            $response['espresso_thank_you_page'] = array(
125
-                'errors' => ! empty($notices['errors'])
126
-                    ? $notices['errors']
127
-                    : sprintf(
128
-                        __(
129
-                            'The information for your transaction could not be retrieved from the server or the transaction data received was invalid because of a technical reason. (%s)',
130
-                            'event_espresso'
131
-                        ),
132
-                        __LINE__
133
-                    ),
134
-            );
135
-            return $response;
136
-        }
137
-        $this->transaction = $transaction;
138
-        return $response;
139
-    }
140
-
141
-
142
-    /**
143
-     * @param string $txn_status
144
-     * @param array  $response
145
-     * @param array  $data
146
-     * @return array
147
-     * @throws EE_Error
148
-     */
149
-    private function getTransactionDetails($txn_status, $response, $data)
150
-    {
151
-        // has the TXN status changed since we last checked (or empty because this is the first time running through this code)?
152
-        if ($txn_status !== $this->transaction->status_ID()) {
153
-            // switch between two possible basic outcomes
154
-            switch ($this->transaction->status_ID()) {
155
-                // TXN has been updated in some way
156
-                case EEM_Transaction::overpaid_status_code:
157
-                case EEM_Transaction::complete_status_code:
158
-                case EEM_Transaction::incomplete_status_code:
159
-                    // send updated TXN results back to client,
160
-                    $response['espresso_thank_you_page'] = array(
161
-                        'transaction_details' => $this->thank_you_page->get_transaction_details(),
162
-                        'txn_status'          => $this->transaction->status_ID(),
163
-                    );
164
-                    return $response;
165
-                // or we have a bad TXN, or really slow IPN, so calculate the wait time and send that back...
166
-                case EEM_Transaction::failed_status_code:
167
-                default:
168
-                    // keep on waiting...
169
-                    return $this->updateServerWaitTime($data['espresso_thank_you_page']);
170
-            }
171
-            // or is the TXN still failed (never been updated) ???
172
-        } elseif ($this->transaction->failed()) {
173
-            // keep on waiting...
174
-            return $this->updateServerWaitTime($data['espresso_thank_you_page']);
175
-        }
176
-    }
177
-
178
-
179
-    /**
180
-     * @param int $since
181
-     * @return array
182
-     * @throws EE_Error
183
-     */
184
-    private function paymentDetails($since)
185
-    {
186
-        // then check for payments
187
-        $payments = $this->thank_you_page->get_txn_payments($since);
188
-        // has a payment been processed ?
189
-        if (! empty($payments) || $this->thank_you_page->isOfflinePaymentMethod()) {
190
-            if ($since) {
191
-                $response['espresso_thank_you_page'] = array(
192
-                    'new_payments'        => $this->thank_you_page->get_new_payments($payments),
193
-                    'transaction_details' => $this->thank_you_page->get_transaction_details(),
194
-                    'txn_status'          => $this->transaction->status_ID(),
195
-                );
196
-            } else {
197
-                $response['espresso_thank_you_page']['payment_details'] = $this->thank_you_page->get_payment_details(
198
-                    $payments
199
-                );
200
-            }
201
-            // reset time to check for payments
202
-            $response['espresso_thank_you_page']['get_payments_since'] = time();
203
-        } else {
204
-            $response['espresso_thank_you_page']['get_payments_since'] = $since;
205
-        }
206
-        return $response;
207
-    }
208
-
209
-
210
-    /**
211
-     * @param array $thank_you_page_data    thank you page portion of the incoming JSON array
212
-     *                                      from the WP heartbeat data
213
-     * @return array
214
-     * @throws EE_Error
215
-     */
216
-    private function updateServerWaitTime($thank_you_page_data)
217
-    {
218
-        $response['espresso_thank_you_page'] = array(
219
-            'still_waiting' => isset($thank_you_page_data['initial_access'])
220
-                ? time() - $thank_you_page_data['initial_access']
221
-                : 0,
222
-            'txn_status'    => $this->transaction->status_ID(),
223
-        );
224
-        return $response;
225
-    }
24
+	/**
25
+	 * @var EED_Thank_You_Page $thank_you_page
26
+	 */
27
+	private $thank_you_page;
28
+
29
+	/**
30
+	 * @var EE_Transaction $transaction
31
+	 */
32
+	private $transaction;
33
+
34
+
35
+	/**
36
+	 * EventEditorHeartbeat constructor.
37
+	 */
38
+	public function __construct()
39
+	{
40
+		add_filter('heartbeat_received', array($this, 'heartbeatResponse'), 10, 3);
41
+		add_filter('heartbeat_nopriv_received', array($this, 'heartbeatResponse'), 10, 3);
42
+	}
43
+
44
+
45
+	/**
46
+	 * thank_you_page_IPN_monitor
47
+	 * this basically just pulls the TXN based on the reg_url_link sent from the server,
48
+	 * then checks that the TXN status is not failed, and that no other errors have been generated.
49
+	 * it also calculates the IPN wait time since the Thank You page was first loaded
50
+	 *
51
+	 * @param array $response
52
+	 * @param array $data
53
+	 * @return array
54
+	 * @throws EE_Error
55
+	 * @throws InvalidDataTypeException
56
+	 * @throws InvalidInterfaceException
57
+	 * @throws InvalidArgumentException
58
+	 */
59
+	public function heartbeatResponse($response = array(), $data = array())
60
+	{
61
+		// does this heartbeat contain our data ?
62
+		if (! isset($data['espresso_thank_you_page'])) {
63
+			return $response;
64
+		}
65
+		// check for reg_url_link in the incoming heartbeat data
66
+		if (! isset($data['espresso_thank_you_page']['e_reg_url_link'])) {
67
+			$response['espresso_thank_you_page'] = array(
68
+				'errors' => ! empty($notices['errors'])
69
+					? $notices['errors']
70
+					: __(
71
+						'No transaction information could be retrieved because the registration URL link is missing or invalid.',
72
+						'event_espresso'
73
+					),
74
+			);
75
+			return $response;
76
+		}
77
+		// kk heartbeat has our data
78
+		$response = $this->initializeThankYouPageAndTransaction($response, $data);
79
+		// if something went wrong...
80
+		if (isset($response['espresso_thank_you_page']['errors'])) {
81
+			return $response;
82
+		}
83
+		// grab transient of Transaction's status
84
+		$txn_status = isset($data['espresso_thank_you_page']['txn_status'])
85
+			? $data['espresso_thank_you_page']['txn_status']
86
+			: null;
87
+		$response = $this->getTransactionDetails($txn_status, $response, $data);
88
+		// no payment data yet?
89
+		if (isset($response['espresso_thank_you_page']['still_waiting'])) {
90
+			return $response;
91
+		}
92
+		// TXN is happening so let's get the payments now
93
+		// if we've already gotten payments then the heartbeat data will contain the timestamp of the last time we checked
94
+		$since = isset($data['espresso_thank_you_page']['get_payments_since'])
95
+			? $data['espresso_thank_you_page']['get_payments_since']
96
+			: 0;
97
+		return $this->paymentDetails($since);
98
+	}
99
+
100
+
101
+	/**
102
+	 * @param array $response
103
+	 * @param array $data
104
+	 * @return array
105
+	 * @throws EE_Error
106
+	 * @throws InvalidArgumentException
107
+	 * @throws InvalidDataTypeException
108
+	 * @throws InvalidInterfaceException
109
+	 */
110
+	private function initializeThankYouPageAndTransaction($response, $data)
111
+	{
112
+		require_once EE_MODULES . 'thank_you_page/EED_Thank_You_Page.module.php';
113
+		// set_definitions, instantiate the thank you page class, and get the ball rolling
114
+		EED_Thank_You_Page::set_definitions();
115
+		$this->thank_you_page = EED_Thank_You_Page::instance();
116
+		$this->thank_you_page->set_reg_url_link($data['espresso_thank_you_page']['e_reg_url_link']);
117
+		$this->thank_you_page->init();
118
+		$response['espresso_thank_you_page'] = array();
119
+		// get TXN
120
+		$transaction = $this->thank_you_page->get_txn();
121
+		// no TXN? then get out
122
+		if (! $transaction instanceof EE_Transaction) {
123
+			$notices = EE_Error::get_notices();
124
+			$response['espresso_thank_you_page'] = array(
125
+				'errors' => ! empty($notices['errors'])
126
+					? $notices['errors']
127
+					: sprintf(
128
+						__(
129
+							'The information for your transaction could not be retrieved from the server or the transaction data received was invalid because of a technical reason. (%s)',
130
+							'event_espresso'
131
+						),
132
+						__LINE__
133
+					),
134
+			);
135
+			return $response;
136
+		}
137
+		$this->transaction = $transaction;
138
+		return $response;
139
+	}
140
+
141
+
142
+	/**
143
+	 * @param string $txn_status
144
+	 * @param array  $response
145
+	 * @param array  $data
146
+	 * @return array
147
+	 * @throws EE_Error
148
+	 */
149
+	private function getTransactionDetails($txn_status, $response, $data)
150
+	{
151
+		// has the TXN status changed since we last checked (or empty because this is the first time running through this code)?
152
+		if ($txn_status !== $this->transaction->status_ID()) {
153
+			// switch between two possible basic outcomes
154
+			switch ($this->transaction->status_ID()) {
155
+				// TXN has been updated in some way
156
+				case EEM_Transaction::overpaid_status_code:
157
+				case EEM_Transaction::complete_status_code:
158
+				case EEM_Transaction::incomplete_status_code:
159
+					// send updated TXN results back to client,
160
+					$response['espresso_thank_you_page'] = array(
161
+						'transaction_details' => $this->thank_you_page->get_transaction_details(),
162
+						'txn_status'          => $this->transaction->status_ID(),
163
+					);
164
+					return $response;
165
+				// or we have a bad TXN, or really slow IPN, so calculate the wait time and send that back...
166
+				case EEM_Transaction::failed_status_code:
167
+				default:
168
+					// keep on waiting...
169
+					return $this->updateServerWaitTime($data['espresso_thank_you_page']);
170
+			}
171
+			// or is the TXN still failed (never been updated) ???
172
+		} elseif ($this->transaction->failed()) {
173
+			// keep on waiting...
174
+			return $this->updateServerWaitTime($data['espresso_thank_you_page']);
175
+		}
176
+	}
177
+
178
+
179
+	/**
180
+	 * @param int $since
181
+	 * @return array
182
+	 * @throws EE_Error
183
+	 */
184
+	private function paymentDetails($since)
185
+	{
186
+		// then check for payments
187
+		$payments = $this->thank_you_page->get_txn_payments($since);
188
+		// has a payment been processed ?
189
+		if (! empty($payments) || $this->thank_you_page->isOfflinePaymentMethod()) {
190
+			if ($since) {
191
+				$response['espresso_thank_you_page'] = array(
192
+					'new_payments'        => $this->thank_you_page->get_new_payments($payments),
193
+					'transaction_details' => $this->thank_you_page->get_transaction_details(),
194
+					'txn_status'          => $this->transaction->status_ID(),
195
+				);
196
+			} else {
197
+				$response['espresso_thank_you_page']['payment_details'] = $this->thank_you_page->get_payment_details(
198
+					$payments
199
+				);
200
+			}
201
+			// reset time to check for payments
202
+			$response['espresso_thank_you_page']['get_payments_since'] = time();
203
+		} else {
204
+			$response['espresso_thank_you_page']['get_payments_since'] = $since;
205
+		}
206
+		return $response;
207
+	}
208
+
209
+
210
+	/**
211
+	 * @param array $thank_you_page_data    thank you page portion of the incoming JSON array
212
+	 *                                      from the WP heartbeat data
213
+	 * @return array
214
+	 * @throws EE_Error
215
+	 */
216
+	private function updateServerWaitTime($thank_you_page_data)
217
+	{
218
+		$response['espresso_thank_you_page'] = array(
219
+			'still_waiting' => isset($thank_you_page_data['initial_access'])
220
+				? time() - $thank_you_page_data['initial_access']
221
+				: 0,
222
+			'txn_status'    => $this->transaction->status_ID(),
223
+		);
224
+		return $response;
225
+	}
226 226
 }
Please login to merge, or discard this patch.
admin_pages/general_settings/General_Settings_Admin_Page.core.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -661,7 +661,7 @@  discard block
 block discarded – undo
661 661
      *
662 662
      * @param string          $CNT_ISO
663 663
      * @param EE_Country|null $country
664
-     * @return mixed string | array$country
664
+     * @return string|null string | array$country
665 665
      * @throws DomainException
666 666
      * @throws EE_Error
667 667
      * @throws InvalidArgumentException
@@ -1017,7 +1017,7 @@  discard block
 block discarded – undo
1017 1017
      *        delete_state
1018 1018
      *
1019 1019
      * @access    public
1020
-     * @return        boolean
1020
+     * @return        false|null
1021 1021
      * @throws EE_Error
1022 1022
      * @throws InvalidArgumentException
1023 1023
      * @throws InvalidDataTypeException
Please login to merge, or discard this patch.
Indentation   +1385 added lines, -1385 removed lines patch added patch discarded remove patch
@@ -20,1400 +20,1400 @@
 block discarded – undo
20 20
 class General_Settings_Admin_Page extends EE_Admin_Page
21 21
 {
22 22
 
23
-    /**
24
-     * _question_group
25
-     * holds the specific question group object for the question group details screen
26
-     *
27
-     * @var object
28
-     */
29
-    protected $_question_group;
30
-
31
-
32
-    /**
33
-     * Initialize basic properties.
34
-     */
35
-    protected function _init_page_props()
36
-    {
37
-        $this->page_slug = GEN_SET_PG_SLUG;
38
-        $this->page_label = GEN_SET_LABEL;
39
-        $this->_admin_base_url = GEN_SET_ADMIN_URL;
40
-        $this->_admin_base_path = GEN_SET_ADMIN;
41
-    }
42
-
43
-
44
-    /**
45
-     * Set ajax hooks
46
-     */
47
-    protected function _ajax_hooks()
48
-    {
49
-        add_action('wp_ajax_espresso_display_country_settings', array($this, 'display_country_settings'));
50
-        add_action('wp_ajax_espresso_display_country_states', array($this, 'display_country_states'));
51
-        add_action('wp_ajax_espresso_delete_state', array($this, 'delete_state'), 10, 3);
52
-        add_action('wp_ajax_espresso_add_new_state', array($this, 'add_new_state'));
53
-    }
54
-
55
-
56
-    /**
57
-     * More page properties initialization.
58
-     */
59
-    protected function _define_page_props()
60
-    {
61
-        $this->_admin_page_title = GEN_SET_LABEL;
62
-        $this->_labels = array(
63
-            'publishbox' => __('Update Settings', 'event_espresso'),
64
-        );
65
-    }
66
-
67
-
68
-    /**
69
-     * Set page routes property.
70
-     */
71
-    protected function _set_page_routes()
72
-    {
73
-        $this->_page_routes = array(
74
-
75
-            'critical_pages'                => array(
76
-                'func'       => '_espresso_page_settings',
77
-                'capability' => 'manage_options',
78
-            ),
79
-            'update_espresso_page_settings' => array(
80
-                'func'       => '_update_espresso_page_settings',
81
-                'capability' => 'manage_options',
82
-                'noheader'   => true,
83
-            ),
84
-            'default'                       => array(
85
-                'func'       => '_your_organization_settings',
86
-                'capability' => 'manage_options',
87
-            ),
88
-
89
-            'update_your_organization_settings' => array(
90
-                'func'       => '_update_your_organization_settings',
91
-                'capability' => 'manage_options',
92
-                'noheader'   => true,
93
-            ),
94
-
95
-            'admin_option_settings' => array(
96
-                'func'       => '_admin_option_settings',
97
-                'capability' => 'manage_options',
98
-            ),
99
-
100
-            'update_admin_option_settings' => array(
101
-                'func'       => '_update_admin_option_settings',
102
-                'capability' => 'manage_options',
103
-                'noheader'   => true,
104
-            ),
105
-
106
-            'country_settings' => array(
107
-                'func'       => '_country_settings',
108
-                'capability' => 'manage_options',
109
-            ),
110
-
111
-            'update_country_settings' => array(
112
-                'func'       => '_update_country_settings',
113
-                'capability' => 'manage_options',
114
-                'noheader'   => true,
115
-            ),
116
-
117
-            'display_country_settings' => array(
118
-                'func'       => 'display_country_settings',
119
-                'capability' => 'manage_options',
120
-                'noheader'   => true,
121
-            ),
122
-
123
-            'add_new_state' => array(
124
-                'func'       => 'add_new_state',
125
-                'capability' => 'manage_options',
126
-                'noheader'   => true,
127
-            ),
128
-
129
-            'delete_state'            => array(
130
-                'func'       => 'delete_state',
131
-                'capability' => 'manage_options',
132
-                'noheader'   => true,
133
-            ),
134
-            'privacy_settings'        => array(
135
-                'func'       => 'privacySettings',
136
-                'capability' => 'manage_options',
137
-            ),
138
-            'update_privacy_settings' => array(
139
-                'func'               => 'updatePrivacySettings',
140
-                'capability'         => 'manage_options',
141
-                'noheader'           => true,
142
-                'headers_sent_route' => 'privacy_settings',
143
-            ),
144
-        );
145
-    }
146
-
147
-
148
-    /**
149
-     * Set page configuration property
150
-     */
151
-    protected function _set_page_config()
152
-    {
153
-        $this->_page_config = array(
154
-            'critical_pages'        => array(
155
-                'nav'           => array(
156
-                    'label' => __('Critical Pages', 'event_espresso'),
157
-                    'order' => 50,
158
-                ),
159
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
160
-                'help_tabs'     => array(
161
-                    'general_settings_critical_pages_help_tab' => array(
162
-                        'title'    => __('Critical Pages', 'event_espresso'),
163
-                        'filename' => 'general_settings_critical_pages',
164
-                    ),
165
-                ),
166
-                'help_tour'     => array('Critical_Pages_Help_Tour'),
167
-                'require_nonce' => false,
168
-            ),
169
-            'default'               => array(
170
-                'nav'           => array(
171
-                    'label' => __('Your Organization', 'event_espresso'),
172
-                    'order' => 20,
173
-                ),
174
-                'help_tabs'     => array(
175
-                    'general_settings_your_organization_help_tab' => array(
176
-                        'title'    => __('Your Organization', 'event_espresso'),
177
-                        'filename' => 'general_settings_your_organization',
178
-                    ),
179
-                ),
180
-                'help_tour'     => array('Your_Organization_Help_Tour'),
181
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
182
-                'require_nonce' => false,
183
-            ),
184
-            'admin_option_settings' => array(
185
-                'nav'           => array(
186
-                    'label' => __('Admin Options', 'event_espresso'),
187
-                    'order' => 60,
188
-                ),
189
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
190
-                'help_tabs'     => array(
191
-                    'general_settings_admin_options_help_tab' => array(
192
-                        'title'    => __('Admin Options', 'event_espresso'),
193
-                        'filename' => 'general_settings_admin_options',
194
-                    ),
195
-                ),
196
-                'help_tour'     => array('Admin_Options_Help_Tour'),
197
-                'require_nonce' => false,
198
-            ),
199
-            'country_settings'      => array(
200
-                'nav'           => array(
201
-                    'label' => __('Countries', 'event_espresso'),
202
-                    'order' => 70,
203
-                ),
204
-                'help_tabs'     => array(
205
-                    'general_settings_countries_help_tab' => array(
206
-                        'title'    => __('Countries', 'event_espresso'),
207
-                        'filename' => 'general_settings_countries',
208
-                    ),
209
-                ),
210
-                'help_tour'     => array('Countries_Help_Tour'),
211
-                'require_nonce' => false,
212
-            ),
213
-            'privacy_settings'      => array(
214
-                'nav'           => array(
215
-                    'label' => esc_html__('Privacy', 'event_espresso'),
216
-                    'order' => 80,
217
-                ),
218
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
219
-                'require_nonce' => false,
220
-            ),
221
-        );
222
-    }
223
-
224
-
225
-    protected function _add_screen_options()
226
-    {
227
-    }
228
-
229
-
230
-    protected function _add_feature_pointers()
231
-    {
232
-    }
233
-
234
-
235
-    /**
236
-     * Enqueue global scripts and styles for all routes in the General Settings Admin Pages.
237
-     */
238
-    public function load_scripts_styles()
239
-    {
240
-        // styles
241
-        wp_enqueue_style('espresso-ui-theme');
242
-        // scripts
243
-        wp_enqueue_script('ee_admin_js');
244
-    }
245
-
246
-
247
-    /**
248
-     * Execute logic running on `admin_init`
249
-     */
250
-    public function admin_init()
251
-    {
252
-        EE_Registry::$i18n_js_strings['invalid_server_response'] = __(
253
-            'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.',
254
-            'event_espresso'
255
-        );
256
-        EE_Registry::$i18n_js_strings['error_occurred'] = __(
257
-            'An error occurred! Please refresh the page and try again.',
258
-            'event_espresso'
259
-        );
260
-        EE_Registry::$i18n_js_strings['confirm_delete_state'] = __(
261
-            'Are you sure you want to delete this State / Province?',
262
-            'event_espresso'
263
-        );
264
-        $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
265
-        EE_Registry::$i18n_js_strings['ajax_url'] = admin_url(
266
-            'admin-ajax.php?page=espresso_general_settings',
267
-            $protocol
268
-        );
269
-    }
270
-
271
-
272
-    public function admin_notices()
273
-    {
274
-    }
275
-
276
-
277
-    public function admin_footer_scripts()
278
-    {
279
-    }
280
-
281
-
282
-    /**
283
-     * Enqueue scripts and styles for the default route.
284
-     */
285
-    public function load_scripts_styles_default()
286
-    {
287
-        // styles
288
-        wp_enqueue_style('thickbox');
289
-        // scripts
290
-        wp_enqueue_script('media-upload');
291
-        wp_enqueue_script('thickbox');
292
-        wp_register_script(
293
-            'organization_settings',
294
-            GEN_SET_ASSETS_URL . 'your_organization_settings.js',
295
-            array('jquery', 'media-upload', 'thickbox'),
296
-            EVENT_ESPRESSO_VERSION,
297
-            true
298
-        );
299
-        wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION);
300
-        wp_enqueue_script('organization_settings');
301
-        wp_enqueue_style('organization-css');
302
-        $confirm_image_delete = array(
303
-            'text' => __(
304
-                'Do you really want to delete this image? Please remember to save your settings to complete the removal.',
305
-                'event_espresso'
306
-            ),
307
-        );
308
-        wp_localize_script('organization_settings', 'confirm_image_delete', $confirm_image_delete);
309
-    }
310
-
311
-
312
-    /**
313
-     * Enqueue scripts and styles for the country settings route.
314
-     */
315
-    public function load_scripts_styles_country_settings()
316
-    {
317
-        // scripts
318
-        wp_register_script(
319
-            'gen_settings_countries',
320
-            GEN_SET_ASSETS_URL . 'gen_settings_countries.js',
321
-            array('ee_admin_js'),
322
-            EVENT_ESPRESSO_VERSION,
323
-            true
324
-        );
325
-        wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION);
326
-        wp_enqueue_script('gen_settings_countries');
327
-        wp_enqueue_style('organization-css');
328
-    }
329
-
330
-
331
-    /*************        Espresso Pages        *************/
332
-    /**
333
-     * _espresso_page_settings
334
-     *
335
-     * @throws \EE_Error
336
-     * @throws DomainException
337
-     * @throws DomainException
338
-     * @throws InvalidDataTypeException
339
-     * @throws InvalidArgumentException
340
-     */
341
-    protected function _espresso_page_settings()
342
-    {
343
-        // Check to make sure all of the main pages are setup properly,
344
-        // if not create the default pages and display an admin notice
345
-        EEH_Activation::verify_default_pages_exist();
346
-        $this->_transient_garbage_collection();
347
-        $this->_template_args['values'] = $this->_yes_no_values;
348
-        $this->_template_args['reg_page_id'] = isset(EE_Registry::instance()->CFG->core->reg_page_id)
349
-            ? EE_Registry::instance()->CFG->core->reg_page_id
350
-            : null;
351
-        $this->_template_args['reg_page_obj'] = isset(EE_Registry::instance()->CFG->core->reg_page_id)
352
-            ? get_page(EE_Registry::instance()->CFG->core->reg_page_id)
353
-            : false;
354
-        $this->_template_args['txn_page_id'] = isset(EE_Registry::instance()->CFG->core->txn_page_id)
355
-            ? EE_Registry::instance()->CFG->core->txn_page_id
356
-            : null;
357
-        $this->_template_args['txn_page_obj'] = isset(EE_Registry::instance()->CFG->core->txn_page_id)
358
-            ? get_page(EE_Registry::instance()->CFG->core->txn_page_id)
359
-            : false;
360
-        $this->_template_args['thank_you_page_id'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id)
361
-            ? EE_Registry::instance()->CFG->core->thank_you_page_id
362
-            : null;
363
-        $this->_template_args['thank_you_page_obj'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id)
364
-            ? get_page(EE_Registry::instance()->CFG->core->thank_you_page_id)
365
-            : false;
366
-        $this->_template_args['cancel_page_id'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id)
367
-            ? EE_Registry::instance()->CFG->core->cancel_page_id
368
-            : null;
369
-        $this->_template_args['cancel_page_obj'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id)
370
-            ? get_page(EE_Registry::instance()->CFG->core->cancel_page_id)
371
-            : false;
372
-        $this->_set_add_edit_form_tags('update_espresso_page_settings');
373
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
374
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
375
-            GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php',
376
-            $this->_template_args,
377
-            true
378
-        );
379
-        $this->display_admin_page_with_sidebar();
380
-    }
381
-
382
-
383
-    /**
384
-     * Handler for updating espresso page settings.
385
-     *
386
-     * @throws EE_Error
387
-     */
388
-    protected function _update_espresso_page_settings()
389
-    {
390
-        // capture incoming request data && set page IDs
391
-        EE_Registry::instance()->CFG->core->reg_page_id = isset($this->_req_data['reg_page_id'])
392
-            ? absint($this->_req_data['reg_page_id'])
393
-            : EE_Registry::instance()->CFG->core->reg_page_id;
394
-        EE_Registry::instance()->CFG->core->txn_page_id = isset($this->_req_data['txn_page_id'])
395
-            ? absint($this->_req_data['txn_page_id'])
396
-            : EE_Registry::instance()->CFG->core->txn_page_id;
397
-        EE_Registry::instance()->CFG->core->thank_you_page_id = isset($this->_req_data['thank_you_page_id'])
398
-            ? absint($this->_req_data['thank_you_page_id'])
399
-            : EE_Registry::instance()->CFG->core->thank_you_page_id;
400
-        EE_Registry::instance()->CFG->core->cancel_page_id = isset($this->_req_data['cancel_page_id'])
401
-            ? absint($this->_req_data['cancel_page_id'])
402
-            : EE_Registry::instance()->CFG->core->cancel_page_id;
403
-
404
-        EE_Registry::instance()->CFG->core = apply_filters(
405
-            'FHEE__General_Settings_Admin_Page___update_espresso_page_settings__CFG_core',
406
-            EE_Registry::instance()->CFG->core,
407
-            $this->_req_data
408
-        );
409
-        $what = __('Critical Pages & Shortcodes', 'event_espresso');
410
-        $this->_redirect_after_action(
411
-            $this->_update_espresso_configuration(
412
-                $what,
413
-                EE_Registry::instance()->CFG->core,
414
-                __FILE__,
415
-                __FUNCTION__,
416
-                __LINE__
417
-            ),
418
-            $what,
419
-            '',
420
-            array(
421
-                'action' => 'critical_pages',
422
-            ),
423
-            true
424
-        );
425
-    }
426
-
427
-
428
-    /*************        Your Organization        *************/
429
-
430
-
431
-    /**
432
-     * @throws DomainException
433
-     * @throws EE_Error
434
-     * @throws InvalidArgumentException
435
-     * @throws InvalidDataTypeException
436
-     * @throws InvalidInterfaceException
437
-     */
438
-    protected function _your_organization_settings()
439
-    {
440
-        $this->_template_args['admin_page_content'] = '';
441
-        try {
442
-            /** @var EventEspresso\admin_pages\general_settings\OrganizationSettings $organization_settings_form */
443
-            $organization_settings_form = $this->loader->getShared(
444
-                'EventEspresso\admin_pages\general_settings\OrganizationSettings'
445
-            );
446
-            $this->_template_args['admin_page_content'] = $organization_settings_form->display();
447
-        } catch (Exception $e) {
448
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
449
-        }
450
-        $this->_set_add_edit_form_tags('update_your_organization_settings');
451
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
452
-        $this->display_admin_page_with_sidebar();
453
-    }
454
-
455
-
456
-    /**
457
-     * Handler for updating organization settings.
458
-     *
459
-     * @throws EE_Error
460
-     */
461
-    protected function _update_your_organization_settings()
462
-    {
463
-        try {
464
-            /** @var EventEspresso\admin_pages\general_settings\OrganizationSettings $organization_settings_form */
465
-            $organization_settings_form = $this->loader->getShared(
466
-                'EventEspresso\admin_pages\general_settings\OrganizationSettings'
467
-            );
468
-            $success = $organization_settings_form->process($this->_req_data);
469
-            EE_Registry::instance()->CFG = apply_filters(
470
-                'FHEE__General_Settings_Admin_Page___update_your_organization_settings__CFG',
471
-                EE_Registry::instance()->CFG
472
-            );
473
-        } catch (Exception $e) {
474
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
475
-            $success = false;
476
-        }
477
-
478
-        if ($success) {
479
-            $success = $this->_update_espresso_configuration(
480
-                esc_html__('Your Organization Settings', 'event_espresso'),
481
-                EE_Registry::instance()->CFG,
482
-                __FILE__,
483
-                __FUNCTION__,
484
-                __LINE__
485
-            );
486
-        }
487
-
488
-        $this->_redirect_after_action($success, '', '', array('action' => 'default'), true);
489
-    }
490
-
491
-
492
-
493
-    /*************        Admin Options        *************/
494
-
495
-
496
-    /**
497
-     * _admin_option_settings
498
-     *
499
-     * @throws \EE_Error
500
-     * @throws \LogicException
501
-     */
502
-    protected function _admin_option_settings()
503
-    {
504
-        $this->_template_args['admin_page_content'] = '';
505
-        try {
506
-            $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
507
-            // still need this for the old school form in Extend_General_Settings_Admin_Page
508
-            $this->_template_args['values'] = $this->_yes_no_values;
509
-            // also need to account for the do_action that was in the old template
510
-            $admin_options_settings_form->setTemplateArgs($this->_template_args);
511
-            $this->_template_args['admin_page_content'] = $admin_options_settings_form->display();
512
-        } catch (Exception $e) {
513
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
514
-        }
515
-        $this->_set_add_edit_form_tags('update_admin_option_settings');
516
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
517
-        $this->display_admin_page_with_sidebar();
518
-    }
519
-
520
-
521
-    /**
522
-     * _update_admin_option_settings
523
-     *
524
-     * @throws \EE_Error
525
-     * @throws InvalidDataTypeException
526
-     * @throws \EventEspresso\core\exceptions\InvalidFormSubmissionException
527
-     * @throws \InvalidArgumentException
528
-     * @throws \LogicException
529
-     */
530
-    protected function _update_admin_option_settings()
531
-    {
532
-        try {
533
-            $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
534
-            $admin_options_settings_form->process($this->_req_data[ $admin_options_settings_form->slug() ]);
535
-            EE_Registry::instance()->CFG->admin = apply_filters(
536
-                'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin',
537
-                EE_Registry::instance()->CFG->admin
538
-            );
539
-        } catch (Exception $e) {
540
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
541
-        }
542
-        $this->_redirect_after_action(
543
-            apply_filters(
544
-                'FHEE__General_Settings_Admin_Page___update_admin_option_settings__success',
545
-                $this->_update_espresso_configuration(
546
-                    'Admin Options',
547
-                    EE_Registry::instance()->CFG->admin,
548
-                    __FILE__,
549
-                    __FUNCTION__,
550
-                    __LINE__
551
-                )
552
-            ),
553
-            'Admin Options',
554
-            'updated',
555
-            array('action' => 'admin_option_settings')
556
-        );
557
-    }
558
-
559
-
560
-    /*************        Countries        *************/
561
-
562
-
563
-    /**
564
-     * @return string
565
-     */
566
-    protected function getCountryIsoForSite()
567
-    {
568
-        return ! empty(EE_Registry::instance()->CFG->organization->CNT_ISO)
569
-            ? EE_Registry::instance()->CFG->organization->CNT_ISO
570
-            : 'US';
571
-    }
572
-
573
-
574
-    /**
575
-     * @param string          $CNT_ISO
576
-     * @param EE_Country|null $country
577
-     * @return EE_Base_Class|EE_Country
578
-     * @throws EE_Error
579
-     * @throws InvalidArgumentException
580
-     * @throws InvalidDataTypeException
581
-     * @throws InvalidInterfaceException
582
-     * @throws ReflectionException
583
-     */
584
-    protected function verifyOrGetCountryFromIso($CNT_ISO, EE_Country $country = null)
585
-    {
586
-        /** @var EE_Country $country */
587
-        return $country instanceof EE_Country && $country->ID() === $CNT_ISO
588
-            ? $country
589
-            : EEM_Country::instance()->get_one_by_ID($CNT_ISO);
590
-    }
591
-
592
-
593
-    /**
594
-     * Output Country Settings view.
595
-     *
596
-     * @throws DomainException
597
-     * @throws EE_Error
598
-     * @throws InvalidArgumentException
599
-     * @throws InvalidDataTypeException
600
-     * @throws InvalidInterfaceException
601
-     * @throws ReflectionException
602
-     */
603
-    protected function _country_settings()
604
-    {
605
-        $CNT_ISO_for_site = $this->getCountryIsoForSite();
606
-        $CNT_ISO = isset($this->_req_data['country'])
607
-            ? strtoupper(sanitize_text_field($this->_req_data['country']))
608
-            : $CNT_ISO_for_site;
609
-
610
-        // load field generator helper
611
-
612
-        $this->_template_args['values'] = $this->_yes_no_values;
613
-
614
-        $this->_template_args['countries'] = new EE_Question_Form_Input(
615
-            EE_Question::new_instance(
616
-                array(
617
-                    'QST_ID'           => 0,
618
-                    'QST_display_text' => __('Select Country', 'event_espresso'),
619
-                    'QST_system'       => 'admin-country',
620
-                )
621
-            ),
622
-            EE_Answer::new_instance(
623
-                array(
624
-                    'ANS_ID'    => 0,
625
-                    'ANS_value' => $CNT_ISO,
626
-                )
627
-            ),
628
-            array(
629
-                'input_id'       => 'country',
630
-                'input_name'     => 'country',
631
-                'input_prefix'   => '',
632
-                'append_qstn_id' => false,
633
-            )
634
-        );
635
-        $country = $this->verifyOrGetCountryFromIso($CNT_ISO_for_site);
636
-        add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2);
637
-        add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2);
638
-        $this->_template_args['country_details_settings'] = $this->display_country_settings(
639
-            $country->ID(),
640
-            $country
641
-        );
642
-        $this->_template_args['country_states_settings'] = $this->display_country_states(
643
-            $country->ID(),
644
-            $country
645
-        );
646
-        $this->_template_args['CNT_name_for_site'] = $country->name();
647
-
648
-        $this->_set_add_edit_form_tags('update_country_settings');
649
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
650
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
651
-            GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php',
652
-            $this->_template_args,
653
-            true
654
-        );
655
-        $this->display_admin_page_with_no_sidebar();
656
-    }
657
-
658
-
659
-    /**
660
-     *        display_country_settings
661
-     *
662
-     * @param string          $CNT_ISO
663
-     * @param EE_Country|null $country
664
-     * @return mixed string | array$country
665
-     * @throws DomainException
666
-     * @throws EE_Error
667
-     * @throws InvalidArgumentException
668
-     * @throws InvalidDataTypeException
669
-     * @throws InvalidInterfaceException
670
-     * @throws ReflectionException
671
-     */
672
-    public function display_country_settings($CNT_ISO = '', EE_Country $country = null)
673
-    {
674
-        $CNT_ISO_for_site = $this->getCountryIsoForSite();
675
-
676
-        $CNT_ISO = isset($this->_req_data['country'])
677
-            ? strtoupper(sanitize_text_field($this->_req_data['country']))
678
-            : $CNT_ISO;
679
-        if (! $CNT_ISO) {
680
-            return '';
681
-        }
682
-
683
-        // for ajax
684
-        remove_all_filters('FHEE__EEH_Form_Fields__label_html');
685
-        remove_all_filters('FHEE__EEH_Form_Fields__input_html');
686
-        add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2);
687
-        add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2);
688
-        $country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country);
689
-        $CNT_cur_disabled = $CNT_ISO !== $CNT_ISO_for_site;
690
-        $this->_template_args['CNT_cur_disabled'] = $CNT_cur_disabled;
691
-
692
-        $country_input_types = array(
693
-            'CNT_active'      => array(
694
-                'type'             => 'RADIO_BTN',
695
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
696
-                'class'            => '',
697
-                'options'          => $this->_yes_no_values,
698
-                'use_desc_4_label' => true,
699
-            ),
700
-            'CNT_ISO'         => array(
701
-                'type'       => 'TEXT',
702
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
703
-                'class'      => 'small-text',
704
-            ),
705
-            'CNT_ISO3'        => array(
706
-                'type'       => 'TEXT',
707
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
708
-                'class'      => 'small-text',
709
-            ),
710
-            'RGN_ID'          => array(
711
-                'type'       => 'TEXT',
712
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
713
-                'class'      => 'small-text',
714
-            ),
715
-            'CNT_name'        => array(
716
-                'type'       => 'TEXT',
717
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
718
-                'class'      => 'regular-text',
719
-            ),
720
-            'CNT_cur_code'    => array(
721
-                'type'       => 'TEXT',
722
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
723
-                'class'      => 'small-text',
724
-                'disabled'   => $CNT_cur_disabled,
725
-            ),
726
-            'CNT_cur_single'  => array(
727
-                'type'       => 'TEXT',
728
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
729
-                'class'      => 'medium-text',
730
-                'disabled'   => $CNT_cur_disabled,
731
-            ),
732
-            'CNT_cur_plural'  => array(
733
-                'type'       => 'TEXT',
734
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
735
-                'class'      => 'medium-text',
736
-                'disabled'   => $CNT_cur_disabled,
737
-            ),
738
-            'CNT_cur_sign'    => array(
739
-                'type'         => 'TEXT',
740
-                'input_name'   => 'cntry[' . $CNT_ISO . ']',
741
-                'class'        => 'small-text',
742
-                'htmlentities' => false,
743
-                'disabled'     => $CNT_cur_disabled,
744
-            ),
745
-            'CNT_cur_sign_b4' => array(
746
-                'type'             => 'RADIO_BTN',
747
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
748
-                'class'            => '',
749
-                'options'          => $this->_yes_no_values,
750
-                'use_desc_4_label' => true,
751
-                'disabled'         => $CNT_cur_disabled,
752
-            ),
753
-            'CNT_cur_dec_plc' => array(
754
-                'type'       => 'RADIO_BTN',
755
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
756
-                'class'      => '',
757
-                'options'    => array(
758
-                    array('id' => 0, 'text' => ''),
759
-                    array('id' => 1, 'text' => ''),
760
-                    array('id' => 2, 'text' => ''),
761
-                    array('id' => 3, 'text' => ''),
762
-                ),
763
-                'disabled'   => $CNT_cur_disabled,
764
-            ),
765
-            'CNT_cur_dec_mrk' => array(
766
-                'type'             => 'RADIO_BTN',
767
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
768
-                'class'            => '',
769
-                'options'          => array(
770
-                    array(
771
-                        'id'   => ',',
772
-                        'text' => __(', (comma)', 'event_espresso'),
773
-                    ),
774
-                    array('id' => '.', 'text' => __('. (decimal)', 'event_espresso')),
775
-                ),
776
-                'use_desc_4_label' => true,
777
-                'disabled'         => $CNT_cur_disabled,
778
-            ),
779
-            'CNT_cur_thsnds'  => array(
780
-                'type'             => 'RADIO_BTN',
781
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
782
-                'class'            => '',
783
-                'options'          => array(
784
-                    array(
785
-                        'id'   => ',',
786
-                        'text' => __(', (comma)', 'event_espresso'),
787
-                    ),
788
-                    array('id' => '.', 'text' => __('. (decimal)', 'event_espresso')),
789
-                ),
790
-                'use_desc_4_label' => true,
791
-                'disabled'         => $CNT_cur_disabled,
792
-            ),
793
-            'CNT_tel_code'    => array(
794
-                'type'       => 'TEXT',
795
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
796
-                'class'      => 'small-text',
797
-            ),
798
-            'CNT_is_EU'       => array(
799
-                'type'             => 'RADIO_BTN',
800
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
801
-                'class'            => '',
802
-                'options'          => $this->_yes_no_values,
803
-                'use_desc_4_label' => true,
804
-            ),
805
-        );
806
-        $this->_template_args['inputs'] = EE_Question_Form_Input::generate_question_form_inputs_for_object(
807
-            $country,
808
-            $country_input_types
809
-        );
810
-        $country_details_settings = EEH_Template::display_template(
811
-            GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php',
812
-            $this->_template_args,
813
-            true
814
-        );
815
-
816
-        if (defined('DOING_AJAX')) {
817
-            $notices = EE_Error::get_notices(false, false, false);
818
-            echo wp_json_encode(
819
-                array(
820
-                    'return_data' => $country_details_settings,
821
-                    'success'     => $notices['success'],
822
-                    'errors'      => $notices['errors'],
823
-                )
824
-            );
825
-            die();
826
-        } else {
827
-            return $country_details_settings;
828
-        }
829
-    }
830
-
831
-
832
-    /**
833
-     * @param string          $CNT_ISO
834
-     * @param EE_Country|null $country
835
-     * @return string
836
-     * @throws DomainException
837
-     * @throws EE_Error
838
-     * @throws InvalidArgumentException
839
-     * @throws InvalidDataTypeException
840
-     * @throws InvalidInterfaceException
841
-     * @throws ReflectionException
842
-     */
843
-    public function display_country_states($CNT_ISO = '', EE_Country $country = null)
844
-    {
845
-
846
-        $CNT_ISO = isset($this->_req_data['country'])
847
-            ? sanitize_text_field($this->_req_data['country'])
848
-            : $CNT_ISO;
849
-        if (! $CNT_ISO) {
850
-            return '';
851
-        }
852
-        // for ajax
853
-        remove_all_filters('FHEE__EEH_Form_Fields__label_html');
854
-        remove_all_filters('FHEE__EEH_Form_Fields__input_html');
855
-        add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'state_form_field_label_wrap'), 10, 2);
856
-        add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'state_form_field_input__wrap'), 10, 2);
857
-        $states = EEM_State::instance()->get_all_states_for_these_countries(array($CNT_ISO => $CNT_ISO));
858
-        if (empty($states)) {
859
-            /** @var EventEspresso\core\services\address\CountrySubRegionDao $countrySubRegionDao */
860
-            $countrySubRegionDao = $this->loader->getShared(
861
-                'EventEspresso\core\services\address\CountrySubRegionDao'
862
-            );
863
-            if ($countrySubRegionDao instanceof EventEspresso\core\services\address\CountrySubRegionDao) {
864
-                $country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country);
865
-                if ($countrySubRegionDao->saveCountrySubRegions($country)) {
866
-                    $states = EEM_State::instance()->get_all_states_for_these_countries(
867
-                        array($CNT_ISO => $CNT_ISO)
868
-                    );
869
-                }
870
-            }
871
-        }
872
-        if (is_array($states)) {
873
-            foreach ($states as $STA_ID => $state) {
874
-                if ($state instanceof EE_State) {
875
-                    // STA_abbrev    STA_name    STA_active
876
-                    $state_input_types = array(
877
-                        'STA_abbrev' => array(
878
-                            'type'       => 'TEXT',
879
-                            'input_name' => 'states[' . $STA_ID . ']',
880
-                            'class'      => 'mid-text',
881
-                        ),
882
-                        'STA_name'   => array(
883
-                            'type'       => 'TEXT',
884
-                            'input_name' => 'states[' . $STA_ID . ']',
885
-                            'class'      => 'regular-text',
886
-                        ),
887
-                        'STA_active' => array(
888
-                            'type'             => 'RADIO_BTN',
889
-                            'input_name'       => 'states[' . $STA_ID . ']',
890
-                            'options'          => $this->_yes_no_values,
891
-                            'use_desc_4_label' => true,
892
-                        ),
893
-                    );
894
-                    $this->_template_args['states'][ $STA_ID ]['inputs'] =
895
-                        EE_Question_Form_Input::generate_question_form_inputs_for_object(
896
-                            $state,
897
-                            $state_input_types
898
-                        );
899
-                    $query_args = array(
900
-                        'action'     => 'delete_state',
901
-                        'STA_ID'     => $STA_ID,
902
-                        'CNT_ISO'    => $CNT_ISO,
903
-                        'STA_abbrev' => $state->abbrev(),
904
-                    );
905
-                    $this->_template_args['states'][ $STA_ID ]['delete_state_url'] =
906
-                        EE_Admin_Page::add_query_args_and_nonce(
907
-                            $query_args,
908
-                            GEN_SET_ADMIN_URL
909
-                        );
910
-                }
911
-            }
912
-        } else {
913
-            $this->_template_args['states'] = false;
914
-        }
915
-
916
-        $this->_template_args['add_new_state_url'] = EE_Admin_Page::add_query_args_and_nonce(
917
-            array('action' => 'add_new_state'),
918
-            GEN_SET_ADMIN_URL
919
-        );
920
-
921
-        $state_details_settings = EEH_Template::display_template(
922
-            GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php',
923
-            $this->_template_args,
924
-            true
925
-        );
926
-
927
-        if (defined('DOING_AJAX')) {
928
-            $notices = EE_Error::get_notices(false, false, false);
929
-            echo wp_json_encode(
930
-                array(
931
-                    'return_data' => $state_details_settings,
932
-                    'success'     => $notices['success'],
933
-                    'errors'      => $notices['errors'],
934
-                )
935
-            );
936
-            die();
937
-        } else {
938
-            return $state_details_settings;
939
-        }
940
-    }
941
-
942
-
943
-    /**
944
-     *        add_new_state
945
-     *
946
-     * @access    public
947
-     * @return void
948
-     * @throws EE_Error
949
-     * @throws InvalidArgumentException
950
-     * @throws InvalidDataTypeException
951
-     * @throws InvalidInterfaceException
952
-     */
953
-    public function add_new_state()
954
-    {
955
-
956
-        $success = true;
957
-
958
-        $CNT_ISO = isset($this->_req_data['CNT_ISO'])
959
-            ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO']))
960
-            : false;
961
-        if (! $CNT_ISO) {
962
-            EE_Error::add_error(
963
-                __('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
964
-                __FILE__,
965
-                __FUNCTION__,
966
-                __LINE__
967
-            );
968
-            $success = false;
969
-        }
970
-        $STA_abbrev = isset($this->_req_data['STA_abbrev'])
971
-            ? sanitize_text_field($this->_req_data['STA_abbrev'])
972
-            : false;
973
-        if (! $STA_abbrev) {
974
-            EE_Error::add_error(
975
-                __('No State ISO code or an invalid State ISO code was received.', 'event_espresso'),
976
-                __FILE__,
977
-                __FUNCTION__,
978
-                __LINE__
979
-            );
980
-            $success = false;
981
-        }
982
-        $STA_name = isset($this->_req_data['STA_name'])
983
-            ? sanitize_text_field($this->_req_data['STA_name'])
984
-            : false;
985
-        if (! $STA_name) {
986
-            EE_Error::add_error(
987
-                __('No State name or an invalid State name was received.', 'event_espresso'),
988
-                __FILE__,
989
-                __FUNCTION__,
990
-                __LINE__
991
-            );
992
-            $success = false;
993
-        }
994
-
995
-        if ($success) {
996
-            $cols_n_values = array(
997
-                'CNT_ISO'    => $CNT_ISO,
998
-                'STA_abbrev' => $STA_abbrev,
999
-                'STA_name'   => $STA_name,
1000
-                'STA_active' => true,
1001
-            );
1002
-            $success = EEM_State::instance()->insert($cols_n_values);
1003
-            EE_Error::add_success(__('The State was added successfully.', 'event_espresso'));
1004
-        }
1005
-
1006
-        if (defined('DOING_AJAX')) {
1007
-            $notices = EE_Error::get_notices(false, false, false);
1008
-            echo wp_json_encode(array_merge($notices, array('return_data' => $CNT_ISO)));
1009
-            die();
1010
-        } else {
1011
-            $this->_redirect_after_action($success, 'State', 'added', array('action' => 'country_settings'));
1012
-        }
1013
-    }
1014
-
1015
-
1016
-    /**
1017
-     *        delete_state
1018
-     *
1019
-     * @access    public
1020
-     * @return        boolean
1021
-     * @throws EE_Error
1022
-     * @throws InvalidArgumentException
1023
-     * @throws InvalidDataTypeException
1024
-     * @throws InvalidInterfaceException
1025
-     */
1026
-    public function delete_state()
1027
-    {
1028
-        $CNT_ISO = isset($this->_req_data['CNT_ISO'])
1029
-            ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO']))
1030
-            : false;
1031
-        $STA_ID = isset($this->_req_data['STA_ID'])
1032
-            ? sanitize_text_field($this->_req_data['STA_ID'])
1033
-            : false;
1034
-        $STA_abbrev = isset($this->_req_data['STA_abbrev'])
1035
-            ? sanitize_text_field($this->_req_data['STA_abbrev'])
1036
-            : false;
1037
-        if (! $STA_ID) {
1038
-            EE_Error::add_error(
1039
-                __('No State ID or an invalid State ID was received.', 'event_espresso'),
1040
-                __FILE__,
1041
-                __FUNCTION__,
1042
-                __LINE__
1043
-            );
1044
-            return false;
1045
-        }
1046
-
1047
-        $success = EEM_State::instance()->delete_by_ID($STA_ID);
1048
-        if ($success !== false) {
1049
-            do_action(
1050
-                'AHEE__General_Settings_Admin_Page__delete_state__state_deleted',
1051
-                $CNT_ISO,
1052
-                $STA_ID,
1053
-                array('STA_abbrev' => $STA_abbrev)
1054
-            );
1055
-            EE_Error::add_success(__('The State was deleted successfully.', 'event_espresso'));
1056
-        }
1057
-        if (defined('DOING_AJAX')) {
1058
-            $notices = EE_Error::get_notices(false, false);
1059
-            $notices['return_data'] = true;
1060
-            echo wp_json_encode($notices);
1061
-            die();
1062
-        } else {
1063
-            $this->_redirect_after_action(
1064
-                $success,
1065
-                'State',
1066
-                'deleted',
1067
-                array('action' => 'country_settings')
1068
-            );
1069
-        }
1070
-    }
1071
-
1072
-
1073
-    /**
1074
-     *        _update_country_settings
1075
-     *
1076
-     * @access    protected
1077
-     * @return void
1078
-     * @throws EE_Error
1079
-     * @throws InvalidArgumentException
1080
-     * @throws InvalidDataTypeException
1081
-     * @throws InvalidInterfaceException
1082
-     */
1083
-    protected function _update_country_settings()
1084
-    {
1085
-        // grab the country ISO code
1086
-        $CNT_ISO = isset($this->_req_data['country'])
1087
-            ? strtoupper(sanitize_text_field($this->_req_data['country']))
1088
-            : false;
1089
-        if (! $CNT_ISO) {
1090
-            EE_Error::add_error(
1091
-                __('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
1092
-                __FILE__,
1093
-                __FUNCTION__,
1094
-                __LINE__
1095
-            );
1096
-
1097
-            return;
1098
-        }
1099
-        $cols_n_values = array();
1100
-        $cols_n_values['CNT_ISO3'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3'])
1101
-            ? strtoupper(sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3']))
1102
-            : false;
1103
-        $cols_n_values['RGN_ID'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID'])
1104
-            ? absint($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID'])
1105
-            : null;
1106
-        $cols_n_values['CNT_name'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name'])
1107
-            ? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name'])
1108
-            : null;
1109
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code'])) {
1110
-            $cols_n_values['CNT_cur_code'] = strtoupper(
1111
-                sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code'])
1112
-            );
1113
-        }
1114
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single'])) {
1115
-            $cols_n_values['CNT_cur_single'] = sanitize_text_field(
1116
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single']
1117
-            );
1118
-        }
1119
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural'])) {
1120
-            $cols_n_values['CNT_cur_plural'] = sanitize_text_field(
1121
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural']
1122
-            );
1123
-        }
1124
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign'])) {
1125
-            $cols_n_values['CNT_cur_sign'] = sanitize_text_field(
1126
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign']
1127
-            );
1128
-        }
1129
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4'])) {
1130
-            $cols_n_values['CNT_cur_sign_b4'] = absint(
1131
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4']
1132
-            );
1133
-        }
1134
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc'])) {
1135
-            $cols_n_values['CNT_cur_dec_plc'] = absint(
1136
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc']
1137
-            );
1138
-        }
1139
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk'])) {
1140
-            $cols_n_values['CNT_cur_dec_mrk'] = sanitize_text_field(
1141
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk']
1142
-            );
1143
-        }
1144
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds'])) {
1145
-            $cols_n_values['CNT_cur_thsnds'] = sanitize_text_field(
1146
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds']
1147
-            );
1148
-        }
1149
-        $cols_n_values['CNT_tel_code'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code'])
1150
-            ? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code'])
1151
-            : null;
1152
-        $cols_n_values['CNT_is_EU'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU'])
1153
-            ? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU'])
1154
-            : false;
1155
-        $cols_n_values['CNT_active'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active'])
1156
-            ? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active'])
1157
-            : false;
1158
-        // allow filtering of country data
1159
-        $cols_n_values = apply_filters(
1160
-            'FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values',
1161
-            $cols_n_values
1162
-        );
1163
-
1164
-        // where values
1165
-        $where_cols_n_values = array(array('CNT_ISO' => $CNT_ISO));
1166
-        // run the update
1167
-        $success = EEM_Country::instance()->update($cols_n_values, $where_cols_n_values);
1168
-
1169
-        if (isset($this->_req_data['states']) && is_array($this->_req_data['states']) && $success !== false) {
1170
-            // allow filtering of states data
1171
-            $states = apply_filters(
1172
-                'FHEE__General_Settings_Admin_Page___update_country_settings__states',
1173
-                $this->_req_data['states']
1174
-            );
1175
-
1176
-            // loop thru state data ( looks like : states[75][STA_name] )
1177
-            foreach ($states as $STA_ID => $state) {
1178
-                $cols_n_values = array(
1179
-                    'CNT_ISO'    => $CNT_ISO,
1180
-                    'STA_abbrev' => sanitize_text_field($state['STA_abbrev']),
1181
-                    'STA_name'   => sanitize_text_field($state['STA_name']),
1182
-                    'STA_active' => (bool) absint($state['STA_active']),
1183
-                );
1184
-                // where values
1185
-                $where_cols_n_values = array(array('STA_ID' => $STA_ID));
1186
-                // run the update
1187
-                $success = EEM_State::instance()->update($cols_n_values, $where_cols_n_values);
1188
-                if ($success !== false) {
1189
-                    do_action(
1190
-                        'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved',
1191
-                        $CNT_ISO,
1192
-                        $STA_ID,
1193
-                        $cols_n_values
1194
-                    );
1195
-                }
1196
-            }
1197
-        }
1198
-        // check if country being edited matches org option country, and if so, then  update EE_Config with new settings
1199
-        if (isset(EE_Registry::instance()->CFG->organization->CNT_ISO)
1200
-            && $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO
1201
-        ) {
1202
-            EE_Registry::instance()->CFG->currency = new EE_Currency_Config($CNT_ISO);
1203
-            EE_Registry::instance()->CFG->update_espresso_config();
1204
-        }
1205
-
1206
-        if ($success !== false) {
1207
-            EE_Error::add_success(
1208
-                esc_html__('Country Settings updated successfully.', 'event_espresso')
1209
-            );
1210
-        }
1211
-        $this->_redirect_after_action(
1212
-            $success,
1213
-            '',
1214
-            '',
1215
-            array('action' => 'country_settings', 'country' => $CNT_ISO),
1216
-            true
1217
-        );
1218
-    }
1219
-
1220
-
1221
-    /**
1222
-     *        form_form_field_label_wrap
1223
-     *
1224
-     * @access        public
1225
-     * @param        string $label
1226
-     * @return        string
1227
-     */
1228
-    public function country_form_field_label_wrap($label, $required_text)
1229
-    {
1230
-        return '
23
+	/**
24
+	 * _question_group
25
+	 * holds the specific question group object for the question group details screen
26
+	 *
27
+	 * @var object
28
+	 */
29
+	protected $_question_group;
30
+
31
+
32
+	/**
33
+	 * Initialize basic properties.
34
+	 */
35
+	protected function _init_page_props()
36
+	{
37
+		$this->page_slug = GEN_SET_PG_SLUG;
38
+		$this->page_label = GEN_SET_LABEL;
39
+		$this->_admin_base_url = GEN_SET_ADMIN_URL;
40
+		$this->_admin_base_path = GEN_SET_ADMIN;
41
+	}
42
+
43
+
44
+	/**
45
+	 * Set ajax hooks
46
+	 */
47
+	protected function _ajax_hooks()
48
+	{
49
+		add_action('wp_ajax_espresso_display_country_settings', array($this, 'display_country_settings'));
50
+		add_action('wp_ajax_espresso_display_country_states', array($this, 'display_country_states'));
51
+		add_action('wp_ajax_espresso_delete_state', array($this, 'delete_state'), 10, 3);
52
+		add_action('wp_ajax_espresso_add_new_state', array($this, 'add_new_state'));
53
+	}
54
+
55
+
56
+	/**
57
+	 * More page properties initialization.
58
+	 */
59
+	protected function _define_page_props()
60
+	{
61
+		$this->_admin_page_title = GEN_SET_LABEL;
62
+		$this->_labels = array(
63
+			'publishbox' => __('Update Settings', 'event_espresso'),
64
+		);
65
+	}
66
+
67
+
68
+	/**
69
+	 * Set page routes property.
70
+	 */
71
+	protected function _set_page_routes()
72
+	{
73
+		$this->_page_routes = array(
74
+
75
+			'critical_pages'                => array(
76
+				'func'       => '_espresso_page_settings',
77
+				'capability' => 'manage_options',
78
+			),
79
+			'update_espresso_page_settings' => array(
80
+				'func'       => '_update_espresso_page_settings',
81
+				'capability' => 'manage_options',
82
+				'noheader'   => true,
83
+			),
84
+			'default'                       => array(
85
+				'func'       => '_your_organization_settings',
86
+				'capability' => 'manage_options',
87
+			),
88
+
89
+			'update_your_organization_settings' => array(
90
+				'func'       => '_update_your_organization_settings',
91
+				'capability' => 'manage_options',
92
+				'noheader'   => true,
93
+			),
94
+
95
+			'admin_option_settings' => array(
96
+				'func'       => '_admin_option_settings',
97
+				'capability' => 'manage_options',
98
+			),
99
+
100
+			'update_admin_option_settings' => array(
101
+				'func'       => '_update_admin_option_settings',
102
+				'capability' => 'manage_options',
103
+				'noheader'   => true,
104
+			),
105
+
106
+			'country_settings' => array(
107
+				'func'       => '_country_settings',
108
+				'capability' => 'manage_options',
109
+			),
110
+
111
+			'update_country_settings' => array(
112
+				'func'       => '_update_country_settings',
113
+				'capability' => 'manage_options',
114
+				'noheader'   => true,
115
+			),
116
+
117
+			'display_country_settings' => array(
118
+				'func'       => 'display_country_settings',
119
+				'capability' => 'manage_options',
120
+				'noheader'   => true,
121
+			),
122
+
123
+			'add_new_state' => array(
124
+				'func'       => 'add_new_state',
125
+				'capability' => 'manage_options',
126
+				'noheader'   => true,
127
+			),
128
+
129
+			'delete_state'            => array(
130
+				'func'       => 'delete_state',
131
+				'capability' => 'manage_options',
132
+				'noheader'   => true,
133
+			),
134
+			'privacy_settings'        => array(
135
+				'func'       => 'privacySettings',
136
+				'capability' => 'manage_options',
137
+			),
138
+			'update_privacy_settings' => array(
139
+				'func'               => 'updatePrivacySettings',
140
+				'capability'         => 'manage_options',
141
+				'noheader'           => true,
142
+				'headers_sent_route' => 'privacy_settings',
143
+			),
144
+		);
145
+	}
146
+
147
+
148
+	/**
149
+	 * Set page configuration property
150
+	 */
151
+	protected function _set_page_config()
152
+	{
153
+		$this->_page_config = array(
154
+			'critical_pages'        => array(
155
+				'nav'           => array(
156
+					'label' => __('Critical Pages', 'event_espresso'),
157
+					'order' => 50,
158
+				),
159
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
160
+				'help_tabs'     => array(
161
+					'general_settings_critical_pages_help_tab' => array(
162
+						'title'    => __('Critical Pages', 'event_espresso'),
163
+						'filename' => 'general_settings_critical_pages',
164
+					),
165
+				),
166
+				'help_tour'     => array('Critical_Pages_Help_Tour'),
167
+				'require_nonce' => false,
168
+			),
169
+			'default'               => array(
170
+				'nav'           => array(
171
+					'label' => __('Your Organization', 'event_espresso'),
172
+					'order' => 20,
173
+				),
174
+				'help_tabs'     => array(
175
+					'general_settings_your_organization_help_tab' => array(
176
+						'title'    => __('Your Organization', 'event_espresso'),
177
+						'filename' => 'general_settings_your_organization',
178
+					),
179
+				),
180
+				'help_tour'     => array('Your_Organization_Help_Tour'),
181
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
182
+				'require_nonce' => false,
183
+			),
184
+			'admin_option_settings' => array(
185
+				'nav'           => array(
186
+					'label' => __('Admin Options', 'event_espresso'),
187
+					'order' => 60,
188
+				),
189
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
190
+				'help_tabs'     => array(
191
+					'general_settings_admin_options_help_tab' => array(
192
+						'title'    => __('Admin Options', 'event_espresso'),
193
+						'filename' => 'general_settings_admin_options',
194
+					),
195
+				),
196
+				'help_tour'     => array('Admin_Options_Help_Tour'),
197
+				'require_nonce' => false,
198
+			),
199
+			'country_settings'      => array(
200
+				'nav'           => array(
201
+					'label' => __('Countries', 'event_espresso'),
202
+					'order' => 70,
203
+				),
204
+				'help_tabs'     => array(
205
+					'general_settings_countries_help_tab' => array(
206
+						'title'    => __('Countries', 'event_espresso'),
207
+						'filename' => 'general_settings_countries',
208
+					),
209
+				),
210
+				'help_tour'     => array('Countries_Help_Tour'),
211
+				'require_nonce' => false,
212
+			),
213
+			'privacy_settings'      => array(
214
+				'nav'           => array(
215
+					'label' => esc_html__('Privacy', 'event_espresso'),
216
+					'order' => 80,
217
+				),
218
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
219
+				'require_nonce' => false,
220
+			),
221
+		);
222
+	}
223
+
224
+
225
+	protected function _add_screen_options()
226
+	{
227
+	}
228
+
229
+
230
+	protected function _add_feature_pointers()
231
+	{
232
+	}
233
+
234
+
235
+	/**
236
+	 * Enqueue global scripts and styles for all routes in the General Settings Admin Pages.
237
+	 */
238
+	public function load_scripts_styles()
239
+	{
240
+		// styles
241
+		wp_enqueue_style('espresso-ui-theme');
242
+		// scripts
243
+		wp_enqueue_script('ee_admin_js');
244
+	}
245
+
246
+
247
+	/**
248
+	 * Execute logic running on `admin_init`
249
+	 */
250
+	public function admin_init()
251
+	{
252
+		EE_Registry::$i18n_js_strings['invalid_server_response'] = __(
253
+			'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.',
254
+			'event_espresso'
255
+		);
256
+		EE_Registry::$i18n_js_strings['error_occurred'] = __(
257
+			'An error occurred! Please refresh the page and try again.',
258
+			'event_espresso'
259
+		);
260
+		EE_Registry::$i18n_js_strings['confirm_delete_state'] = __(
261
+			'Are you sure you want to delete this State / Province?',
262
+			'event_espresso'
263
+		);
264
+		$protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
265
+		EE_Registry::$i18n_js_strings['ajax_url'] = admin_url(
266
+			'admin-ajax.php?page=espresso_general_settings',
267
+			$protocol
268
+		);
269
+	}
270
+
271
+
272
+	public function admin_notices()
273
+	{
274
+	}
275
+
276
+
277
+	public function admin_footer_scripts()
278
+	{
279
+	}
280
+
281
+
282
+	/**
283
+	 * Enqueue scripts and styles for the default route.
284
+	 */
285
+	public function load_scripts_styles_default()
286
+	{
287
+		// styles
288
+		wp_enqueue_style('thickbox');
289
+		// scripts
290
+		wp_enqueue_script('media-upload');
291
+		wp_enqueue_script('thickbox');
292
+		wp_register_script(
293
+			'organization_settings',
294
+			GEN_SET_ASSETS_URL . 'your_organization_settings.js',
295
+			array('jquery', 'media-upload', 'thickbox'),
296
+			EVENT_ESPRESSO_VERSION,
297
+			true
298
+		);
299
+		wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION);
300
+		wp_enqueue_script('organization_settings');
301
+		wp_enqueue_style('organization-css');
302
+		$confirm_image_delete = array(
303
+			'text' => __(
304
+				'Do you really want to delete this image? Please remember to save your settings to complete the removal.',
305
+				'event_espresso'
306
+			),
307
+		);
308
+		wp_localize_script('organization_settings', 'confirm_image_delete', $confirm_image_delete);
309
+	}
310
+
311
+
312
+	/**
313
+	 * Enqueue scripts and styles for the country settings route.
314
+	 */
315
+	public function load_scripts_styles_country_settings()
316
+	{
317
+		// scripts
318
+		wp_register_script(
319
+			'gen_settings_countries',
320
+			GEN_SET_ASSETS_URL . 'gen_settings_countries.js',
321
+			array('ee_admin_js'),
322
+			EVENT_ESPRESSO_VERSION,
323
+			true
324
+		);
325
+		wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION);
326
+		wp_enqueue_script('gen_settings_countries');
327
+		wp_enqueue_style('organization-css');
328
+	}
329
+
330
+
331
+	/*************        Espresso Pages        *************/
332
+	/**
333
+	 * _espresso_page_settings
334
+	 *
335
+	 * @throws \EE_Error
336
+	 * @throws DomainException
337
+	 * @throws DomainException
338
+	 * @throws InvalidDataTypeException
339
+	 * @throws InvalidArgumentException
340
+	 */
341
+	protected function _espresso_page_settings()
342
+	{
343
+		// Check to make sure all of the main pages are setup properly,
344
+		// if not create the default pages and display an admin notice
345
+		EEH_Activation::verify_default_pages_exist();
346
+		$this->_transient_garbage_collection();
347
+		$this->_template_args['values'] = $this->_yes_no_values;
348
+		$this->_template_args['reg_page_id'] = isset(EE_Registry::instance()->CFG->core->reg_page_id)
349
+			? EE_Registry::instance()->CFG->core->reg_page_id
350
+			: null;
351
+		$this->_template_args['reg_page_obj'] = isset(EE_Registry::instance()->CFG->core->reg_page_id)
352
+			? get_page(EE_Registry::instance()->CFG->core->reg_page_id)
353
+			: false;
354
+		$this->_template_args['txn_page_id'] = isset(EE_Registry::instance()->CFG->core->txn_page_id)
355
+			? EE_Registry::instance()->CFG->core->txn_page_id
356
+			: null;
357
+		$this->_template_args['txn_page_obj'] = isset(EE_Registry::instance()->CFG->core->txn_page_id)
358
+			? get_page(EE_Registry::instance()->CFG->core->txn_page_id)
359
+			: false;
360
+		$this->_template_args['thank_you_page_id'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id)
361
+			? EE_Registry::instance()->CFG->core->thank_you_page_id
362
+			: null;
363
+		$this->_template_args['thank_you_page_obj'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id)
364
+			? get_page(EE_Registry::instance()->CFG->core->thank_you_page_id)
365
+			: false;
366
+		$this->_template_args['cancel_page_id'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id)
367
+			? EE_Registry::instance()->CFG->core->cancel_page_id
368
+			: null;
369
+		$this->_template_args['cancel_page_obj'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id)
370
+			? get_page(EE_Registry::instance()->CFG->core->cancel_page_id)
371
+			: false;
372
+		$this->_set_add_edit_form_tags('update_espresso_page_settings');
373
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
374
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
375
+			GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php',
376
+			$this->_template_args,
377
+			true
378
+		);
379
+		$this->display_admin_page_with_sidebar();
380
+	}
381
+
382
+
383
+	/**
384
+	 * Handler for updating espresso page settings.
385
+	 *
386
+	 * @throws EE_Error
387
+	 */
388
+	protected function _update_espresso_page_settings()
389
+	{
390
+		// capture incoming request data && set page IDs
391
+		EE_Registry::instance()->CFG->core->reg_page_id = isset($this->_req_data['reg_page_id'])
392
+			? absint($this->_req_data['reg_page_id'])
393
+			: EE_Registry::instance()->CFG->core->reg_page_id;
394
+		EE_Registry::instance()->CFG->core->txn_page_id = isset($this->_req_data['txn_page_id'])
395
+			? absint($this->_req_data['txn_page_id'])
396
+			: EE_Registry::instance()->CFG->core->txn_page_id;
397
+		EE_Registry::instance()->CFG->core->thank_you_page_id = isset($this->_req_data['thank_you_page_id'])
398
+			? absint($this->_req_data['thank_you_page_id'])
399
+			: EE_Registry::instance()->CFG->core->thank_you_page_id;
400
+		EE_Registry::instance()->CFG->core->cancel_page_id = isset($this->_req_data['cancel_page_id'])
401
+			? absint($this->_req_data['cancel_page_id'])
402
+			: EE_Registry::instance()->CFG->core->cancel_page_id;
403
+
404
+		EE_Registry::instance()->CFG->core = apply_filters(
405
+			'FHEE__General_Settings_Admin_Page___update_espresso_page_settings__CFG_core',
406
+			EE_Registry::instance()->CFG->core,
407
+			$this->_req_data
408
+		);
409
+		$what = __('Critical Pages & Shortcodes', 'event_espresso');
410
+		$this->_redirect_after_action(
411
+			$this->_update_espresso_configuration(
412
+				$what,
413
+				EE_Registry::instance()->CFG->core,
414
+				__FILE__,
415
+				__FUNCTION__,
416
+				__LINE__
417
+			),
418
+			$what,
419
+			'',
420
+			array(
421
+				'action' => 'critical_pages',
422
+			),
423
+			true
424
+		);
425
+	}
426
+
427
+
428
+	/*************        Your Organization        *************/
429
+
430
+
431
+	/**
432
+	 * @throws DomainException
433
+	 * @throws EE_Error
434
+	 * @throws InvalidArgumentException
435
+	 * @throws InvalidDataTypeException
436
+	 * @throws InvalidInterfaceException
437
+	 */
438
+	protected function _your_organization_settings()
439
+	{
440
+		$this->_template_args['admin_page_content'] = '';
441
+		try {
442
+			/** @var EventEspresso\admin_pages\general_settings\OrganizationSettings $organization_settings_form */
443
+			$organization_settings_form = $this->loader->getShared(
444
+				'EventEspresso\admin_pages\general_settings\OrganizationSettings'
445
+			);
446
+			$this->_template_args['admin_page_content'] = $organization_settings_form->display();
447
+		} catch (Exception $e) {
448
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
449
+		}
450
+		$this->_set_add_edit_form_tags('update_your_organization_settings');
451
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
452
+		$this->display_admin_page_with_sidebar();
453
+	}
454
+
455
+
456
+	/**
457
+	 * Handler for updating organization settings.
458
+	 *
459
+	 * @throws EE_Error
460
+	 */
461
+	protected function _update_your_organization_settings()
462
+	{
463
+		try {
464
+			/** @var EventEspresso\admin_pages\general_settings\OrganizationSettings $organization_settings_form */
465
+			$organization_settings_form = $this->loader->getShared(
466
+				'EventEspresso\admin_pages\general_settings\OrganizationSettings'
467
+			);
468
+			$success = $organization_settings_form->process($this->_req_data);
469
+			EE_Registry::instance()->CFG = apply_filters(
470
+				'FHEE__General_Settings_Admin_Page___update_your_organization_settings__CFG',
471
+				EE_Registry::instance()->CFG
472
+			);
473
+		} catch (Exception $e) {
474
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
475
+			$success = false;
476
+		}
477
+
478
+		if ($success) {
479
+			$success = $this->_update_espresso_configuration(
480
+				esc_html__('Your Organization Settings', 'event_espresso'),
481
+				EE_Registry::instance()->CFG,
482
+				__FILE__,
483
+				__FUNCTION__,
484
+				__LINE__
485
+			);
486
+		}
487
+
488
+		$this->_redirect_after_action($success, '', '', array('action' => 'default'), true);
489
+	}
490
+
491
+
492
+
493
+	/*************        Admin Options        *************/
494
+
495
+
496
+	/**
497
+	 * _admin_option_settings
498
+	 *
499
+	 * @throws \EE_Error
500
+	 * @throws \LogicException
501
+	 */
502
+	protected function _admin_option_settings()
503
+	{
504
+		$this->_template_args['admin_page_content'] = '';
505
+		try {
506
+			$admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
507
+			// still need this for the old school form in Extend_General_Settings_Admin_Page
508
+			$this->_template_args['values'] = $this->_yes_no_values;
509
+			// also need to account for the do_action that was in the old template
510
+			$admin_options_settings_form->setTemplateArgs($this->_template_args);
511
+			$this->_template_args['admin_page_content'] = $admin_options_settings_form->display();
512
+		} catch (Exception $e) {
513
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
514
+		}
515
+		$this->_set_add_edit_form_tags('update_admin_option_settings');
516
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
517
+		$this->display_admin_page_with_sidebar();
518
+	}
519
+
520
+
521
+	/**
522
+	 * _update_admin_option_settings
523
+	 *
524
+	 * @throws \EE_Error
525
+	 * @throws InvalidDataTypeException
526
+	 * @throws \EventEspresso\core\exceptions\InvalidFormSubmissionException
527
+	 * @throws \InvalidArgumentException
528
+	 * @throws \LogicException
529
+	 */
530
+	protected function _update_admin_option_settings()
531
+	{
532
+		try {
533
+			$admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
534
+			$admin_options_settings_form->process($this->_req_data[ $admin_options_settings_form->slug() ]);
535
+			EE_Registry::instance()->CFG->admin = apply_filters(
536
+				'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin',
537
+				EE_Registry::instance()->CFG->admin
538
+			);
539
+		} catch (Exception $e) {
540
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
541
+		}
542
+		$this->_redirect_after_action(
543
+			apply_filters(
544
+				'FHEE__General_Settings_Admin_Page___update_admin_option_settings__success',
545
+				$this->_update_espresso_configuration(
546
+					'Admin Options',
547
+					EE_Registry::instance()->CFG->admin,
548
+					__FILE__,
549
+					__FUNCTION__,
550
+					__LINE__
551
+				)
552
+			),
553
+			'Admin Options',
554
+			'updated',
555
+			array('action' => 'admin_option_settings')
556
+		);
557
+	}
558
+
559
+
560
+	/*************        Countries        *************/
561
+
562
+
563
+	/**
564
+	 * @return string
565
+	 */
566
+	protected function getCountryIsoForSite()
567
+	{
568
+		return ! empty(EE_Registry::instance()->CFG->organization->CNT_ISO)
569
+			? EE_Registry::instance()->CFG->organization->CNT_ISO
570
+			: 'US';
571
+	}
572
+
573
+
574
+	/**
575
+	 * @param string          $CNT_ISO
576
+	 * @param EE_Country|null $country
577
+	 * @return EE_Base_Class|EE_Country
578
+	 * @throws EE_Error
579
+	 * @throws InvalidArgumentException
580
+	 * @throws InvalidDataTypeException
581
+	 * @throws InvalidInterfaceException
582
+	 * @throws ReflectionException
583
+	 */
584
+	protected function verifyOrGetCountryFromIso($CNT_ISO, EE_Country $country = null)
585
+	{
586
+		/** @var EE_Country $country */
587
+		return $country instanceof EE_Country && $country->ID() === $CNT_ISO
588
+			? $country
589
+			: EEM_Country::instance()->get_one_by_ID($CNT_ISO);
590
+	}
591
+
592
+
593
+	/**
594
+	 * Output Country Settings view.
595
+	 *
596
+	 * @throws DomainException
597
+	 * @throws EE_Error
598
+	 * @throws InvalidArgumentException
599
+	 * @throws InvalidDataTypeException
600
+	 * @throws InvalidInterfaceException
601
+	 * @throws ReflectionException
602
+	 */
603
+	protected function _country_settings()
604
+	{
605
+		$CNT_ISO_for_site = $this->getCountryIsoForSite();
606
+		$CNT_ISO = isset($this->_req_data['country'])
607
+			? strtoupper(sanitize_text_field($this->_req_data['country']))
608
+			: $CNT_ISO_for_site;
609
+
610
+		// load field generator helper
611
+
612
+		$this->_template_args['values'] = $this->_yes_no_values;
613
+
614
+		$this->_template_args['countries'] = new EE_Question_Form_Input(
615
+			EE_Question::new_instance(
616
+				array(
617
+					'QST_ID'           => 0,
618
+					'QST_display_text' => __('Select Country', 'event_espresso'),
619
+					'QST_system'       => 'admin-country',
620
+				)
621
+			),
622
+			EE_Answer::new_instance(
623
+				array(
624
+					'ANS_ID'    => 0,
625
+					'ANS_value' => $CNT_ISO,
626
+				)
627
+			),
628
+			array(
629
+				'input_id'       => 'country',
630
+				'input_name'     => 'country',
631
+				'input_prefix'   => '',
632
+				'append_qstn_id' => false,
633
+			)
634
+		);
635
+		$country = $this->verifyOrGetCountryFromIso($CNT_ISO_for_site);
636
+		add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2);
637
+		add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2);
638
+		$this->_template_args['country_details_settings'] = $this->display_country_settings(
639
+			$country->ID(),
640
+			$country
641
+		);
642
+		$this->_template_args['country_states_settings'] = $this->display_country_states(
643
+			$country->ID(),
644
+			$country
645
+		);
646
+		$this->_template_args['CNT_name_for_site'] = $country->name();
647
+
648
+		$this->_set_add_edit_form_tags('update_country_settings');
649
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
650
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
651
+			GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php',
652
+			$this->_template_args,
653
+			true
654
+		);
655
+		$this->display_admin_page_with_no_sidebar();
656
+	}
657
+
658
+
659
+	/**
660
+	 *        display_country_settings
661
+	 *
662
+	 * @param string          $CNT_ISO
663
+	 * @param EE_Country|null $country
664
+	 * @return mixed string | array$country
665
+	 * @throws DomainException
666
+	 * @throws EE_Error
667
+	 * @throws InvalidArgumentException
668
+	 * @throws InvalidDataTypeException
669
+	 * @throws InvalidInterfaceException
670
+	 * @throws ReflectionException
671
+	 */
672
+	public function display_country_settings($CNT_ISO = '', EE_Country $country = null)
673
+	{
674
+		$CNT_ISO_for_site = $this->getCountryIsoForSite();
675
+
676
+		$CNT_ISO = isset($this->_req_data['country'])
677
+			? strtoupper(sanitize_text_field($this->_req_data['country']))
678
+			: $CNT_ISO;
679
+		if (! $CNT_ISO) {
680
+			return '';
681
+		}
682
+
683
+		// for ajax
684
+		remove_all_filters('FHEE__EEH_Form_Fields__label_html');
685
+		remove_all_filters('FHEE__EEH_Form_Fields__input_html');
686
+		add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2);
687
+		add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2);
688
+		$country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country);
689
+		$CNT_cur_disabled = $CNT_ISO !== $CNT_ISO_for_site;
690
+		$this->_template_args['CNT_cur_disabled'] = $CNT_cur_disabled;
691
+
692
+		$country_input_types = array(
693
+			'CNT_active'      => array(
694
+				'type'             => 'RADIO_BTN',
695
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
696
+				'class'            => '',
697
+				'options'          => $this->_yes_no_values,
698
+				'use_desc_4_label' => true,
699
+			),
700
+			'CNT_ISO'         => array(
701
+				'type'       => 'TEXT',
702
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
703
+				'class'      => 'small-text',
704
+			),
705
+			'CNT_ISO3'        => array(
706
+				'type'       => 'TEXT',
707
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
708
+				'class'      => 'small-text',
709
+			),
710
+			'RGN_ID'          => array(
711
+				'type'       => 'TEXT',
712
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
713
+				'class'      => 'small-text',
714
+			),
715
+			'CNT_name'        => array(
716
+				'type'       => 'TEXT',
717
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
718
+				'class'      => 'regular-text',
719
+			),
720
+			'CNT_cur_code'    => array(
721
+				'type'       => 'TEXT',
722
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
723
+				'class'      => 'small-text',
724
+				'disabled'   => $CNT_cur_disabled,
725
+			),
726
+			'CNT_cur_single'  => array(
727
+				'type'       => 'TEXT',
728
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
729
+				'class'      => 'medium-text',
730
+				'disabled'   => $CNT_cur_disabled,
731
+			),
732
+			'CNT_cur_plural'  => array(
733
+				'type'       => 'TEXT',
734
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
735
+				'class'      => 'medium-text',
736
+				'disabled'   => $CNT_cur_disabled,
737
+			),
738
+			'CNT_cur_sign'    => array(
739
+				'type'         => 'TEXT',
740
+				'input_name'   => 'cntry[' . $CNT_ISO . ']',
741
+				'class'        => 'small-text',
742
+				'htmlentities' => false,
743
+				'disabled'     => $CNT_cur_disabled,
744
+			),
745
+			'CNT_cur_sign_b4' => array(
746
+				'type'             => 'RADIO_BTN',
747
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
748
+				'class'            => '',
749
+				'options'          => $this->_yes_no_values,
750
+				'use_desc_4_label' => true,
751
+				'disabled'         => $CNT_cur_disabled,
752
+			),
753
+			'CNT_cur_dec_plc' => array(
754
+				'type'       => 'RADIO_BTN',
755
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
756
+				'class'      => '',
757
+				'options'    => array(
758
+					array('id' => 0, 'text' => ''),
759
+					array('id' => 1, 'text' => ''),
760
+					array('id' => 2, 'text' => ''),
761
+					array('id' => 3, 'text' => ''),
762
+				),
763
+				'disabled'   => $CNT_cur_disabled,
764
+			),
765
+			'CNT_cur_dec_mrk' => array(
766
+				'type'             => 'RADIO_BTN',
767
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
768
+				'class'            => '',
769
+				'options'          => array(
770
+					array(
771
+						'id'   => ',',
772
+						'text' => __(', (comma)', 'event_espresso'),
773
+					),
774
+					array('id' => '.', 'text' => __('. (decimal)', 'event_espresso')),
775
+				),
776
+				'use_desc_4_label' => true,
777
+				'disabled'         => $CNT_cur_disabled,
778
+			),
779
+			'CNT_cur_thsnds'  => array(
780
+				'type'             => 'RADIO_BTN',
781
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
782
+				'class'            => '',
783
+				'options'          => array(
784
+					array(
785
+						'id'   => ',',
786
+						'text' => __(', (comma)', 'event_espresso'),
787
+					),
788
+					array('id' => '.', 'text' => __('. (decimal)', 'event_espresso')),
789
+				),
790
+				'use_desc_4_label' => true,
791
+				'disabled'         => $CNT_cur_disabled,
792
+			),
793
+			'CNT_tel_code'    => array(
794
+				'type'       => 'TEXT',
795
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
796
+				'class'      => 'small-text',
797
+			),
798
+			'CNT_is_EU'       => array(
799
+				'type'             => 'RADIO_BTN',
800
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
801
+				'class'            => '',
802
+				'options'          => $this->_yes_no_values,
803
+				'use_desc_4_label' => true,
804
+			),
805
+		);
806
+		$this->_template_args['inputs'] = EE_Question_Form_Input::generate_question_form_inputs_for_object(
807
+			$country,
808
+			$country_input_types
809
+		);
810
+		$country_details_settings = EEH_Template::display_template(
811
+			GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php',
812
+			$this->_template_args,
813
+			true
814
+		);
815
+
816
+		if (defined('DOING_AJAX')) {
817
+			$notices = EE_Error::get_notices(false, false, false);
818
+			echo wp_json_encode(
819
+				array(
820
+					'return_data' => $country_details_settings,
821
+					'success'     => $notices['success'],
822
+					'errors'      => $notices['errors'],
823
+				)
824
+			);
825
+			die();
826
+		} else {
827
+			return $country_details_settings;
828
+		}
829
+	}
830
+
831
+
832
+	/**
833
+	 * @param string          $CNT_ISO
834
+	 * @param EE_Country|null $country
835
+	 * @return string
836
+	 * @throws DomainException
837
+	 * @throws EE_Error
838
+	 * @throws InvalidArgumentException
839
+	 * @throws InvalidDataTypeException
840
+	 * @throws InvalidInterfaceException
841
+	 * @throws ReflectionException
842
+	 */
843
+	public function display_country_states($CNT_ISO = '', EE_Country $country = null)
844
+	{
845
+
846
+		$CNT_ISO = isset($this->_req_data['country'])
847
+			? sanitize_text_field($this->_req_data['country'])
848
+			: $CNT_ISO;
849
+		if (! $CNT_ISO) {
850
+			return '';
851
+		}
852
+		// for ajax
853
+		remove_all_filters('FHEE__EEH_Form_Fields__label_html');
854
+		remove_all_filters('FHEE__EEH_Form_Fields__input_html');
855
+		add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'state_form_field_label_wrap'), 10, 2);
856
+		add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'state_form_field_input__wrap'), 10, 2);
857
+		$states = EEM_State::instance()->get_all_states_for_these_countries(array($CNT_ISO => $CNT_ISO));
858
+		if (empty($states)) {
859
+			/** @var EventEspresso\core\services\address\CountrySubRegionDao $countrySubRegionDao */
860
+			$countrySubRegionDao = $this->loader->getShared(
861
+				'EventEspresso\core\services\address\CountrySubRegionDao'
862
+			);
863
+			if ($countrySubRegionDao instanceof EventEspresso\core\services\address\CountrySubRegionDao) {
864
+				$country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country);
865
+				if ($countrySubRegionDao->saveCountrySubRegions($country)) {
866
+					$states = EEM_State::instance()->get_all_states_for_these_countries(
867
+						array($CNT_ISO => $CNT_ISO)
868
+					);
869
+				}
870
+			}
871
+		}
872
+		if (is_array($states)) {
873
+			foreach ($states as $STA_ID => $state) {
874
+				if ($state instanceof EE_State) {
875
+					// STA_abbrev    STA_name    STA_active
876
+					$state_input_types = array(
877
+						'STA_abbrev' => array(
878
+							'type'       => 'TEXT',
879
+							'input_name' => 'states[' . $STA_ID . ']',
880
+							'class'      => 'mid-text',
881
+						),
882
+						'STA_name'   => array(
883
+							'type'       => 'TEXT',
884
+							'input_name' => 'states[' . $STA_ID . ']',
885
+							'class'      => 'regular-text',
886
+						),
887
+						'STA_active' => array(
888
+							'type'             => 'RADIO_BTN',
889
+							'input_name'       => 'states[' . $STA_ID . ']',
890
+							'options'          => $this->_yes_no_values,
891
+							'use_desc_4_label' => true,
892
+						),
893
+					);
894
+					$this->_template_args['states'][ $STA_ID ]['inputs'] =
895
+						EE_Question_Form_Input::generate_question_form_inputs_for_object(
896
+							$state,
897
+							$state_input_types
898
+						);
899
+					$query_args = array(
900
+						'action'     => 'delete_state',
901
+						'STA_ID'     => $STA_ID,
902
+						'CNT_ISO'    => $CNT_ISO,
903
+						'STA_abbrev' => $state->abbrev(),
904
+					);
905
+					$this->_template_args['states'][ $STA_ID ]['delete_state_url'] =
906
+						EE_Admin_Page::add_query_args_and_nonce(
907
+							$query_args,
908
+							GEN_SET_ADMIN_URL
909
+						);
910
+				}
911
+			}
912
+		} else {
913
+			$this->_template_args['states'] = false;
914
+		}
915
+
916
+		$this->_template_args['add_new_state_url'] = EE_Admin_Page::add_query_args_and_nonce(
917
+			array('action' => 'add_new_state'),
918
+			GEN_SET_ADMIN_URL
919
+		);
920
+
921
+		$state_details_settings = EEH_Template::display_template(
922
+			GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php',
923
+			$this->_template_args,
924
+			true
925
+		);
926
+
927
+		if (defined('DOING_AJAX')) {
928
+			$notices = EE_Error::get_notices(false, false, false);
929
+			echo wp_json_encode(
930
+				array(
931
+					'return_data' => $state_details_settings,
932
+					'success'     => $notices['success'],
933
+					'errors'      => $notices['errors'],
934
+				)
935
+			);
936
+			die();
937
+		} else {
938
+			return $state_details_settings;
939
+		}
940
+	}
941
+
942
+
943
+	/**
944
+	 *        add_new_state
945
+	 *
946
+	 * @access    public
947
+	 * @return void
948
+	 * @throws EE_Error
949
+	 * @throws InvalidArgumentException
950
+	 * @throws InvalidDataTypeException
951
+	 * @throws InvalidInterfaceException
952
+	 */
953
+	public function add_new_state()
954
+	{
955
+
956
+		$success = true;
957
+
958
+		$CNT_ISO = isset($this->_req_data['CNT_ISO'])
959
+			? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO']))
960
+			: false;
961
+		if (! $CNT_ISO) {
962
+			EE_Error::add_error(
963
+				__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
964
+				__FILE__,
965
+				__FUNCTION__,
966
+				__LINE__
967
+			);
968
+			$success = false;
969
+		}
970
+		$STA_abbrev = isset($this->_req_data['STA_abbrev'])
971
+			? sanitize_text_field($this->_req_data['STA_abbrev'])
972
+			: false;
973
+		if (! $STA_abbrev) {
974
+			EE_Error::add_error(
975
+				__('No State ISO code or an invalid State ISO code was received.', 'event_espresso'),
976
+				__FILE__,
977
+				__FUNCTION__,
978
+				__LINE__
979
+			);
980
+			$success = false;
981
+		}
982
+		$STA_name = isset($this->_req_data['STA_name'])
983
+			? sanitize_text_field($this->_req_data['STA_name'])
984
+			: false;
985
+		if (! $STA_name) {
986
+			EE_Error::add_error(
987
+				__('No State name or an invalid State name was received.', 'event_espresso'),
988
+				__FILE__,
989
+				__FUNCTION__,
990
+				__LINE__
991
+			);
992
+			$success = false;
993
+		}
994
+
995
+		if ($success) {
996
+			$cols_n_values = array(
997
+				'CNT_ISO'    => $CNT_ISO,
998
+				'STA_abbrev' => $STA_abbrev,
999
+				'STA_name'   => $STA_name,
1000
+				'STA_active' => true,
1001
+			);
1002
+			$success = EEM_State::instance()->insert($cols_n_values);
1003
+			EE_Error::add_success(__('The State was added successfully.', 'event_espresso'));
1004
+		}
1005
+
1006
+		if (defined('DOING_AJAX')) {
1007
+			$notices = EE_Error::get_notices(false, false, false);
1008
+			echo wp_json_encode(array_merge($notices, array('return_data' => $CNT_ISO)));
1009
+			die();
1010
+		} else {
1011
+			$this->_redirect_after_action($success, 'State', 'added', array('action' => 'country_settings'));
1012
+		}
1013
+	}
1014
+
1015
+
1016
+	/**
1017
+	 *        delete_state
1018
+	 *
1019
+	 * @access    public
1020
+	 * @return        boolean
1021
+	 * @throws EE_Error
1022
+	 * @throws InvalidArgumentException
1023
+	 * @throws InvalidDataTypeException
1024
+	 * @throws InvalidInterfaceException
1025
+	 */
1026
+	public function delete_state()
1027
+	{
1028
+		$CNT_ISO = isset($this->_req_data['CNT_ISO'])
1029
+			? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO']))
1030
+			: false;
1031
+		$STA_ID = isset($this->_req_data['STA_ID'])
1032
+			? sanitize_text_field($this->_req_data['STA_ID'])
1033
+			: false;
1034
+		$STA_abbrev = isset($this->_req_data['STA_abbrev'])
1035
+			? sanitize_text_field($this->_req_data['STA_abbrev'])
1036
+			: false;
1037
+		if (! $STA_ID) {
1038
+			EE_Error::add_error(
1039
+				__('No State ID or an invalid State ID was received.', 'event_espresso'),
1040
+				__FILE__,
1041
+				__FUNCTION__,
1042
+				__LINE__
1043
+			);
1044
+			return false;
1045
+		}
1046
+
1047
+		$success = EEM_State::instance()->delete_by_ID($STA_ID);
1048
+		if ($success !== false) {
1049
+			do_action(
1050
+				'AHEE__General_Settings_Admin_Page__delete_state__state_deleted',
1051
+				$CNT_ISO,
1052
+				$STA_ID,
1053
+				array('STA_abbrev' => $STA_abbrev)
1054
+			);
1055
+			EE_Error::add_success(__('The State was deleted successfully.', 'event_espresso'));
1056
+		}
1057
+		if (defined('DOING_AJAX')) {
1058
+			$notices = EE_Error::get_notices(false, false);
1059
+			$notices['return_data'] = true;
1060
+			echo wp_json_encode($notices);
1061
+			die();
1062
+		} else {
1063
+			$this->_redirect_after_action(
1064
+				$success,
1065
+				'State',
1066
+				'deleted',
1067
+				array('action' => 'country_settings')
1068
+			);
1069
+		}
1070
+	}
1071
+
1072
+
1073
+	/**
1074
+	 *        _update_country_settings
1075
+	 *
1076
+	 * @access    protected
1077
+	 * @return void
1078
+	 * @throws EE_Error
1079
+	 * @throws InvalidArgumentException
1080
+	 * @throws InvalidDataTypeException
1081
+	 * @throws InvalidInterfaceException
1082
+	 */
1083
+	protected function _update_country_settings()
1084
+	{
1085
+		// grab the country ISO code
1086
+		$CNT_ISO = isset($this->_req_data['country'])
1087
+			? strtoupper(sanitize_text_field($this->_req_data['country']))
1088
+			: false;
1089
+		if (! $CNT_ISO) {
1090
+			EE_Error::add_error(
1091
+				__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
1092
+				__FILE__,
1093
+				__FUNCTION__,
1094
+				__LINE__
1095
+			);
1096
+
1097
+			return;
1098
+		}
1099
+		$cols_n_values = array();
1100
+		$cols_n_values['CNT_ISO3'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3'])
1101
+			? strtoupper(sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3']))
1102
+			: false;
1103
+		$cols_n_values['RGN_ID'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID'])
1104
+			? absint($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID'])
1105
+			: null;
1106
+		$cols_n_values['CNT_name'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name'])
1107
+			? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name'])
1108
+			: null;
1109
+		if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code'])) {
1110
+			$cols_n_values['CNT_cur_code'] = strtoupper(
1111
+				sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code'])
1112
+			);
1113
+		}
1114
+		if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single'])) {
1115
+			$cols_n_values['CNT_cur_single'] = sanitize_text_field(
1116
+				$this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single']
1117
+			);
1118
+		}
1119
+		if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural'])) {
1120
+			$cols_n_values['CNT_cur_plural'] = sanitize_text_field(
1121
+				$this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural']
1122
+			);
1123
+		}
1124
+		if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign'])) {
1125
+			$cols_n_values['CNT_cur_sign'] = sanitize_text_field(
1126
+				$this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign']
1127
+			);
1128
+		}
1129
+		if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4'])) {
1130
+			$cols_n_values['CNT_cur_sign_b4'] = absint(
1131
+				$this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4']
1132
+			);
1133
+		}
1134
+		if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc'])) {
1135
+			$cols_n_values['CNT_cur_dec_plc'] = absint(
1136
+				$this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc']
1137
+			);
1138
+		}
1139
+		if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk'])) {
1140
+			$cols_n_values['CNT_cur_dec_mrk'] = sanitize_text_field(
1141
+				$this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk']
1142
+			);
1143
+		}
1144
+		if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds'])) {
1145
+			$cols_n_values['CNT_cur_thsnds'] = sanitize_text_field(
1146
+				$this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds']
1147
+			);
1148
+		}
1149
+		$cols_n_values['CNT_tel_code'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code'])
1150
+			? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code'])
1151
+			: null;
1152
+		$cols_n_values['CNT_is_EU'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU'])
1153
+			? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU'])
1154
+			: false;
1155
+		$cols_n_values['CNT_active'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active'])
1156
+			? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active'])
1157
+			: false;
1158
+		// allow filtering of country data
1159
+		$cols_n_values = apply_filters(
1160
+			'FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values',
1161
+			$cols_n_values
1162
+		);
1163
+
1164
+		// where values
1165
+		$where_cols_n_values = array(array('CNT_ISO' => $CNT_ISO));
1166
+		// run the update
1167
+		$success = EEM_Country::instance()->update($cols_n_values, $where_cols_n_values);
1168
+
1169
+		if (isset($this->_req_data['states']) && is_array($this->_req_data['states']) && $success !== false) {
1170
+			// allow filtering of states data
1171
+			$states = apply_filters(
1172
+				'FHEE__General_Settings_Admin_Page___update_country_settings__states',
1173
+				$this->_req_data['states']
1174
+			);
1175
+
1176
+			// loop thru state data ( looks like : states[75][STA_name] )
1177
+			foreach ($states as $STA_ID => $state) {
1178
+				$cols_n_values = array(
1179
+					'CNT_ISO'    => $CNT_ISO,
1180
+					'STA_abbrev' => sanitize_text_field($state['STA_abbrev']),
1181
+					'STA_name'   => sanitize_text_field($state['STA_name']),
1182
+					'STA_active' => (bool) absint($state['STA_active']),
1183
+				);
1184
+				// where values
1185
+				$where_cols_n_values = array(array('STA_ID' => $STA_ID));
1186
+				// run the update
1187
+				$success = EEM_State::instance()->update($cols_n_values, $where_cols_n_values);
1188
+				if ($success !== false) {
1189
+					do_action(
1190
+						'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved',
1191
+						$CNT_ISO,
1192
+						$STA_ID,
1193
+						$cols_n_values
1194
+					);
1195
+				}
1196
+			}
1197
+		}
1198
+		// check if country being edited matches org option country, and if so, then  update EE_Config with new settings
1199
+		if (isset(EE_Registry::instance()->CFG->organization->CNT_ISO)
1200
+			&& $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO
1201
+		) {
1202
+			EE_Registry::instance()->CFG->currency = new EE_Currency_Config($CNT_ISO);
1203
+			EE_Registry::instance()->CFG->update_espresso_config();
1204
+		}
1205
+
1206
+		if ($success !== false) {
1207
+			EE_Error::add_success(
1208
+				esc_html__('Country Settings updated successfully.', 'event_espresso')
1209
+			);
1210
+		}
1211
+		$this->_redirect_after_action(
1212
+			$success,
1213
+			'',
1214
+			'',
1215
+			array('action' => 'country_settings', 'country' => $CNT_ISO),
1216
+			true
1217
+		);
1218
+	}
1219
+
1220
+
1221
+	/**
1222
+	 *        form_form_field_label_wrap
1223
+	 *
1224
+	 * @access        public
1225
+	 * @param        string $label
1226
+	 * @return        string
1227
+	 */
1228
+	public function country_form_field_label_wrap($label, $required_text)
1229
+	{
1230
+		return '
1231 1231
 			<tr>
1232 1232
 				<th>
1233 1233
 					' . $label . '
1234 1234
 				</th>';
1235
-    }
1236
-
1237
-
1238
-    /**
1239
-     *        form_form_field_input__wrap
1240
-     *
1241
-     * @access        public
1242
-     * @param        string $label
1243
-     * @return        string
1244
-     */
1245
-    public function country_form_field_input__wrap($input, $label)
1246
-    {
1247
-        return '
1235
+	}
1236
+
1237
+
1238
+	/**
1239
+	 *        form_form_field_input__wrap
1240
+	 *
1241
+	 * @access        public
1242
+	 * @param        string $label
1243
+	 * @return        string
1244
+	 */
1245
+	public function country_form_field_input__wrap($input, $label)
1246
+	{
1247
+		return '
1248 1248
 				<td class="general-settings-country-input-td">
1249 1249
 					' . $input . '
1250 1250
 				</td>
1251 1251
 			</tr>';
1252
-    }
1253
-
1254
-
1255
-    /**
1256
-     *        form_form_field_label_wrap
1257
-     *
1258
-     * @access        public
1259
-     * @param        string $label
1260
-     * @param        string $required_text
1261
-     * @return        string
1262
-     */
1263
-    public function state_form_field_label_wrap($label, $required_text)
1264
-    {
1265
-        return $required_text;
1266
-    }
1267
-
1268
-
1269
-    /**
1270
-     *        form_form_field_input__wrap
1271
-     *
1272
-     * @access        public
1273
-     * @param        string $label
1274
-     * @return        string
1275
-     */
1276
-    public function state_form_field_input__wrap($input, $label)
1277
-    {
1278
-        return '
1252
+	}
1253
+
1254
+
1255
+	/**
1256
+	 *        form_form_field_label_wrap
1257
+	 *
1258
+	 * @access        public
1259
+	 * @param        string $label
1260
+	 * @param        string $required_text
1261
+	 * @return        string
1262
+	 */
1263
+	public function state_form_field_label_wrap($label, $required_text)
1264
+	{
1265
+		return $required_text;
1266
+	}
1267
+
1268
+
1269
+	/**
1270
+	 *        form_form_field_input__wrap
1271
+	 *
1272
+	 * @access        public
1273
+	 * @param        string $label
1274
+	 * @return        string
1275
+	 */
1276
+	public function state_form_field_input__wrap($input, $label)
1277
+	{
1278
+		return '
1279 1279
 				<td class="general-settings-country-state-input-td">
1280 1280
 					' . $input . '
1281 1281
 				</td>';
1282
-    }
1283
-
1284
-
1285
-    /***********/
1286
-
1287
-
1288
-    /**
1289
-     * displays edit and view links for critical EE pages
1290
-     *
1291
-     * @access public
1292
-     * @param int $ee_page_id
1293
-     * @return string
1294
-     */
1295
-    public static function edit_view_links($ee_page_id)
1296
-    {
1297
-        $links = '<a href="'
1298
-                 . add_query_arg(
1299
-                     array('post' => $ee_page_id, 'action' => 'edit'),
1300
-                     admin_url('post.php')
1301
-                 )
1302
-                 . '" >'
1303
-                 . __('Edit', 'event_espresso')
1304
-                 . '</a>';
1305
-        $links .= ' &nbsp;|&nbsp; ';
1306
-        $links .= '<a href="' . get_permalink($ee_page_id) . '" >' . __('View', 'event_espresso') . '</a>';
1307
-
1308
-        return $links;
1309
-    }
1310
-
1311
-
1312
-    /**
1313
-     * displays page and shortcode status for critical EE pages
1314
-     *
1315
-     * @param WP page object $ee_page
1316
-     * @return string
1317
-     */
1318
-    public static function page_and_shortcode_status($ee_page, $shortcode)
1319
-    {
1320
-
1321
-        // page status
1322
-        if (isset($ee_page->post_status) && $ee_page->post_status == 'publish') {
1323
-            $pg_colour = 'green';
1324
-            $pg_status = sprintf(__('Page%sStatus%sOK', 'event_espresso'), '&nbsp;', '&nbsp;');
1325
-        } else {
1326
-            $pg_colour = 'red';
1327
-            $pg_status = sprintf(__('Page%sVisibility%sProblem', 'event_espresso'), '&nbsp;', '&nbsp;');
1328
-        }
1329
-
1330
-        // shortcode status
1331
-        if (isset($ee_page->post_content) && strpos($ee_page->post_content, $shortcode) !== false) {
1332
-            $sc_colour = 'green';
1333
-            $sc_status = sprintf(__('Shortcode%sOK', 'event_espresso'), '&nbsp;');
1334
-        } else {
1335
-            $sc_colour = 'red';
1336
-            $sc_status = sprintf(__('Shortcode%sProblem', 'event_espresso'), '&nbsp;');
1337
-        }
1338
-
1339
-        return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>'
1340
-               . $pg_status
1341
-               . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>';
1342
-    }
1343
-
1344
-
1345
-    /**
1346
-     * generates a dropdown of all parent pages - copied from WP core
1347
-     *
1348
-     * @param int $default
1349
-     * @param int $parent
1350
-     * @param int $level
1351
-     */
1352
-    public static function page_settings_dropdown($default = 0, $parent = 0, $level = 0)
1353
-    {
1354
-        global $wpdb;
1355
-        $items = $wpdb->get_results(
1356
-            $wpdb->prepare(
1357
-                "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status != 'trash' ORDER BY menu_order",
1358
-                $parent
1359
-            )
1360
-        );
1361
-
1362
-        if ($items) {
1363
-            foreach ($items as $item) {
1364
-                $pad = str_repeat('&nbsp;', $level * 3);
1365
-                if ($item->ID == $default) {
1366
-                    $current = ' selected="selected"';
1367
-                } else {
1368
-                    $current = '';
1369
-                }
1370
-
1371
-                echo "\n\t<option class='level-$level' value='$item->ID'$current>$pad "
1372
-                     . esc_html($item->post_title)
1373
-                     . "</option>";
1374
-                parent_dropdown($default, $item->ID, $level + 1);
1375
-            }
1376
-        }
1377
-    }
1378
-
1379
-
1380
-    /**
1381
-     * Loads the scripts for the privacy settings form
1382
-     */
1383
-    public function load_scripts_styles_privacy_settings()
1384
-    {
1385
-        $form_handler = $this->loader->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler');
1386
-        $form_handler->enqueueStylesAndScripts();
1387
-    }
1388
-
1389
-
1390
-    /**
1391
-     * display the privacy settings form
1392
-     */
1393
-    public function privacySettings()
1394
-    {
1395
-        $this->_set_add_edit_form_tags('update_privacy_settings');
1396
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
1397
-        $form_handler = $this->loader->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler');
1398
-        $this->_template_args['admin_page_content'] = $form_handler->display();
1399
-        $this->display_admin_page_with_sidebar();
1400
-    }
1401
-
1402
-
1403
-    /**
1404
-     * Update the privacy settings from form data
1405
-     *
1406
-     * @throws EE_Error
1407
-     */
1408
-    public function updatePrivacySettings()
1409
-    {
1410
-        $form_handler = $this->loader->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler');
1411
-        $success = $form_handler->process($this->get_request_data());
1412
-        $this->_redirect_after_action(
1413
-            $success,
1414
-            esc_html__('Registration Form Options', 'event_espresso'),
1415
-            'updated',
1416
-            array('action' => 'privacy_settings')
1417
-        );
1418
-    }
1282
+	}
1283
+
1284
+
1285
+	/***********/
1286
+
1287
+
1288
+	/**
1289
+	 * displays edit and view links for critical EE pages
1290
+	 *
1291
+	 * @access public
1292
+	 * @param int $ee_page_id
1293
+	 * @return string
1294
+	 */
1295
+	public static function edit_view_links($ee_page_id)
1296
+	{
1297
+		$links = '<a href="'
1298
+				 . add_query_arg(
1299
+					 array('post' => $ee_page_id, 'action' => 'edit'),
1300
+					 admin_url('post.php')
1301
+				 )
1302
+				 . '" >'
1303
+				 . __('Edit', 'event_espresso')
1304
+				 . '</a>';
1305
+		$links .= ' &nbsp;|&nbsp; ';
1306
+		$links .= '<a href="' . get_permalink($ee_page_id) . '" >' . __('View', 'event_espresso') . '</a>';
1307
+
1308
+		return $links;
1309
+	}
1310
+
1311
+
1312
+	/**
1313
+	 * displays page and shortcode status for critical EE pages
1314
+	 *
1315
+	 * @param WP page object $ee_page
1316
+	 * @return string
1317
+	 */
1318
+	public static function page_and_shortcode_status($ee_page, $shortcode)
1319
+	{
1320
+
1321
+		// page status
1322
+		if (isset($ee_page->post_status) && $ee_page->post_status == 'publish') {
1323
+			$pg_colour = 'green';
1324
+			$pg_status = sprintf(__('Page%sStatus%sOK', 'event_espresso'), '&nbsp;', '&nbsp;');
1325
+		} else {
1326
+			$pg_colour = 'red';
1327
+			$pg_status = sprintf(__('Page%sVisibility%sProblem', 'event_espresso'), '&nbsp;', '&nbsp;');
1328
+		}
1329
+
1330
+		// shortcode status
1331
+		if (isset($ee_page->post_content) && strpos($ee_page->post_content, $shortcode) !== false) {
1332
+			$sc_colour = 'green';
1333
+			$sc_status = sprintf(__('Shortcode%sOK', 'event_espresso'), '&nbsp;');
1334
+		} else {
1335
+			$sc_colour = 'red';
1336
+			$sc_status = sprintf(__('Shortcode%sProblem', 'event_espresso'), '&nbsp;');
1337
+		}
1338
+
1339
+		return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>'
1340
+			   . $pg_status
1341
+			   . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>';
1342
+	}
1343
+
1344
+
1345
+	/**
1346
+	 * generates a dropdown of all parent pages - copied from WP core
1347
+	 *
1348
+	 * @param int $default
1349
+	 * @param int $parent
1350
+	 * @param int $level
1351
+	 */
1352
+	public static function page_settings_dropdown($default = 0, $parent = 0, $level = 0)
1353
+	{
1354
+		global $wpdb;
1355
+		$items = $wpdb->get_results(
1356
+			$wpdb->prepare(
1357
+				"SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status != 'trash' ORDER BY menu_order",
1358
+				$parent
1359
+			)
1360
+		);
1361
+
1362
+		if ($items) {
1363
+			foreach ($items as $item) {
1364
+				$pad = str_repeat('&nbsp;', $level * 3);
1365
+				if ($item->ID == $default) {
1366
+					$current = ' selected="selected"';
1367
+				} else {
1368
+					$current = '';
1369
+				}
1370
+
1371
+				echo "\n\t<option class='level-$level' value='$item->ID'$current>$pad "
1372
+					 . esc_html($item->post_title)
1373
+					 . "</option>";
1374
+				parent_dropdown($default, $item->ID, $level + 1);
1375
+			}
1376
+		}
1377
+	}
1378
+
1379
+
1380
+	/**
1381
+	 * Loads the scripts for the privacy settings form
1382
+	 */
1383
+	public function load_scripts_styles_privacy_settings()
1384
+	{
1385
+		$form_handler = $this->loader->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler');
1386
+		$form_handler->enqueueStylesAndScripts();
1387
+	}
1388
+
1389
+
1390
+	/**
1391
+	 * display the privacy settings form
1392
+	 */
1393
+	public function privacySettings()
1394
+	{
1395
+		$this->_set_add_edit_form_tags('update_privacy_settings');
1396
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
1397
+		$form_handler = $this->loader->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler');
1398
+		$this->_template_args['admin_page_content'] = $form_handler->display();
1399
+		$this->display_admin_page_with_sidebar();
1400
+	}
1401
+
1402
+
1403
+	/**
1404
+	 * Update the privacy settings from form data
1405
+	 *
1406
+	 * @throws EE_Error
1407
+	 */
1408
+	public function updatePrivacySettings()
1409
+	{
1410
+		$form_handler = $this->loader->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler');
1411
+		$success = $form_handler->process($this->get_request_data());
1412
+		$this->_redirect_after_action(
1413
+			$success,
1414
+			esc_html__('Registration Form Options', 'event_espresso'),
1415
+			'updated',
1416
+			array('action' => 'privacy_settings')
1417
+		);
1418
+	}
1419 1419
 }
Please login to merge, or discard this patch.
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -291,12 +291,12 @@  discard block
 block discarded – undo
291 291
         wp_enqueue_script('thickbox');
292 292
         wp_register_script(
293 293
             'organization_settings',
294
-            GEN_SET_ASSETS_URL . 'your_organization_settings.js',
294
+            GEN_SET_ASSETS_URL.'your_organization_settings.js',
295 295
             array('jquery', 'media-upload', 'thickbox'),
296 296
             EVENT_ESPRESSO_VERSION,
297 297
             true
298 298
         );
299
-        wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION);
299
+        wp_register_style('organization-css', GEN_SET_ASSETS_URL.'organization.css', array(), EVENT_ESPRESSO_VERSION);
300 300
         wp_enqueue_script('organization_settings');
301 301
         wp_enqueue_style('organization-css');
302 302
         $confirm_image_delete = array(
@@ -317,12 +317,12 @@  discard block
 block discarded – undo
317 317
         // scripts
318 318
         wp_register_script(
319 319
             'gen_settings_countries',
320
-            GEN_SET_ASSETS_URL . 'gen_settings_countries.js',
320
+            GEN_SET_ASSETS_URL.'gen_settings_countries.js',
321 321
             array('ee_admin_js'),
322 322
             EVENT_ESPRESSO_VERSION,
323 323
             true
324 324
         );
325
-        wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION);
325
+        wp_register_style('organization-css', GEN_SET_ASSETS_URL.'organization.css', array(), EVENT_ESPRESSO_VERSION);
326 326
         wp_enqueue_script('gen_settings_countries');
327 327
         wp_enqueue_style('organization-css');
328 328
     }
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
         $this->_set_add_edit_form_tags('update_espresso_page_settings');
373 373
         $this->_set_publish_post_box_vars(null, false, false, null, false);
374 374
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
375
-            GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php',
375
+            GEN_SET_TEMPLATE_PATH.'espresso_page_settings.template.php',
376 376
             $this->_template_args,
377 377
             true
378 378
         );
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
     {
532 532
         try {
533 533
             $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
534
-            $admin_options_settings_form->process($this->_req_data[ $admin_options_settings_form->slug() ]);
534
+            $admin_options_settings_form->process($this->_req_data[$admin_options_settings_form->slug()]);
535 535
             EE_Registry::instance()->CFG->admin = apply_filters(
536 536
                 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin',
537 537
                 EE_Registry::instance()->CFG->admin
@@ -648,7 +648,7 @@  discard block
 block discarded – undo
648 648
         $this->_set_add_edit_form_tags('update_country_settings');
649 649
         $this->_set_publish_post_box_vars(null, false, false, null, false);
650 650
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
651
-            GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php',
651
+            GEN_SET_TEMPLATE_PATH.'countries_settings.template.php',
652 652
             $this->_template_args,
653 653
             true
654 654
         );
@@ -676,7 +676,7 @@  discard block
 block discarded – undo
676 676
         $CNT_ISO = isset($this->_req_data['country'])
677 677
             ? strtoupper(sanitize_text_field($this->_req_data['country']))
678 678
             : $CNT_ISO;
679
-        if (! $CNT_ISO) {
679
+        if ( ! $CNT_ISO) {
680 680
             return '';
681 681
         }
682 682
 
@@ -692,59 +692,59 @@  discard block
 block discarded – undo
692 692
         $country_input_types = array(
693 693
             'CNT_active'      => array(
694 694
                 'type'             => 'RADIO_BTN',
695
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
695
+                'input_name'       => 'cntry['.$CNT_ISO.']',
696 696
                 'class'            => '',
697 697
                 'options'          => $this->_yes_no_values,
698 698
                 'use_desc_4_label' => true,
699 699
             ),
700 700
             'CNT_ISO'         => array(
701 701
                 'type'       => 'TEXT',
702
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
702
+                'input_name' => 'cntry['.$CNT_ISO.']',
703 703
                 'class'      => 'small-text',
704 704
             ),
705 705
             'CNT_ISO3'        => array(
706 706
                 'type'       => 'TEXT',
707
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
707
+                'input_name' => 'cntry['.$CNT_ISO.']',
708 708
                 'class'      => 'small-text',
709 709
             ),
710 710
             'RGN_ID'          => array(
711 711
                 'type'       => 'TEXT',
712
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
712
+                'input_name' => 'cntry['.$CNT_ISO.']',
713 713
                 'class'      => 'small-text',
714 714
             ),
715 715
             'CNT_name'        => array(
716 716
                 'type'       => 'TEXT',
717
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
717
+                'input_name' => 'cntry['.$CNT_ISO.']',
718 718
                 'class'      => 'regular-text',
719 719
             ),
720 720
             'CNT_cur_code'    => array(
721 721
                 'type'       => 'TEXT',
722
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
722
+                'input_name' => 'cntry['.$CNT_ISO.']',
723 723
                 'class'      => 'small-text',
724 724
                 'disabled'   => $CNT_cur_disabled,
725 725
             ),
726 726
             'CNT_cur_single'  => array(
727 727
                 'type'       => 'TEXT',
728
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
728
+                'input_name' => 'cntry['.$CNT_ISO.']',
729 729
                 'class'      => 'medium-text',
730 730
                 'disabled'   => $CNT_cur_disabled,
731 731
             ),
732 732
             'CNT_cur_plural'  => array(
733 733
                 'type'       => 'TEXT',
734
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
734
+                'input_name' => 'cntry['.$CNT_ISO.']',
735 735
                 'class'      => 'medium-text',
736 736
                 'disabled'   => $CNT_cur_disabled,
737 737
             ),
738 738
             'CNT_cur_sign'    => array(
739 739
                 'type'         => 'TEXT',
740
-                'input_name'   => 'cntry[' . $CNT_ISO . ']',
740
+                'input_name'   => 'cntry['.$CNT_ISO.']',
741 741
                 'class'        => 'small-text',
742 742
                 'htmlentities' => false,
743 743
                 'disabled'     => $CNT_cur_disabled,
744 744
             ),
745 745
             'CNT_cur_sign_b4' => array(
746 746
                 'type'             => 'RADIO_BTN',
747
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
747
+                'input_name'       => 'cntry['.$CNT_ISO.']',
748 748
                 'class'            => '',
749 749
                 'options'          => $this->_yes_no_values,
750 750
                 'use_desc_4_label' => true,
@@ -752,7 +752,7 @@  discard block
 block discarded – undo
752 752
             ),
753 753
             'CNT_cur_dec_plc' => array(
754 754
                 'type'       => 'RADIO_BTN',
755
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
755
+                'input_name' => 'cntry['.$CNT_ISO.']',
756 756
                 'class'      => '',
757 757
                 'options'    => array(
758 758
                     array('id' => 0, 'text' => ''),
@@ -764,7 +764,7 @@  discard block
 block discarded – undo
764 764
             ),
765 765
             'CNT_cur_dec_mrk' => array(
766 766
                 'type'             => 'RADIO_BTN',
767
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
767
+                'input_name'       => 'cntry['.$CNT_ISO.']',
768 768
                 'class'            => '',
769 769
                 'options'          => array(
770 770
                     array(
@@ -778,7 +778,7 @@  discard block
 block discarded – undo
778 778
             ),
779 779
             'CNT_cur_thsnds'  => array(
780 780
                 'type'             => 'RADIO_BTN',
781
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
781
+                'input_name'       => 'cntry['.$CNT_ISO.']',
782 782
                 'class'            => '',
783 783
                 'options'          => array(
784 784
                     array(
@@ -792,12 +792,12 @@  discard block
 block discarded – undo
792 792
             ),
793 793
             'CNT_tel_code'    => array(
794 794
                 'type'       => 'TEXT',
795
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
795
+                'input_name' => 'cntry['.$CNT_ISO.']',
796 796
                 'class'      => 'small-text',
797 797
             ),
798 798
             'CNT_is_EU'       => array(
799 799
                 'type'             => 'RADIO_BTN',
800
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
800
+                'input_name'       => 'cntry['.$CNT_ISO.']',
801 801
                 'class'            => '',
802 802
                 'options'          => $this->_yes_no_values,
803 803
                 'use_desc_4_label' => true,
@@ -808,7 +808,7 @@  discard block
 block discarded – undo
808 808
             $country_input_types
809 809
         );
810 810
         $country_details_settings = EEH_Template::display_template(
811
-            GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php',
811
+            GEN_SET_TEMPLATE_PATH.'country_details_settings.template.php',
812 812
             $this->_template_args,
813 813
             true
814 814
         );
@@ -846,7 +846,7 @@  discard block
 block discarded – undo
846 846
         $CNT_ISO = isset($this->_req_data['country'])
847 847
             ? sanitize_text_field($this->_req_data['country'])
848 848
             : $CNT_ISO;
849
-        if (! $CNT_ISO) {
849
+        if ( ! $CNT_ISO) {
850 850
             return '';
851 851
         }
852 852
         // for ajax
@@ -876,22 +876,22 @@  discard block
 block discarded – undo
876 876
                     $state_input_types = array(
877 877
                         'STA_abbrev' => array(
878 878
                             'type'       => 'TEXT',
879
-                            'input_name' => 'states[' . $STA_ID . ']',
879
+                            'input_name' => 'states['.$STA_ID.']',
880 880
                             'class'      => 'mid-text',
881 881
                         ),
882 882
                         'STA_name'   => array(
883 883
                             'type'       => 'TEXT',
884
-                            'input_name' => 'states[' . $STA_ID . ']',
884
+                            'input_name' => 'states['.$STA_ID.']',
885 885
                             'class'      => 'regular-text',
886 886
                         ),
887 887
                         'STA_active' => array(
888 888
                             'type'             => 'RADIO_BTN',
889
-                            'input_name'       => 'states[' . $STA_ID . ']',
889
+                            'input_name'       => 'states['.$STA_ID.']',
890 890
                             'options'          => $this->_yes_no_values,
891 891
                             'use_desc_4_label' => true,
892 892
                         ),
893 893
                     );
894
-                    $this->_template_args['states'][ $STA_ID ]['inputs'] =
894
+                    $this->_template_args['states'][$STA_ID]['inputs'] =
895 895
                         EE_Question_Form_Input::generate_question_form_inputs_for_object(
896 896
                             $state,
897 897
                             $state_input_types
@@ -902,7 +902,7 @@  discard block
 block discarded – undo
902 902
                         'CNT_ISO'    => $CNT_ISO,
903 903
                         'STA_abbrev' => $state->abbrev(),
904 904
                     );
905
-                    $this->_template_args['states'][ $STA_ID ]['delete_state_url'] =
905
+                    $this->_template_args['states'][$STA_ID]['delete_state_url'] =
906 906
                         EE_Admin_Page::add_query_args_and_nonce(
907 907
                             $query_args,
908 908
                             GEN_SET_ADMIN_URL
@@ -919,7 +919,7 @@  discard block
 block discarded – undo
919 919
         );
920 920
 
921 921
         $state_details_settings = EEH_Template::display_template(
922
-            GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php',
922
+            GEN_SET_TEMPLATE_PATH.'state_details_settings.template.php',
923 923
             $this->_template_args,
924 924
             true
925 925
         );
@@ -958,7 +958,7 @@  discard block
 block discarded – undo
958 958
         $CNT_ISO = isset($this->_req_data['CNT_ISO'])
959 959
             ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO']))
960 960
             : false;
961
-        if (! $CNT_ISO) {
961
+        if ( ! $CNT_ISO) {
962 962
             EE_Error::add_error(
963 963
                 __('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
964 964
                 __FILE__,
@@ -970,7 +970,7 @@  discard block
 block discarded – undo
970 970
         $STA_abbrev = isset($this->_req_data['STA_abbrev'])
971 971
             ? sanitize_text_field($this->_req_data['STA_abbrev'])
972 972
             : false;
973
-        if (! $STA_abbrev) {
973
+        if ( ! $STA_abbrev) {
974 974
             EE_Error::add_error(
975 975
                 __('No State ISO code or an invalid State ISO code was received.', 'event_espresso'),
976 976
                 __FILE__,
@@ -982,7 +982,7 @@  discard block
 block discarded – undo
982 982
         $STA_name = isset($this->_req_data['STA_name'])
983 983
             ? sanitize_text_field($this->_req_data['STA_name'])
984 984
             : false;
985
-        if (! $STA_name) {
985
+        if ( ! $STA_name) {
986 986
             EE_Error::add_error(
987 987
                 __('No State name or an invalid State name was received.', 'event_espresso'),
988 988
                 __FILE__,
@@ -1034,7 +1034,7 @@  discard block
 block discarded – undo
1034 1034
         $STA_abbrev = isset($this->_req_data['STA_abbrev'])
1035 1035
             ? sanitize_text_field($this->_req_data['STA_abbrev'])
1036 1036
             : false;
1037
-        if (! $STA_ID) {
1037
+        if ( ! $STA_ID) {
1038 1038
             EE_Error::add_error(
1039 1039
                 __('No State ID or an invalid State ID was received.', 'event_espresso'),
1040 1040
                 __FILE__,
@@ -1086,7 +1086,7 @@  discard block
 block discarded – undo
1086 1086
         $CNT_ISO = isset($this->_req_data['country'])
1087 1087
             ? strtoupper(sanitize_text_field($this->_req_data['country']))
1088 1088
             : false;
1089
-        if (! $CNT_ISO) {
1089
+        if ( ! $CNT_ISO) {
1090 1090
             EE_Error::add_error(
1091 1091
                 __('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
1092 1092
                 __FILE__,
@@ -1097,63 +1097,63 @@  discard block
 block discarded – undo
1097 1097
             return;
1098 1098
         }
1099 1099
         $cols_n_values = array();
1100
-        $cols_n_values['CNT_ISO3'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3'])
1101
-            ? strtoupper(sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3']))
1100
+        $cols_n_values['CNT_ISO3'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_ISO3'])
1101
+            ? strtoupper(sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_ISO3']))
1102 1102
             : false;
1103
-        $cols_n_values['RGN_ID'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID'])
1104
-            ? absint($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID'])
1103
+        $cols_n_values['RGN_ID'] = isset($this->_req_data['cntry'][$CNT_ISO]['RGN_ID'])
1104
+            ? absint($this->_req_data['cntry'][$CNT_ISO]['RGN_ID'])
1105 1105
             : null;
1106
-        $cols_n_values['CNT_name'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name'])
1107
-            ? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name'])
1106
+        $cols_n_values['CNT_name'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_name'])
1107
+            ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_name'])
1108 1108
             : null;
1109
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code'])) {
1109
+        if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_code'])) {
1110 1110
             $cols_n_values['CNT_cur_code'] = strtoupper(
1111
-                sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code'])
1111
+                sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_code'])
1112 1112
             );
1113 1113
         }
1114
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single'])) {
1114
+        if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_single'])) {
1115 1115
             $cols_n_values['CNT_cur_single'] = sanitize_text_field(
1116
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single']
1116
+                $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_single']
1117 1117
             );
1118 1118
         }
1119
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural'])) {
1119
+        if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_plural'])) {
1120 1120
             $cols_n_values['CNT_cur_plural'] = sanitize_text_field(
1121
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural']
1121
+                $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_plural']
1122 1122
             );
1123 1123
         }
1124
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign'])) {
1124
+        if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign'])) {
1125 1125
             $cols_n_values['CNT_cur_sign'] = sanitize_text_field(
1126
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign']
1126
+                $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign']
1127 1127
             );
1128 1128
         }
1129
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4'])) {
1129
+        if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign_b4'])) {
1130 1130
             $cols_n_values['CNT_cur_sign_b4'] = absint(
1131
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4']
1131
+                $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign_b4']
1132 1132
             );
1133 1133
         }
1134
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc'])) {
1134
+        if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_plc'])) {
1135 1135
             $cols_n_values['CNT_cur_dec_plc'] = absint(
1136
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc']
1136
+                $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_plc']
1137 1137
             );
1138 1138
         }
1139
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk'])) {
1139
+        if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_mrk'])) {
1140 1140
             $cols_n_values['CNT_cur_dec_mrk'] = sanitize_text_field(
1141
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk']
1141
+                $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_mrk']
1142 1142
             );
1143 1143
         }
1144
-        if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds'])) {
1144
+        if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_thsnds'])) {
1145 1145
             $cols_n_values['CNT_cur_thsnds'] = sanitize_text_field(
1146
-                $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds']
1146
+                $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_thsnds']
1147 1147
             );
1148 1148
         }
1149
-        $cols_n_values['CNT_tel_code'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code'])
1150
-            ? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code'])
1149
+        $cols_n_values['CNT_tel_code'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_tel_code'])
1150
+            ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_tel_code'])
1151 1151
             : null;
1152
-        $cols_n_values['CNT_is_EU'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU'])
1153
-            ? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU'])
1152
+        $cols_n_values['CNT_is_EU'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_is_EU'])
1153
+            ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_is_EU'])
1154 1154
             : false;
1155
-        $cols_n_values['CNT_active'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active'])
1156
-            ? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active'])
1155
+        $cols_n_values['CNT_active'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_active'])
1156
+            ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_active'])
1157 1157
             : false;
1158 1158
         // allow filtering of country data
1159 1159
         $cols_n_values = apply_filters(
@@ -1230,7 +1230,7 @@  discard block
 block discarded – undo
1230 1230
         return '
1231 1231
 			<tr>
1232 1232
 				<th>
1233
-					' . $label . '
1233
+					' . $label.'
1234 1234
 				</th>';
1235 1235
     }
1236 1236
 
@@ -1246,7 +1246,7 @@  discard block
 block discarded – undo
1246 1246
     {
1247 1247
         return '
1248 1248
 				<td class="general-settings-country-input-td">
1249
-					' . $input . '
1249
+					' . $input.'
1250 1250
 				</td>
1251 1251
 			</tr>';
1252 1252
     }
@@ -1277,7 +1277,7 @@  discard block
 block discarded – undo
1277 1277
     {
1278 1278
         return '
1279 1279
 				<td class="general-settings-country-state-input-td">
1280
-					' . $input . '
1280
+					' . $input.'
1281 1281
 				</td>';
1282 1282
     }
1283 1283
 
@@ -1303,7 +1303,7 @@  discard block
 block discarded – undo
1303 1303
                  . __('Edit', 'event_espresso')
1304 1304
                  . '</a>';
1305 1305
         $links .= ' &nbsp;|&nbsp; ';
1306
-        $links .= '<a href="' . get_permalink($ee_page_id) . '" >' . __('View', 'event_espresso') . '</a>';
1306
+        $links .= '<a href="'.get_permalink($ee_page_id).'" >'.__('View', 'event_espresso').'</a>';
1307 1307
 
1308 1308
         return $links;
1309 1309
     }
@@ -1336,9 +1336,9 @@  discard block
 block discarded – undo
1336 1336
             $sc_status = sprintf(__('Shortcode%sProblem', 'event_espresso'), '&nbsp;');
1337 1337
         }
1338 1338
 
1339
-        return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>'
1339
+        return '<span style="color:'.$pg_colour.'; margin-right:2em;"><strong>'
1340 1340
                . $pg_status
1341
-               . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>';
1341
+               . '</strong></span><span style="color:'.$sc_colour.'"><strong>'.$sc_status.'</strong></span>';
1342 1342
     }
1343 1343
 
1344 1344
 
Please login to merge, or discard this patch.
core/services/address/CountrySubRegionDao.php 3 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -5,7 +5,6 @@
 block discarded – undo
5 5
 use EE_Country;
6 6
 use EE_Error;
7 7
 use EE_State;
8
-use EEM_Country;
9 8
 use EEM_State;
10 9
 use EventEspresso\core\exceptions\InvalidDataTypeException;
11 10
 use EventEspresso\core\exceptions\InvalidInterfaceException;
Please login to merge, or discard this patch.
Indentation   +223 added lines, -223 removed lines patch added patch discarded remove patch
@@ -26,248 +26,248 @@
 block discarded – undo
26 26
 class CountrySubRegionDao
27 27
 {
28 28
 
29
-    const REPO_URL = 'https://raw.githubusercontent.com/eventespresso/countries-and-subregions/master/';
29
+	const REPO_URL = 'https://raw.githubusercontent.com/eventespresso/countries-and-subregions/master/';
30 30
 
31
-    const OPTION_NAME_COUNTRY_DATA_VERSION = 'espresso-country-sub-region-data-version';
31
+	const OPTION_NAME_COUNTRY_DATA_VERSION = 'espresso-country-sub-region-data-version';
32 32
 
33
-    /**
34
-     * @var EEM_State $state_model
35
-     */
36
-    private $state_model;
33
+	/**
34
+	 * @var EEM_State $state_model
35
+	 */
36
+	private $state_model;
37 37
 
38
-    /**
39
-     * @var JsonValidator $json_validator
40
-     */
41
-    private $json_validator;
38
+	/**
39
+	 * @var JsonValidator $json_validator
40
+	 */
41
+	private $json_validator;
42 42
 
43
-    /**
44
-     * @var string $data_version
45
-     */
46
-    private $data_version;
43
+	/**
44
+	 * @var string $data_version
45
+	 */
46
+	private $data_version;
47 47
 
48
-    /**
49
-     * @var array $countries
50
-     */
51
-    private $countries = array();
48
+	/**
49
+	 * @var array $countries
50
+	 */
51
+	private $countries = array();
52 52
 
53 53
 
54
-    /**
55
-     * CountrySubRegionDao constructor.
56
-     *
57
-     * @param EEM_State     $state_model
58
-     * @param JsonValidator $json_validator
59
-     */
60
-    public function __construct(EEM_State $state_model, JsonValidator $json_validator)
61
-    {
62
-        $this->state_model = $state_model;
63
-        $this->json_validator = $json_validator;
64
-    }
54
+	/**
55
+	 * CountrySubRegionDao constructor.
56
+	 *
57
+	 * @param EEM_State     $state_model
58
+	 * @param JsonValidator $json_validator
59
+	 */
60
+	public function __construct(EEM_State $state_model, JsonValidator $json_validator)
61
+	{
62
+		$this->state_model = $state_model;
63
+		$this->json_validator = $json_validator;
64
+	}
65 65
 
66 66
 
67
-    /**
68
-     * @param EE_Country $country_object
69
-     * @return bool
70
-     * @throws EE_Error
71
-     * @throws InvalidArgumentException
72
-     * @throws InvalidDataTypeException
73
-     * @throws InvalidInterfaceException
74
-     * @throws ReflectionException
75
-     */
76
-    public function saveCountrySubRegions(EE_Country $country_object)
77
-    {
78
-        $CNT_ISO = $country_object->ID();
79
-        $has_sub_regions = $this->state_model->count(array(array('Country.CNT_ISO' => $CNT_ISO)));
80
-        $data = [];
81
-        if (empty($this->countries)) {
82
-            $this->data_version = $this->getCountrySubRegionDataVersion();
83
-            $data = $this->retrieveJsonData(self::REPO_URL . 'countries.json');
84
-        }
85
-        if (empty($data)) {
86
-            EE_Error::add_error(
87
-                'Country Subregion Data could not be retrieved',
88
-                __FILE__,
89
-                __METHOD__,
90
-                __LINE__
91
-            );
92
-        }
93
-        if (! $has_sub_regions
94
-            || (isset($data->version) && version_compare($data->version, $this->data_version))
95
-        ) {
96
-            if (isset($data->countries)
97
-                && $this->processCountryData($CNT_ISO, $data->countries) > 0
98
-            ) {
99
-                $this->countries = $data->countries;
100
-                $this->updateCountrySubRegionDataVersion($data->version);
101
-                return true;
102
-            }
103
-        }
104
-        return false;
105
-    }
67
+	/**
68
+	 * @param EE_Country $country_object
69
+	 * @return bool
70
+	 * @throws EE_Error
71
+	 * @throws InvalidArgumentException
72
+	 * @throws InvalidDataTypeException
73
+	 * @throws InvalidInterfaceException
74
+	 * @throws ReflectionException
75
+	 */
76
+	public function saveCountrySubRegions(EE_Country $country_object)
77
+	{
78
+		$CNT_ISO = $country_object->ID();
79
+		$has_sub_regions = $this->state_model->count(array(array('Country.CNT_ISO' => $CNT_ISO)));
80
+		$data = [];
81
+		if (empty($this->countries)) {
82
+			$this->data_version = $this->getCountrySubRegionDataVersion();
83
+			$data = $this->retrieveJsonData(self::REPO_URL . 'countries.json');
84
+		}
85
+		if (empty($data)) {
86
+			EE_Error::add_error(
87
+				'Country Subregion Data could not be retrieved',
88
+				__FILE__,
89
+				__METHOD__,
90
+				__LINE__
91
+			);
92
+		}
93
+		if (! $has_sub_regions
94
+			|| (isset($data->version) && version_compare($data->version, $this->data_version))
95
+		) {
96
+			if (isset($data->countries)
97
+				&& $this->processCountryData($CNT_ISO, $data->countries) > 0
98
+			) {
99
+				$this->countries = $data->countries;
100
+				$this->updateCountrySubRegionDataVersion($data->version);
101
+				return true;
102
+			}
103
+		}
104
+		return false;
105
+	}
106 106
 
107 107
 
108
-    /**
109
-     * @since 4.9.70.p
110
-     * @return string
111
-     */
112
-    private function getCountrySubRegionDataVersion()
113
-    {
114
-        return get_option(self::OPTION_NAME_COUNTRY_DATA_VERSION, null);
115
-    }
108
+	/**
109
+	 * @since 4.9.70.p
110
+	 * @return string
111
+	 */
112
+	private function getCountrySubRegionDataVersion()
113
+	{
114
+		return get_option(self::OPTION_NAME_COUNTRY_DATA_VERSION, null);
115
+	}
116 116
 
117 117
 
118
-    /**
119
-     * @param string $version
120
-     */
121
-    private function updateCountrySubRegionDataVersion($version = '')
122
-    {
123
-        // add version option if it has never been added before, or update existing
124
-        if ($this->data_version === null) {
125
-            add_option(self::OPTION_NAME_COUNTRY_DATA_VERSION, $version, '', false);
126
-        } else {
127
-            update_option(self::OPTION_NAME_COUNTRY_DATA_VERSION, $version);
128
-        }
129
-    }
118
+	/**
119
+	 * @param string $version
120
+	 */
121
+	private function updateCountrySubRegionDataVersion($version = '')
122
+	{
123
+		// add version option if it has never been added before, or update existing
124
+		if ($this->data_version === null) {
125
+			add_option(self::OPTION_NAME_COUNTRY_DATA_VERSION, $version, '', false);
126
+		} else {
127
+			update_option(self::OPTION_NAME_COUNTRY_DATA_VERSION, $version);
128
+		}
129
+	}
130 130
 
131 131
 
132
-    /**
133
-     * @param string $CNT_ISO
134
-     * @param array  $countries
135
-     * @return int
136
-     * @throws EE_Error
137
-     * @throws InvalidArgumentException
138
-     * @throws InvalidDataTypeException
139
-     * @throws InvalidInterfaceException
140
-     * @throws ReflectionException
141
-     * @since 4.9.70.p
142
-     */
143
-    private function processCountryData($CNT_ISO, $countries = array())
144
-    {
145
-        if (! empty($countries)) {
146
-            foreach ($countries as $key => $country) {
147
-                if ($country instanceof stdClass
148
-                    && $country->code === $CNT_ISO
149
-                    && empty($country->sub_regions)
150
-                    && ! empty($country->filename)
151
-                ) {
152
-                    $country->sub_regions = $this->retrieveJsonData(
153
-                        self::REPO_URL . 'countries/' . $country->filename . '.json'
154
-                    );
155
-                    return $this->saveSubRegionData($country, $country->sub_regions);
156
-                }
157
-            }
158
-        }
159
-        return 0;
160
-    }
132
+	/**
133
+	 * @param string $CNT_ISO
134
+	 * @param array  $countries
135
+	 * @return int
136
+	 * @throws EE_Error
137
+	 * @throws InvalidArgumentException
138
+	 * @throws InvalidDataTypeException
139
+	 * @throws InvalidInterfaceException
140
+	 * @throws ReflectionException
141
+	 * @since 4.9.70.p
142
+	 */
143
+	private function processCountryData($CNT_ISO, $countries = array())
144
+	{
145
+		if (! empty($countries)) {
146
+			foreach ($countries as $key => $country) {
147
+				if ($country instanceof stdClass
148
+					&& $country->code === $CNT_ISO
149
+					&& empty($country->sub_regions)
150
+					&& ! empty($country->filename)
151
+				) {
152
+					$country->sub_regions = $this->retrieveJsonData(
153
+						self::REPO_URL . 'countries/' . $country->filename . '.json'
154
+					);
155
+					return $this->saveSubRegionData($country, $country->sub_regions);
156
+				}
157
+			}
158
+		}
159
+		return 0;
160
+	}
161 161
 
162 162
 
163
-    /**
164
-     * @param string $url
165
-     * @return array
166
-     */
167
-    private function retrieveJsonData($url)
168
-    {
169
-        if (empty($url)) {
170
-            EE_Error::add_error(
171
-                'No URL was provided!',
172
-                __FILE__,
173
-                __METHOD__,
174
-                __LINE__
175
-            );
176
-            return array();
177
-        }
178
-        $request = wp_safe_remote_get($url);
179
-        if ($request instanceof WP_Error) {
180
-            EE_Error::add_error(
181
-                $request->get_error_message(),
182
-                __FILE__,
183
-                __METHOD__,
184
-                __LINE__
185
-            );
186
-            return array();
187
-        }
188
-        $body = wp_remote_retrieve_body($request);
189
-        $json = json_decode($body);
190
-        if ($this->json_validator->isValid(__FILE__, __METHOD__, __LINE__)) {
191
-            return $json;
192
-        }
193
-        return array();
194
-    }
163
+	/**
164
+	 * @param string $url
165
+	 * @return array
166
+	 */
167
+	private function retrieveJsonData($url)
168
+	{
169
+		if (empty($url)) {
170
+			EE_Error::add_error(
171
+				'No URL was provided!',
172
+				__FILE__,
173
+				__METHOD__,
174
+				__LINE__
175
+			);
176
+			return array();
177
+		}
178
+		$request = wp_safe_remote_get($url);
179
+		if ($request instanceof WP_Error) {
180
+			EE_Error::add_error(
181
+				$request->get_error_message(),
182
+				__FILE__,
183
+				__METHOD__,
184
+				__LINE__
185
+			);
186
+			return array();
187
+		}
188
+		$body = wp_remote_retrieve_body($request);
189
+		$json = json_decode($body);
190
+		if ($this->json_validator->isValid(__FILE__, __METHOD__, __LINE__)) {
191
+			return $json;
192
+		}
193
+		return array();
194
+	}
195 195
 
196 196
 
197
-    /**
198
-     * @param stdClass $country
199
-     * @param array    $sub_regions
200
-     * @return int
201
-     * @throws EE_Error
202
-     * @throws InvalidArgumentException
203
-     * @throws InvalidDataTypeException
204
-     * @throws InvalidInterfaceException
205
-     * @throws ReflectionException
206
-     */
207
-    private function saveSubRegionData(stdClass $country, $sub_regions = array())
208
-    {
209
-        $results = 0;
210
-        if (is_array($sub_regions)) {
211
-            $existing_sub_regions = $this->getExistingStateAbbreviations($country->code);
212
-            foreach ($sub_regions as $sub_region) {
213
-                // remove country code from sub region code
214
-                $abbrev = str_replace(
215
-                    $country->code . '-',
216
-                    '',
217
-                    sanitize_text_field($sub_region->code)
218
-                );
219
-                // but NOT if sub region code results in only a number
220
-                if (absint($abbrev) !== 0) {
221
-                    $abbrev = sanitize_text_field($sub_region->code);
222
-                }
223
-                if (! in_array($abbrev, $existing_sub_regions, true)
224
-                    && $this->state_model->insert(
225
-                        [
226
-                            // STA_ID CNT_ISO STA_abbrev STA_name STA_active
227
-                            'CNT_ISO'    => $country->code,
228
-                            'STA_abbrev' => $abbrev,
229
-                            'STA_name'   => sanitize_text_field($sub_region->name),
230
-                            'STA_active' => 1,
231
-                        ]
232
-                    )
233
-                ) {
234
-                    $results++;
235
-                }
236
-            }
237
-        }
238
-        return $results;
239
-    }
197
+	/**
198
+	 * @param stdClass $country
199
+	 * @param array    $sub_regions
200
+	 * @return int
201
+	 * @throws EE_Error
202
+	 * @throws InvalidArgumentException
203
+	 * @throws InvalidDataTypeException
204
+	 * @throws InvalidInterfaceException
205
+	 * @throws ReflectionException
206
+	 */
207
+	private function saveSubRegionData(stdClass $country, $sub_regions = array())
208
+	{
209
+		$results = 0;
210
+		if (is_array($sub_regions)) {
211
+			$existing_sub_regions = $this->getExistingStateAbbreviations($country->code);
212
+			foreach ($sub_regions as $sub_region) {
213
+				// remove country code from sub region code
214
+				$abbrev = str_replace(
215
+					$country->code . '-',
216
+					'',
217
+					sanitize_text_field($sub_region->code)
218
+				);
219
+				// but NOT if sub region code results in only a number
220
+				if (absint($abbrev) !== 0) {
221
+					$abbrev = sanitize_text_field($sub_region->code);
222
+				}
223
+				if (! in_array($abbrev, $existing_sub_regions, true)
224
+					&& $this->state_model->insert(
225
+						[
226
+							// STA_ID CNT_ISO STA_abbrev STA_name STA_active
227
+							'CNT_ISO'    => $country->code,
228
+							'STA_abbrev' => $abbrev,
229
+							'STA_name'   => sanitize_text_field($sub_region->name),
230
+							'STA_active' => 1,
231
+						]
232
+					)
233
+				) {
234
+					$results++;
235
+				}
236
+			}
237
+		}
238
+		return $results;
239
+	}
240 240
 
241 241
 
242
-    /**
243
-     * @param string $CNT_ISO
244
-     * @since $VID:$
245
-     * @return array
246
-     * @throws EE_Error
247
-     * @throws InvalidArgumentException
248
-     * @throws InvalidDataTypeException
249
-     * @throws InvalidInterfaceException
250
-     * @throws ReflectionException
251
-     */
252
-    private function getExistingStateAbbreviations($CNT_ISO)
253
-    {
254
-        $existing_sub_region_IDs = [];
255
-        $existing_sub_regions = $this->state_model->get_all(array(
256
-            array(
257
-                'Country.CNT_ISO' => array(
258
-                    'IN',
259
-                    [$CNT_ISO]
260
-                )
261
-            ),
262
-            'order_by' => array('Country.CNT_name' => 'ASC', 'STA_name' => 'ASC')
263
-        ));
264
-        if (is_array($existing_sub_regions)) {
265
-            foreach ($existing_sub_regions as $existing_sub_region) {
266
-                if ($existing_sub_region instanceof EE_State) {
267
-                    $existing_sub_region_IDs[] = $existing_sub_region->abbrev();
268
-                }
269
-            }
270
-        }
271
-        return $existing_sub_region_IDs;
272
-    }
242
+	/**
243
+	 * @param string $CNT_ISO
244
+	 * @since $VID:$
245
+	 * @return array
246
+	 * @throws EE_Error
247
+	 * @throws InvalidArgumentException
248
+	 * @throws InvalidDataTypeException
249
+	 * @throws InvalidInterfaceException
250
+	 * @throws ReflectionException
251
+	 */
252
+	private function getExistingStateAbbreviations($CNT_ISO)
253
+	{
254
+		$existing_sub_region_IDs = [];
255
+		$existing_sub_regions = $this->state_model->get_all(array(
256
+			array(
257
+				'Country.CNT_ISO' => array(
258
+					'IN',
259
+					[$CNT_ISO]
260
+				)
261
+			),
262
+			'order_by' => array('Country.CNT_name' => 'ASC', 'STA_name' => 'ASC')
263
+		));
264
+		if (is_array($existing_sub_regions)) {
265
+			foreach ($existing_sub_regions as $existing_sub_region) {
266
+				if ($existing_sub_region instanceof EE_State) {
267
+					$existing_sub_region_IDs[] = $existing_sub_region->abbrev();
268
+				}
269
+			}
270
+		}
271
+		return $existing_sub_region_IDs;
272
+	}
273 273
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
         $data = [];
81 81
         if (empty($this->countries)) {
82 82
             $this->data_version = $this->getCountrySubRegionDataVersion();
83
-            $data = $this->retrieveJsonData(self::REPO_URL . 'countries.json');
83
+            $data = $this->retrieveJsonData(self::REPO_URL.'countries.json');
84 84
         }
85 85
         if (empty($data)) {
86 86
             EE_Error::add_error(
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
                 __LINE__
91 91
             );
92 92
         }
93
-        if (! $has_sub_regions
93
+        if ( ! $has_sub_regions
94 94
             || (isset($data->version) && version_compare($data->version, $this->data_version))
95 95
         ) {
96 96
             if (isset($data->countries)
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
      */
143 143
     private function processCountryData($CNT_ISO, $countries = array())
144 144
     {
145
-        if (! empty($countries)) {
145
+        if ( ! empty($countries)) {
146 146
             foreach ($countries as $key => $country) {
147 147
                 if ($country instanceof stdClass
148 148
                     && $country->code === $CNT_ISO
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
                     && ! empty($country->filename)
151 151
                 ) {
152 152
                     $country->sub_regions = $this->retrieveJsonData(
153
-                        self::REPO_URL . 'countries/' . $country->filename . '.json'
153
+                        self::REPO_URL.'countries/'.$country->filename.'.json'
154 154
                     );
155 155
                     return $this->saveSubRegionData($country, $country->sub_regions);
156 156
                 }
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
             foreach ($sub_regions as $sub_region) {
213 213
                 // remove country code from sub region code
214 214
                 $abbrev = str_replace(
215
-                    $country->code . '-',
215
+                    $country->code.'-',
216 216
                     '',
217 217
                     sanitize_text_field($sub_region->code)
218 218
                 );
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
                 if (absint($abbrev) !== 0) {
221 221
                     $abbrev = sanitize_text_field($sub_region->code);
222 222
                 }
223
-                if (! in_array($abbrev, $existing_sub_regions, true)
223
+                if ( ! in_array($abbrev, $existing_sub_regions, true)
224 224
                     && $this->state_model->insert(
225 225
                         [
226 226
                             // STA_ID CNT_ISO STA_abbrev STA_name STA_active
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.76.rc.005');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.76.rc.005');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
Please login to merge, or discard this patch.