Completed
Branch FET/remove-bot-trap-timestamp (63333a)
by
unknown
51:51 queued 42:54
created
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.
modules/bot_trap/EED_Bot_Trap.module.php 1 patch
Indentation   +275 added lines, -275 removed lines patch added patch discarded remove patch
@@ -16,304 +16,304 @@
 block discarded – undo
16 16
 class EED_Bot_Trap extends EED_Module
17 17
 {
18 18
 
19
-    /**
20
-     * @return EED_Bot_Trap|EED_Module
21
-     */
22
-    public static function instance()
23
-    {
24
-        return parent::get_instance(__CLASS__);
25
-    }
19
+	/**
20
+	 * @return EED_Bot_Trap|EED_Module
21
+	 */
22
+	public static function instance()
23
+	{
24
+		return parent::get_instance(__CLASS__);
25
+	}
26 26
 
27 27
 
28
-    /**
29
-     * set_hooks - for hooking into EE Core, other modules, etc
30
-     *
31
-     * @return void
32
-     */
33
-    public static function set_hooks()
34
-    {
35
-        if (apply_filters('FHEE__EED_Bot_Trap__set_hooks__use_bot_trap', true) &&
36
-            EE_Registry::instance()->CFG->registration->use_bot_trap
37
-        ) {
38
-            EED_Bot_Trap::set_trap();
39
-            // redirect bots to bogus success page
40
-            EE_Config::register_route(
41
-                'ticket_selection_received',
42
-                'EED_Bot_Trap',
43
-                'display_bot_trap_success'
44
-            );
45
-        }
46
-    }
28
+	/**
29
+	 * set_hooks - for hooking into EE Core, other modules, etc
30
+	 *
31
+	 * @return void
32
+	 */
33
+	public static function set_hooks()
34
+	{
35
+		if (apply_filters('FHEE__EED_Bot_Trap__set_hooks__use_bot_trap', true) &&
36
+			EE_Registry::instance()->CFG->registration->use_bot_trap
37
+		) {
38
+			EED_Bot_Trap::set_trap();
39
+			// redirect bots to bogus success page
40
+			EE_Config::register_route(
41
+				'ticket_selection_received',
42
+				'EED_Bot_Trap',
43
+				'display_bot_trap_success'
44
+			);
45
+		}
46
+	}
47 47
 
48 48
 
49
-    /**
50
-     * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
51
-     *
52
-     * @return void
53
-     */
54
-    public static function set_trap()
55
-    {
56
-        define('EE_BOT_TRAP_BASE_URL', plugin_dir_url(__FILE__) . DS);
57
-        add_action(
58
-            'AHEE__ticket_selector_chart__template__after_ticket_selector',
59
-            array('EED_Bot_Trap', 'generate_bot_trap'),
60
-            10,
61
-            2
62
-        );
63
-        add_action(
64
-            'EED_Ticket_Selector__process_ticket_selections__before',
65
-            array('EED_Bot_Trap', 'process_bot_trap'),
66
-            1,
67
-            2
68
-        );
69
-    }
49
+	/**
50
+	 * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
51
+	 *
52
+	 * @return void
53
+	 */
54
+	public static function set_trap()
55
+	{
56
+		define('EE_BOT_TRAP_BASE_URL', plugin_dir_url(__FILE__) . DS);
57
+		add_action(
58
+			'AHEE__ticket_selector_chart__template__after_ticket_selector',
59
+			array('EED_Bot_Trap', 'generate_bot_trap'),
60
+			10,
61
+			2
62
+		);
63
+		add_action(
64
+			'EED_Ticket_Selector__process_ticket_selections__before',
65
+			array('EED_Bot_Trap', 'process_bot_trap'),
66
+			1,
67
+			2
68
+		);
69
+	}
70 70
 
71 71
 
72
-    /**
73
-     * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
74
-     *
75
-     * @return void
76
-     */
77
-    public static function set_hooks_admin()
78
-    {
79
-        if (defined('DOING_AJAX')
80
-            && DOING_AJAX
81
-            && apply_filters('FHEE__EED_Bot_Trap__set_hooks__use_bot_trap', true)
82
-            && EE_Registry::instance()->CFG->registration->use_bot_trap
83
-        ) {
84
-            EED_Bot_Trap::set_trap();
85
-        }
86
-        add_action(
87
-            'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template',
88
-            array('EED_Bot_Trap', 'bot_trap_settings_form'),
89
-            5
90
-        );
91
-        add_filter(
92
-            'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration',
93
-            array('EED_Bot_Trap', 'update_bot_trap_settings_form'),
94
-            10,
95
-            1
96
-        );
97
-    }
72
+	/**
73
+	 * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
74
+	 *
75
+	 * @return void
76
+	 */
77
+	public static function set_hooks_admin()
78
+	{
79
+		if (defined('DOING_AJAX')
80
+			&& DOING_AJAX
81
+			&& apply_filters('FHEE__EED_Bot_Trap__set_hooks__use_bot_trap', true)
82
+			&& EE_Registry::instance()->CFG->registration->use_bot_trap
83
+		) {
84
+			EED_Bot_Trap::set_trap();
85
+		}
86
+		add_action(
87
+			'AHEE__Extend_Registration_Form_Admin_Page___reg_form_settings_template',
88
+			array('EED_Bot_Trap', 'bot_trap_settings_form'),
89
+			5
90
+		);
91
+		add_filter(
92
+			'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration',
93
+			array('EED_Bot_Trap', 'update_bot_trap_settings_form'),
94
+			10,
95
+			1
96
+		);
97
+	}
98 98
 
99 99
 
100
-    /**
101
-     * run - initial module setup
102
-     *
103
-     * @param WP $WP
104
-     * @return void
105
-     */
106
-    public function run($WP)
107
-    {
108
-    }
100
+	/**
101
+	 * run - initial module setup
102
+	 *
103
+	 * @param WP $WP
104
+	 * @return void
105
+	 */
106
+	public function run($WP)
107
+	{
108
+	}
109 109
 
110 110
 
111
-    /**
112
-     * generate_bot_trap
113
-     *
114
-     * @return void
115
-     * @throws RuntimeException
116
-     */
117
-    public static function generate_bot_trap()
118
-    {
119
-        $do_not_enter = esc_html__('please do not enter anything in this input', 'event_espresso');
120
-        $time = microtime(true);
121
-        $html = '<div class="tkt-slctr-request-processor-dv" style="float:left; margin:0 0 0 -999em; height: 0;">';
122
-        $html .= '<label for="tkt-slctr-request-processor-email-' . $time . '">' . $do_not_enter . '</label>';
123
-        $html .= '<input type="email" id="tkt-slctr-request-processor-email-';
124
-        $html .= $time . '" name="tkt-slctr-request-processor-email" value=""/>';
125
-        $html .= '</div><!-- .tkt-slctr-request-processor-dv -->';
126
-        echo $html;
127
-    }
111
+	/**
112
+	 * generate_bot_trap
113
+	 *
114
+	 * @return void
115
+	 * @throws RuntimeException
116
+	 */
117
+	public static function generate_bot_trap()
118
+	{
119
+		$do_not_enter = esc_html__('please do not enter anything in this input', 'event_espresso');
120
+		$time = microtime(true);
121
+		$html = '<div class="tkt-slctr-request-processor-dv" style="float:left; margin:0 0 0 -999em; height: 0;">';
122
+		$html .= '<label for="tkt-slctr-request-processor-email-' . $time . '">' . $do_not_enter . '</label>';
123
+		$html .= '<input type="email" id="tkt-slctr-request-processor-email-';
124
+		$html .= $time . '" name="tkt-slctr-request-processor-email" value=""/>';
125
+		$html .= '</div><!-- .tkt-slctr-request-processor-dv -->';
126
+		echo $html;
127
+	}
128 128
 
129 129
 
130
-    /**
131
-     * process_bot_trap
132
-     *
133
-     * @param array|string $triggered_trap_callback Callback that will be executed for handling the
134
-     *                                              response if the bot trap is triggered.
135
-     *                                              It should receive one argument: a boolean indicating
136
-     *                                              whether the trap was triggered by suspicious timing or not.
137
-     * @throws RuntimeException
138
-     */
139
-    public static function process_bot_trap($triggered_trap_callback = array())
140
-    {
141
-        // what's your email address Mr. Bot ?
142
-        $empty_trap = isset($_REQUEST['tkt-slctr-request-processor-email'])
143
-                      && $_REQUEST['tkt-slctr-request-processor-email'] === '';
144
-        // are we human ?
145
-        if ($empty_trap) {
146
-            do_action('AHEE__EED_Bot_Trap__process_bot_trap__trap_not_triggered');
147
-            return;
148
-        }
149
-        // check the given callback is valid first before executing
150
-        if (! is_callable($triggered_trap_callback)) {
151
-            // invalid callback so lets just sub in our default.
152
-            $triggered_trap_callback = array('EED_Bot_Trap', 'triggered_trap_response');
153
-        }
154
-        call_user_func($triggered_trap_callback);
155
-    }
130
+	/**
131
+	 * process_bot_trap
132
+	 *
133
+	 * @param array|string $triggered_trap_callback Callback that will be executed for handling the
134
+	 *                                              response if the bot trap is triggered.
135
+	 *                                              It should receive one argument: a boolean indicating
136
+	 *                                              whether the trap was triggered by suspicious timing or not.
137
+	 * @throws RuntimeException
138
+	 */
139
+	public static function process_bot_trap($triggered_trap_callback = array())
140
+	{
141
+		// what's your email address Mr. Bot ?
142
+		$empty_trap = isset($_REQUEST['tkt-slctr-request-processor-email'])
143
+					  && $_REQUEST['tkt-slctr-request-processor-email'] === '';
144
+		// are we human ?
145
+		if ($empty_trap) {
146
+			do_action('AHEE__EED_Bot_Trap__process_bot_trap__trap_not_triggered');
147
+			return;
148
+		}
149
+		// check the given callback is valid first before executing
150
+		if (! is_callable($triggered_trap_callback)) {
151
+			// invalid callback so lets just sub in our default.
152
+			$triggered_trap_callback = array('EED_Bot_Trap', 'triggered_trap_response');
153
+		}
154
+		call_user_func($triggered_trap_callback);
155
+	}
156 156
 
157 157
 
158
-    /**
159
-     * This is the default callback executed by EED_Bot_Trap::process_bot_trap that handles the response.
160
-     *
161
-     * @throws InvalidArgumentException
162
-     * @throws InvalidDataTypeException
163
-     * @throws InvalidInterfaceException
164
-     */
165
-    public static function triggered_trap_response()
166
-    {
167
-        // UH OH...
168
-        $redirect_url = apply_filters(
169
-            'FHEE__EED_Bot_Trap__process_bot_trap__redirect_url',
170
-            add_query_arg(
171
-                array('ee' => 'ticket_selection_received'),
172
-                EE_Registry::instance()->CFG->core->reg_page_url()
173
-            )
174
-        );
175
-        // if AJAX, return the redirect URL
176
-        if (defined('DOING_AJAX') && DOING_AJAX) {
177
-            echo wp_json_encode(
178
-                array_merge(
179
-                    EE_Error::get_notices(false),
180
-                    array(
181
-                        'redirect_url' => $redirect_url,
182
-                    )
183
-                )
184
-            );
185
-            exit();
186
-        }
187
-        wp_safe_redirect($redirect_url);
188
-        exit();
189
-    }
158
+	/**
159
+	 * This is the default callback executed by EED_Bot_Trap::process_bot_trap that handles the response.
160
+	 *
161
+	 * @throws InvalidArgumentException
162
+	 * @throws InvalidDataTypeException
163
+	 * @throws InvalidInterfaceException
164
+	 */
165
+	public static function triggered_trap_response()
166
+	{
167
+		// UH OH...
168
+		$redirect_url = apply_filters(
169
+			'FHEE__EED_Bot_Trap__process_bot_trap__redirect_url',
170
+			add_query_arg(
171
+				array('ee' => 'ticket_selection_received'),
172
+				EE_Registry::instance()->CFG->core->reg_page_url()
173
+			)
174
+		);
175
+		// if AJAX, return the redirect URL
176
+		if (defined('DOING_AJAX') && DOING_AJAX) {
177
+			echo wp_json_encode(
178
+				array_merge(
179
+					EE_Error::get_notices(false),
180
+					array(
181
+						'redirect_url' => $redirect_url,
182
+					)
183
+				)
184
+			);
185
+			exit();
186
+		}
187
+		wp_safe_redirect($redirect_url);
188
+		exit();
189
+	}
190 190
 
191 191
 
192
-    /**
193
-     * display_bot_trap_success
194
-     * shows a "success" screen to bots so that they (ie: the ppl managing them)
195
-     * think the form was submitted successfully
196
-     *
197
-     * @return void
198
-     */
199
-    public static function display_bot_trap_success()
200
-    {
201
-        add_filter('FHEE__EED_Single_Page_Checkout__run', '__return_false');
202
-        $bot_notice = esc_html__(
203
-            'Thank you so much. Your ticket selections have been received for consideration.',
204
-            'event_espresso'
205
-        );
206
-        $bot_notice = isset($_REQUEST['ee-notice']) && $_REQUEST['ee-notice'] !== ''
207
-            ? sanitize_text_field(stripslashes($_REQUEST['ee-notice']))
208
-            : $bot_notice;
209
-        EE_Registry::instance()->REQ->add_output(EEH_HTML::div($bot_notice, '', 'ee-attention'));
210
-    }
192
+	/**
193
+	 * display_bot_trap_success
194
+	 * shows a "success" screen to bots so that they (ie: the ppl managing them)
195
+	 * think the form was submitted successfully
196
+	 *
197
+	 * @return void
198
+	 */
199
+	public static function display_bot_trap_success()
200
+	{
201
+		add_filter('FHEE__EED_Single_Page_Checkout__run', '__return_false');
202
+		$bot_notice = esc_html__(
203
+			'Thank you so much. Your ticket selections have been received for consideration.',
204
+			'event_espresso'
205
+		);
206
+		$bot_notice = isset($_REQUEST['ee-notice']) && $_REQUEST['ee-notice'] !== ''
207
+			? sanitize_text_field(stripslashes($_REQUEST['ee-notice']))
208
+			: $bot_notice;
209
+		EE_Registry::instance()->REQ->add_output(EEH_HTML::div($bot_notice, '', 'ee-attention'));
210
+	}
211 211
 
212 212
 
213 213
 
214
-    /***********************************    ADMIN    **********************************/
214
+	/***********************************    ADMIN    **********************************/
215 215
 
216 216
 
217
-    /**
218
-     * bot_trap_settings_form
219
-     *
220
-     * @return void
221
-     * @throws EE_Error
222
-     * @throws InvalidArgumentException
223
-     * @throws InvalidDataTypeException
224
-     * @throws InvalidInterfaceException
225
-     */
226
-    public static function bot_trap_settings_form()
227
-    {
228
-        EED_Bot_Trap::_bot_trap_settings_form()->enqueue_js();
229
-        echo EED_Bot_Trap::_bot_trap_settings_form()->get_html();
230
-    }
217
+	/**
218
+	 * bot_trap_settings_form
219
+	 *
220
+	 * @return void
221
+	 * @throws EE_Error
222
+	 * @throws InvalidArgumentException
223
+	 * @throws InvalidDataTypeException
224
+	 * @throws InvalidInterfaceException
225
+	 */
226
+	public static function bot_trap_settings_form()
227
+	{
228
+		EED_Bot_Trap::_bot_trap_settings_form()->enqueue_js();
229
+		echo EED_Bot_Trap::_bot_trap_settings_form()->get_html();
230
+	}
231 231
 
232 232
 
233
-    /**
234
-     * _bot_trap_settings_form
235
-     *
236
-     * @return EE_Form_Section_Proper
237
-     * @throws EE_Error
238
-     */
239
-    protected static function _bot_trap_settings_form()
240
-    {
241
-        return new EE_Form_Section_Proper(
242
-            array(
243
-                'name'            => 'bot_trap_settings',
244
-                'html_id'         => 'bot_trap_settings',
245
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
246
-                'subsections'     => array(
247
-                    'bot_trap_hdr' => new EE_Form_Section_HTML(
248
-                        EEH_HTML::h2(esc_html__('Bot Trap Settings', 'event_espresso'))
249
-                    ),
250
-                    'use_bot_trap' => new EE_Yes_No_Input(
251
-                        array(
252
-                            'html_label_text' => esc_html__('Enable Bot Trap', 'event_espresso'),
253
-                            'html_help_text'  => esc_html__(
254
-                                'The Event Espresso Bot Trap will insert a fake input into your Ticket Selector forms that is hidden from regular site visitors, but visible to spam bots. Because the input asks for an email address, it is irresistible to spam bots who will of course enter text into it. Since regular site visitors can not see this input, any value detected during form submission means a bot has been detected, which will then be blocked from submitting the form.',
255
-                                'event_espresso'
256
-                            ),
257
-                            'default'         => EE_Registry::instance()->CFG->registration->use_bot_trap !== null
258
-                                ? EE_Registry::instance()->CFG->registration->use_bot_trap
259
-                                : true,
260
-                            'required'        => false,
261
-                        )
262
-                    ),
263
-                ),
264
-            )
265
-        );
266
-    }
233
+	/**
234
+	 * _bot_trap_settings_form
235
+	 *
236
+	 * @return EE_Form_Section_Proper
237
+	 * @throws EE_Error
238
+	 */
239
+	protected static function _bot_trap_settings_form()
240
+	{
241
+		return new EE_Form_Section_Proper(
242
+			array(
243
+				'name'            => 'bot_trap_settings',
244
+				'html_id'         => 'bot_trap_settings',
245
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
246
+				'subsections'     => array(
247
+					'bot_trap_hdr' => new EE_Form_Section_HTML(
248
+						EEH_HTML::h2(esc_html__('Bot Trap Settings', 'event_espresso'))
249
+					),
250
+					'use_bot_trap' => new EE_Yes_No_Input(
251
+						array(
252
+							'html_label_text' => esc_html__('Enable Bot Trap', 'event_espresso'),
253
+							'html_help_text'  => esc_html__(
254
+								'The Event Espresso Bot Trap will insert a fake input into your Ticket Selector forms that is hidden from regular site visitors, but visible to spam bots. Because the input asks for an email address, it is irresistible to spam bots who will of course enter text into it. Since regular site visitors can not see this input, any value detected during form submission means a bot has been detected, which will then be blocked from submitting the form.',
255
+								'event_espresso'
256
+							),
257
+							'default'         => EE_Registry::instance()->CFG->registration->use_bot_trap !== null
258
+								? EE_Registry::instance()->CFG->registration->use_bot_trap
259
+								: true,
260
+							'required'        => false,
261
+						)
262
+					),
263
+				),
264
+			)
265
+		);
266
+	}
267 267
 
268 268
 
269
-    /**
270
-     * update_bot_trap_settings_form
271
-     *
272
-     * @param EE_Registration_Config $EE_Registration_Config
273
-     * @return EE_Registration_Config
274
-     * @throws EE_Error
275
-     * @throws InvalidArgumentException
276
-     * @throws ReflectionException
277
-     * @throws InvalidDataTypeException
278
-     * @throws InvalidInterfaceException
279
-     */
280
-    public static function update_bot_trap_settings_form(EE_Registration_Config $EE_Registration_Config)
281
-    {
282
-        try {
283
-            $bot_trap_settings_form = EED_Bot_Trap::_bot_trap_settings_form();
284
-            // if not displaying a form, then check for form submission
285
-            if ($bot_trap_settings_form->was_submitted()) {
286
-                // capture form data
287
-                $bot_trap_settings_form->receive_form_submission();
288
-                // validate form data
289
-                if ($bot_trap_settings_form->is_valid()) {
290
-                    // grab validated data from form
291
-                    $valid_data = $bot_trap_settings_form->valid_data();
292
-                    if (isset($valid_data['use_bot_trap'])) {
293
-                        $EE_Registration_Config->use_bot_trap = $valid_data['use_bot_trap'];
294
-                    } else {
295
-                        EE_Error::add_error(
296
-                            esc_html__(
297
-                                'Invalid or missing Bot Trap settings. Please refresh the form and try again.',
298
-                                'event_espresso'
299
-                            ),
300
-                            __FILE__,
301
-                            __FUNCTION__,
302
-                            __LINE__
303
-                        );
304
-                    }
305
-                } elseif ($bot_trap_settings_form->submission_error_message() !== '') {
306
-                    EE_Error::add_error(
307
-                        $bot_trap_settings_form->submission_error_message(),
308
-                        __FILE__,
309
-                        __FUNCTION__,
310
-                        __LINE__
311
-                    );
312
-                }
313
-            }
314
-        } catch (EE_Error $e) {
315
-            $e->get_error();
316
-        }
317
-        return $EE_Registration_Config;
318
-    }
269
+	/**
270
+	 * update_bot_trap_settings_form
271
+	 *
272
+	 * @param EE_Registration_Config $EE_Registration_Config
273
+	 * @return EE_Registration_Config
274
+	 * @throws EE_Error
275
+	 * @throws InvalidArgumentException
276
+	 * @throws ReflectionException
277
+	 * @throws InvalidDataTypeException
278
+	 * @throws InvalidInterfaceException
279
+	 */
280
+	public static function update_bot_trap_settings_form(EE_Registration_Config $EE_Registration_Config)
281
+	{
282
+		try {
283
+			$bot_trap_settings_form = EED_Bot_Trap::_bot_trap_settings_form();
284
+			// if not displaying a form, then check for form submission
285
+			if ($bot_trap_settings_form->was_submitted()) {
286
+				// capture form data
287
+				$bot_trap_settings_form->receive_form_submission();
288
+				// validate form data
289
+				if ($bot_trap_settings_form->is_valid()) {
290
+					// grab validated data from form
291
+					$valid_data = $bot_trap_settings_form->valid_data();
292
+					if (isset($valid_data['use_bot_trap'])) {
293
+						$EE_Registration_Config->use_bot_trap = $valid_data['use_bot_trap'];
294
+					} else {
295
+						EE_Error::add_error(
296
+							esc_html__(
297
+								'Invalid or missing Bot Trap settings. Please refresh the form and try again.',
298
+								'event_espresso'
299
+							),
300
+							__FILE__,
301
+							__FUNCTION__,
302
+							__LINE__
303
+						);
304
+					}
305
+				} elseif ($bot_trap_settings_form->submission_error_message() !== '') {
306
+					EE_Error::add_error(
307
+						$bot_trap_settings_form->submission_error_message(),
308
+						__FILE__,
309
+						__FUNCTION__,
310
+						__LINE__
311
+					);
312
+				}
313
+			}
314
+		} catch (EE_Error $e) {
315
+			$e->get_error();
316
+		}
317
+		return $EE_Registration_Config;
318
+	}
319 319
 }
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.