Completed
Branch BUG/fix-country-code-request (b45476)
by
unknown
05:35 queued 03:17
created
admin_pages/general_settings/General_Settings_Admin_Page.core.php 1 patch
Indentation   +1414 added lines, -1414 removed lines patch added patch discarded remove patch
@@ -20,1429 +20,1429 @@
 block discarded – undo
20 20
 class General_Settings_Admin_Page extends EE_Admin_Page
21 21
 {
22 22
 
23
-    /**
24
-     * @var EE_Core_Config
25
-     */
26
-    public $core_config;
27
-
28
-
29
-    /**
30
-     * Initialize basic properties.
31
-     */
32
-    protected function _init_page_props()
33
-    {
34
-        $this->page_slug        = GEN_SET_PG_SLUG;
35
-        $this->page_label       = GEN_SET_LABEL;
36
-        $this->_admin_base_url  = GEN_SET_ADMIN_URL;
37
-        $this->_admin_base_path = GEN_SET_ADMIN;
38
-    }
39
-
40
-
41
-    /**
42
-     * Set ajax hooks
43
-     */
44
-    protected function _ajax_hooks()
45
-    {
46
-        add_action('wp_ajax_espresso_display_country_settings', [$this, 'display_country_settings']);
47
-        add_action('wp_ajax_espresso_display_country_states', [$this, 'display_country_states']);
48
-        add_action('wp_ajax_espresso_delete_state', [$this, 'delete_state'], 10, 3);
49
-        add_action('wp_ajax_espresso_add_new_state', [$this, 'add_new_state']);
50
-    }
51
-
52
-
53
-    /**
54
-     * More page properties initialization.
55
-     */
56
-    protected function _define_page_props()
57
-    {
58
-        $this->_admin_page_title = GEN_SET_LABEL;
59
-        $this->_labels           = ['publishbox' => esc_html__('Update Settings', 'event_espresso')];
60
-    }
61
-
62
-
63
-    /**
64
-     * Set page routes property.
65
-     */
66
-    protected function _set_page_routes()
67
-    {
68
-        $this->_page_routes = [
69
-            'critical_pages'                => [
70
-                'func'       => '_espresso_page_settings',
71
-                'capability' => 'manage_options',
72
-            ],
73
-            'update_espresso_page_settings' => [
74
-                'func'       => '_update_espresso_page_settings',
75
-                'capability' => 'manage_options',
76
-                'noheader'   => true,
77
-            ],
78
-            'default'                       => [
79
-                'func'       => '_your_organization_settings',
80
-                'capability' => 'manage_options',
81
-            ],
82
-
83
-            'update_your_organization_settings' => [
84
-                'func'       => '_update_your_organization_settings',
85
-                'capability' => 'manage_options',
86
-                'noheader'   => true,
87
-            ],
88
-
89
-            'admin_option_settings' => [
90
-                'func'       => '_admin_option_settings',
91
-                'capability' => 'manage_options',
92
-            ],
93
-
94
-            'update_admin_option_settings' => [
95
-                'func'       => '_update_admin_option_settings',
96
-                'capability' => 'manage_options',
97
-                'noheader'   => true,
98
-            ],
99
-
100
-            'country_settings' => [
101
-                'func'       => '_country_settings',
102
-                'capability' => 'manage_options',
103
-            ],
104
-
105
-            'update_country_settings' => [
106
-                'func'       => '_update_country_settings',
107
-                'capability' => 'manage_options',
108
-                'noheader'   => true,
109
-            ],
110
-
111
-            'display_country_settings' => [
112
-                'func'       => 'display_country_settings',
113
-                'capability' => 'manage_options',
114
-                'noheader'   => true,
115
-            ],
116
-
117
-            'add_new_state' => [
118
-                'func'       => 'add_new_state',
119
-                'capability' => 'manage_options',
120
-                'noheader'   => true,
121
-            ],
122
-
123
-            'delete_state'            => [
124
-                'func'       => 'delete_state',
125
-                'capability' => 'manage_options',
126
-                'noheader'   => true,
127
-            ],
128
-            'privacy_settings'        => [
129
-                'func'       => 'privacySettings',
130
-                'capability' => 'manage_options',
131
-            ],
132
-            'update_privacy_settings' => [
133
-                'func'               => 'updatePrivacySettings',
134
-                'capability'         => 'manage_options',
135
-                'noheader'           => true,
136
-                'headers_sent_route' => 'privacy_settings',
137
-            ],
138
-        ];
139
-    }
140
-
141
-
142
-    /**
143
-     * Set page configuration property
144
-     */
145
-    protected function _set_page_config()
146
-    {
147
-        $this->_page_config = [
148
-            'critical_pages'        => [
149
-                'nav'           => [
150
-                    'label' => esc_html__('Critical Pages', 'event_espresso'),
151
-                    'order' => 50,
152
-                ],
153
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
154
-                'help_tabs'     => [
155
-                    'general_settings_critical_pages_help_tab' => [
156
-                        'title'    => esc_html__('Critical Pages', 'event_espresso'),
157
-                        'filename' => 'general_settings_critical_pages',
158
-                    ],
159
-                ],
160
-                'require_nonce' => false,
161
-            ],
162
-            'default'               => [
163
-                'nav'           => [
164
-                    'label' => esc_html__('Your Organization', 'event_espresso'),
165
-                    'order' => 20,
166
-                ],
167
-                'help_tabs'     => [
168
-                    'general_settings_your_organization_help_tab' => [
169
-                        'title'    => esc_html__('Your Organization', 'event_espresso'),
170
-                        'filename' => 'general_settings_your_organization',
171
-                    ],
172
-                ],
173
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
174
-                'require_nonce' => false,
175
-            ],
176
-            'admin_option_settings' => [
177
-                'nav'           => [
178
-                    'label' => esc_html__('Admin Options', 'event_espresso'),
179
-                    'order' => 60,
180
-                ],
181
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
182
-                'help_tabs'     => [
183
-                    'general_settings_admin_options_help_tab' => [
184
-                        'title'    => esc_html__('Admin Options', 'event_espresso'),
185
-                        'filename' => 'general_settings_admin_options',
186
-                    ],
187
-                ],
188
-                'require_nonce' => false,
189
-            ],
190
-            'country_settings'      => [
191
-                'nav'           => [
192
-                    'label' => esc_html__('Countries', 'event_espresso'),
193
-                    'order' => 70,
194
-                ],
195
-                'help_tabs'     => [
196
-                    'general_settings_countries_help_tab' => [
197
-                        'title'    => esc_html__('Countries', 'event_espresso'),
198
-                        'filename' => 'general_settings_countries',
199
-                    ],
200
-                ],
201
-                'require_nonce' => false,
202
-            ],
203
-            'privacy_settings'      => [
204
-                'nav'           => [
205
-                    'label' => esc_html__('Privacy', 'event_espresso'),
206
-                    'order' => 80,
207
-                ],
208
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
209
-                'require_nonce' => false,
210
-            ],
211
-        ];
212
-    }
213
-
214
-
215
-    protected function _add_screen_options()
216
-    {
217
-    }
218
-
219
-
220
-    protected function _add_feature_pointers()
221
-    {
222
-    }
223
-
224
-
225
-    /**
226
-     * Enqueue global scripts and styles for all routes in the General Settings Admin Pages.
227
-     */
228
-    public function load_scripts_styles()
229
-    {
230
-        // styles
231
-        wp_enqueue_style('espresso-ui-theme');
232
-        // scripts
233
-        wp_enqueue_script('ee_admin_js');
234
-    }
235
-
236
-
237
-    /**
238
-     * Execute logic running on `admin_init`
239
-     */
240
-    public function admin_init()
241
-    {
242
-        $this->core_config = EE_Registry::instance()->CFG->core;
243
-
244
-        EE_Registry::$i18n_js_strings['invalid_server_response'] = wp_strip_all_tags(
245
-            esc_html__(
246
-                '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.',
247
-                'event_espresso'
248
-            )
249
-        );
250
-        EE_Registry::$i18n_js_strings['error_occurred']          = wp_strip_all_tags(
251
-            esc_html__(
252
-                'An error occurred! Please refresh the page and try again.',
253
-                'event_espresso'
254
-            )
255
-        );
256
-        EE_Registry::$i18n_js_strings['confirm_delete_state']    = wp_strip_all_tags(
257
-            esc_html__(
258
-                'Are you sure you want to delete this State / Province?',
259
-                'event_espresso'
260
-            )
261
-        );
262
-        EE_Registry::$i18n_js_strings['ajax_url']                = admin_url(
263
-            'admin-ajax.php?page=espresso_general_settings',
264
-            is_ssl() ? 'https://' : 'http://'
265
-        );
266
-    }
267
-
268
-
269
-    public function admin_notices()
270
-    {
271
-    }
272
-
273
-
274
-    public function admin_footer_scripts()
275
-    {
276
-    }
277
-
278
-
279
-    /**
280
-     * Enqueue scripts and styles for the default route.
281
-     */
282
-    public function load_scripts_styles_default()
283
-    {
284
-        // styles
285
-        wp_enqueue_style('thickbox');
286
-        // scripts
287
-        wp_enqueue_script('media-upload');
288
-        wp_enqueue_script('thickbox');
289
-        wp_register_script(
290
-            'organization_settings',
291
-            GEN_SET_ASSETS_URL . 'your_organization_settings.js',
292
-            ['jquery', 'media-upload', 'thickbox'],
293
-            EVENT_ESPRESSO_VERSION,
294
-            true
295
-        );
296
-        wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', [], EVENT_ESPRESSO_VERSION);
297
-        wp_enqueue_script('organization_settings');
298
-        wp_enqueue_style('organization-css');
299
-        $confirm_image_delete = [
300
-            'text' => wp_strip_all_tags(
301
-                esc_html__(
302
-                    'Do you really want to delete this image? Please remember to save your settings to complete the removal.',
303
-                    'event_espresso'
304
-                )
305
-            ),
306
-        ];
307
-        wp_localize_script('organization_settings', 'confirm_image_delete', $confirm_image_delete);
308
-    }
309
-
310
-
311
-    /**
312
-     * Enqueue scripts and styles for the country settings route.
313
-     */
314
-    public function load_scripts_styles_country_settings()
315
-    {
316
-        // scripts
317
-        wp_register_script(
318
-            'gen_settings_countries',
319
-            GEN_SET_ASSETS_URL . 'gen_settings_countries.js',
320
-            ['ee_admin_js'],
321
-            EVENT_ESPRESSO_VERSION,
322
-            true
323
-        );
324
-        wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', [], EVENT_ESPRESSO_VERSION);
325
-        wp_enqueue_script('gen_settings_countries');
326
-        wp_enqueue_style('organization-css');
327
-    }
328
-
329
-
330
-    /*************        Espresso Pages        *************/
331
-    /**
332
-     * _espresso_page_settings
333
-     *
334
-     * @throws EE_Error
335
-     * @throws DomainException
336
-     * @throws DomainException
337
-     * @throws InvalidDataTypeException
338
-     * @throws InvalidArgumentException
339
-     */
340
-    protected function _espresso_page_settings()
341
-    {
342
-        // Check to make sure all of the main pages are set up properly,
343
-        // if not create the default pages and display an admin notice
344
-        EEH_Activation::verify_default_pages_exist();
345
-        $this->_transient_garbage_collection();
346
-
347
-        $this->_template_args['values'] = $this->_yes_no_values;
348
-
349
-        $this->_template_args['reg_page_id']  = $this->core_config->reg_page_id ?? null;
350
-        $this->_template_args['reg_page_obj'] = isset($this->core_config->reg_page_id)
351
-            ? get_post($this->core_config->reg_page_id)
352
-            : false;
353
-
354
-        $this->_template_args['txn_page_id']  = $this->core_config->txn_page_id ?? null;
355
-        $this->_template_args['txn_page_obj'] = isset($this->core_config->txn_page_id)
356
-            ? get_post($this->core_config->txn_page_id)
357
-            : false;
358
-
359
-        $this->_template_args['thank_you_page_id']  = $this->core_config->thank_you_page_id ?? null;
360
-        $this->_template_args['thank_you_page_obj'] = isset($this->core_config->thank_you_page_id)
361
-            ? get_post($this->core_config->thank_you_page_id)
362
-            : false;
363
-
364
-        $this->_template_args['cancel_page_id']  = $this->core_config->cancel_page_id ?? null;
365
-        $this->_template_args['cancel_page_obj'] = isset($this->core_config->cancel_page_id)
366
-            ? get_post($this->core_config->cancel_page_id)
367
-            : false;
368
-
369
-        $this->_set_add_edit_form_tags('update_espresso_page_settings');
370
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
371
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
372
-            GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php',
373
-            $this->_template_args,
374
-            true
375
-        );
376
-        $this->display_admin_page_with_sidebar();
377
-    }
378
-
379
-
380
-    /**
381
-     * Handler for updating espresso page settings.
382
-     *
383
-     * @throws EE_Error
384
-     */
385
-    protected function _update_espresso_page_settings()
386
-    {
387
-        // capture incoming request data && set page IDs
388
-        $this->core_config->reg_page_id       = $this->request->getRequestParam(
389
-            'reg_page_id',
390
-            $this->core_config->reg_page_id,
391
-            DataType::INT
392
-        );
393
-        $this->core_config->txn_page_id       = $this->request->getRequestParam(
394
-            'txn_page_id',
395
-            $this->core_config->txn_page_id,
396
-            DataType::INT
397
-        );
398
-        $this->core_config->thank_you_page_id = $this->request->getRequestParam(
399
-            'thank_you_page_id',
400
-            $this->core_config->thank_you_page_id,
401
-            DataType::INT
402
-        );
403
-        $this->core_config->cancel_page_id    = $this->request->getRequestParam(
404
-            'cancel_page_id',
405
-            $this->core_config->cancel_page_id,
406
-            DataType::INT
407
-        );
408
-
409
-        $this->core_config = apply_filters(
410
-            'FHEE__General_Settings_Admin_Page___update_espresso_page_settings__CFG_core',
411
-            $this->core_config,
412
-            $this->request->requestParams()
413
-        );
414
-
415
-        $what = esc_html__('Critical Pages & Shortcodes', 'event_espresso');
416
-        $this->_redirect_after_action(
417
-            $this->_update_espresso_configuration(
418
-                $what,
419
-                $this->core_config,
420
-                __FILE__,
421
-                __FUNCTION__,
422
-                __LINE__
423
-            ),
424
-            $what,
425
-            '',
426
-            [
427
-                'action' => 'critical_pages',
428
-            ],
429
-            true
430
-        );
431
-    }
432
-
433
-
434
-    /*************        Your Organization        *************/
435
-
436
-
437
-    /**
438
-     * @throws DomainException
439
-     * @throws EE_Error
440
-     * @throws InvalidArgumentException
441
-     * @throws InvalidDataTypeException
442
-     * @throws InvalidInterfaceException
443
-     */
444
-    protected function _your_organization_settings()
445
-    {
446
-        $this->_template_args['admin_page_content'] = '';
447
-        try {
448
-            /** @var OrganizationSettings $organization_settings_form */
449
-            $organization_settings_form = $this->loader->getShared(OrganizationSettings::class);
450
-
451
-            $this->_template_args['admin_page_content'] = EEH_HTML::div(
452
-                $organization_settings_form->display(),
453
-                '',
454
-                'padding'
455
-            );
456
-        } catch (Exception $e) {
457
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
458
-        }
459
-        $this->_set_add_edit_form_tags('update_your_organization_settings');
460
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
461
-        $this->display_admin_page_with_sidebar();
462
-    }
463
-
464
-
465
-    /**
466
-     * Handler for updating organization settings.
467
-     *
468
-     * @throws EE_Error
469
-     */
470
-    protected function _update_your_organization_settings()
471
-    {
472
-        try {
473
-            /** @var OrganizationSettings $organization_settings_form */
474
-            $organization_settings_form = $this->loader->getShared(OrganizationSettings::class);
475
-
476
-            $success = $organization_settings_form->process($this->request->requestParams());
477
-
478
-            EE_Registry::instance()->CFG = apply_filters(
479
-                'FHEE__General_Settings_Admin_Page___update_your_organization_settings__CFG',
480
-                EE_Registry::instance()->CFG
481
-            );
482
-        } catch (Exception $e) {
483
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
484
-            $success = false;
485
-        }
486
-
487
-        if ($success) {
488
-            $success = $this->_update_espresso_configuration(
489
-                esc_html__('Your Organization Settings', 'event_espresso'),
490
-                EE_Registry::instance()->CFG,
491
-                __FILE__,
492
-                __FUNCTION__,
493
-                __LINE__
494
-            );
495
-        }
496
-
497
-        $this->_redirect_after_action($success, '', '', ['action' => 'default'], true);
498
-    }
499
-
500
-
501
-
502
-    /*************        Admin Options        *************/
503
-
504
-
505
-    /**
506
-     * _admin_option_settings
507
-     *
508
-     * @throws EE_Error
509
-     * @throws LogicException
510
-     */
511
-    protected function _admin_option_settings()
512
-    {
513
-        $this->_template_args['admin_page_content'] = '';
514
-        try {
515
-            $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
516
-            // still need this for the old school form in Extend_General_Settings_Admin_Page
517
-            $this->_template_args['values'] = $this->_yes_no_values;
518
-            // also need to account for the do_action that was in the old template
519
-            $admin_options_settings_form->setTemplateArgs($this->_template_args);
520
-            $this->_template_args['admin_page_content'] = $admin_options_settings_form->display();
521
-        } catch (Exception $e) {
522
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
523
-        }
524
-        $this->_set_add_edit_form_tags('update_admin_option_settings');
525
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
526
-        $this->display_admin_page_with_sidebar();
527
-    }
528
-
529
-
530
-    /**
531
-     * _update_admin_option_settings
532
-     *
533
-     * @throws EE_Error
534
-     * @throws InvalidDataTypeException
535
-     * @throws InvalidFormSubmissionException
536
-     * @throws InvalidArgumentException
537
-     * @throws LogicException
538
-     */
539
-    protected function _update_admin_option_settings()
540
-    {
541
-        try {
542
-            $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
543
-            $admin_options_settings_form->process(
544
-                $this->request->getRequestParam(
545
-                    $admin_options_settings_form->slug(),
546
-                    [],
547
-                    DataType::OBJECT // need to change this to ARRAY after min PHP version gets bumped to 7+
548
-                )
549
-            );
550
-            EE_Registry::instance()->CFG->admin = apply_filters(
551
-                'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin',
552
-                EE_Registry::instance()->CFG->admin
553
-            );
554
-        } catch (Exception $e) {
555
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
556
-        }
557
-        $this->_redirect_after_action(
558
-            apply_filters(
559
-                'FHEE__General_Settings_Admin_Page___update_admin_option_settings__success',
560
-                $this->_update_espresso_configuration(
561
-                    esc_html__('Admin Options', 'event_espresso'),
562
-                    EE_Registry::instance()->CFG->admin,
563
-                    __FILE__,
564
-                    __FUNCTION__,
565
-                    __LINE__
566
-                )
567
-            ),
568
-            esc_html__('Admin Options', 'event_espresso'),
569
-            'updated',
570
-            ['action' => 'admin_option_settings']
571
-        );
572
-    }
573
-
574
-
575
-    /*************        Countries        *************/
576
-
577
-
578
-    /**
579
-     * @param string|null $default
580
-     * @return string
581
-     */
582
-    protected function getCountryISO(?string $default = null): string
583
-    {
584
-        $default = $default ?? $this->getCountryIsoForSite();
585
-        $CNT_ISO = $this->request->getRequestParam('country', $default);
586
-        $CNT_ISO = $this->request->getRequestParam('CNT_ISO', $CNT_ISO);
587
-        return strtoupper($CNT_ISO);
588
-    }
589
-
590
-
591
-    /**
592
-     * @return string
593
-     */
594
-    protected function getCountryIsoForSite(): string
595
-    {
596
-        return ! empty(EE_Registry::instance()->CFG->organization->CNT_ISO)
597
-            ? EE_Registry::instance()->CFG->organization->CNT_ISO
598
-            : 'US';
599
-    }
600
-
601
-
602
-    /**
603
-     * @param string          $CNT_ISO
604
-     * @param EE_Country|null $country
605
-     * @return EE_Base_Class|EE_Country
606
-     * @throws EE_Error
607
-     * @throws InvalidArgumentException
608
-     * @throws InvalidDataTypeException
609
-     * @throws InvalidInterfaceException
610
-     * @throws ReflectionException
611
-     */
612
-    protected function verifyOrGetCountryFromIso(string $CNT_ISO, ?EE_Country $country = null)
613
-    {
614
-        /** @var EE_Country $country */
615
-        return $country instanceof EE_Country && $country->ID() === $CNT_ISO
616
-            ? $country
617
-            : EEM_Country::instance()->get_one_by_ID($CNT_ISO);
618
-    }
619
-
620
-
621
-    /**
622
-     * Output Country Settings view.
623
-     *
624
-     * @throws DomainException
625
-     * @throws EE_Error
626
-     * @throws InvalidArgumentException
627
-     * @throws InvalidDataTypeException
628
-     * @throws InvalidInterfaceException
629
-     * @throws ReflectionException
630
-     */
631
-    protected function _country_settings()
632
-    {
633
-        $CNT_ISO = $this->getCountryISO();
634
-
635
-        $this->_template_args['values']    = $this->_yes_no_values;
636
-        $this->_template_args['countries'] = new EE_Question_Form_Input(
637
-            EE_Question::new_instance(
638
-                [
639
-                    'QST_ID'           => 0,
640
-                    'QST_display_text' => esc_html__('Select Country', 'event_espresso'),
641
-                    'QST_system'       => 'admin-country',
642
-                ]
643
-            ),
644
-            EE_Answer::new_instance(
645
-                [
646
-                    'ANS_ID'    => 0,
647
-                    'ANS_value' => $CNT_ISO,
648
-                ]
649
-            ),
650
-            [
651
-                'input_id'       => 'country',
652
-                'input_name'     => 'country',
653
-                'input_prefix'   => '',
654
-                'append_qstn_id' => false,
655
-            ]
656
-        );
657
-
658
-        $country = $this->verifyOrGetCountryFromIso($CNT_ISO);
659
-        add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'country_form_field_label_wrap'], 10);
660
-        add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'country_form_field_input__wrap'], 10);
661
-        $this->_template_args['country_details_settings'] = $this->display_country_settings(
662
-            $country->ID(),
663
-            $country
664
-        );
665
-        $this->_template_args['country_states_settings']  = $this->display_country_states(
666
-            $country->ID(),
667
-            $country
668
-        );
669
-        $this->_template_args['CNT_name_for_site']        = $country->name();
670
-
671
-        $this->_set_add_edit_form_tags('update_country_settings');
672
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
673
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
674
-            GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php',
675
-            $this->_template_args,
676
-            true
677
-        );
678
-        $this->display_admin_page_with_no_sidebar();
679
-    }
680
-
681
-
682
-    /**
683
-     * @param string          $CNT_ISO
684
-     * @param EE_Country|null $country
685
-     * @return string
686
-     * @throws DomainException
687
-     * @throws EE_Error
688
-     * @throws InvalidArgumentException
689
-     * @throws InvalidDataTypeException
690
-     * @throws InvalidInterfaceException
691
-     * @throws ReflectionException
692
-     */
693
-    public function display_country_settings(string $CNT_ISO = '', ?EE_Country $country = null): string
694
-    {
695
-        $CNT_ISO          = $this->getCountryISO($CNT_ISO);
696
-        $CNT_ISO_for_site = $this->getCountryIsoForSite();
697
-
698
-        if (! $CNT_ISO) {
699
-            return '';
700
-        }
701
-
702
-        // for ajax
703
-        remove_all_filters('FHEE__EEH_Form_Fields__label_html');
704
-        remove_all_filters('FHEE__EEH_Form_Fields__input_html');
705
-        add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'country_form_field_label_wrap'], 10, 2);
706
-        add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'country_form_field_input__wrap'], 10, 2);
707
-        $country                                  = $this->verifyOrGetCountryFromIso($CNT_ISO, $country);
708
-        $CNT_cur_disabled                         = $CNT_ISO !== $CNT_ISO_for_site;
709
-        $this->_template_args['CNT_cur_disabled'] = $CNT_cur_disabled;
710
-
711
-        $country_input_types            = [
712
-            'CNT_active'      => [
713
-                'type'             => 'RADIO_BTN',
714
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
715
-                'class'            => '',
716
-                'options'          => $this->_yes_no_values,
717
-                'use_desc_4_label' => true,
718
-            ],
719
-            'CNT_ISO'         => [
720
-                'type'       => 'TEXT',
721
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
722
-                'class'      => 'small-text',
723
-            ],
724
-            'CNT_ISO3'        => [
725
-                'type'       => 'TEXT',
726
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
727
-                'class'      => 'small-text',
728
-            ],
729
-            // 'RGN_ID'          => [
730
-            //     'type'       => 'TEXT',
731
-            //     'input_name' => 'cntry[' . $CNT_ISO . ']',
732
-            //     'class'      => 'ee-input-size--small',
733
-            // ],
734
-            'CNT_name'        => [
735
-                'type'       => 'TEXT',
736
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
737
-                'class'      => 'regular-text',
738
-            ],
739
-            'CNT_cur_code'    => [
740
-                'type'       => 'TEXT',
741
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
742
-                'class'      => 'small-text',
743
-                'disabled'   => $CNT_cur_disabled,
744
-            ],
745
-            'CNT_cur_single'  => [
746
-                'type'       => 'TEXT',
747
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
748
-                'class'      => 'medium-text',
749
-                'disabled'   => $CNT_cur_disabled,
750
-            ],
751
-            'CNT_cur_plural'  => [
752
-                'type'       => 'TEXT',
753
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
754
-                'class'      => 'medium-text',
755
-                'disabled'   => $CNT_cur_disabled,
756
-            ],
757
-            'CNT_cur_sign'    => [
758
-                'type'         => 'TEXT',
759
-                'input_name'   => 'cntry[' . $CNT_ISO . ']',
760
-                'class'        => 'small-text',
761
-                'htmlentities' => false,
762
-                'disabled'     => $CNT_cur_disabled,
763
-            ],
764
-            'CNT_cur_sign_b4' => [
765
-                'type'             => 'RADIO_BTN',
766
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
767
-                'class'            => '',
768
-                'options'          => $this->_yes_no_values,
769
-                'use_desc_4_label' => true,
770
-                'disabled'         => $CNT_cur_disabled,
771
-            ],
772
-            'CNT_cur_dec_plc' => [
773
-                'type'       => 'RADIO_BTN',
774
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
775
-                'class'      => '',
776
-                'options'    => [
777
-                    ['id' => 0, 'text' => ''],
778
-                    ['id' => 1, 'text' => ''],
779
-                    ['id' => 2, 'text' => ''],
780
-                    ['id' => 3, 'text' => ''],
781
-                ],
782
-                'disabled'   => $CNT_cur_disabled,
783
-            ],
784
-            'CNT_cur_dec_mrk' => [
785
-                'type'             => 'RADIO_BTN',
786
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
787
-                'class'            => '',
788
-                'options'          => [
789
-                    [
790
-                        'id'   => ',',
791
-                        'text' => esc_html__(', (comma)', 'event_espresso'),
792
-                    ],
793
-                    ['id' => '.', 'text' => esc_html__('. (decimal)', 'event_espresso')],
794
-                ],
795
-                'use_desc_4_label' => true,
796
-                'disabled'         => $CNT_cur_disabled,
797
-            ],
798
-            'CNT_cur_thsnds'  => [
799
-                'type'             => 'RADIO_BTN',
800
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
801
-                'class'            => '',
802
-                'options'          => [
803
-                    [
804
-                        'id'   => ',',
805
-                        'text' => esc_html__(', (comma)', 'event_espresso'),
806
-                    ],
807
-                    [
808
-                        'id'   => '.',
809
-                        'text' => esc_html__('. (decimal)', 'event_espresso'),
810
-                    ],
811
-                    [
812
-                        'id'   => ' ',
813
-                        'text' => esc_html__('(space)', 'event_espresso'),
814
-                    ],
815
-                ],
816
-                'use_desc_4_label' => true,
817
-                'disabled'         => $CNT_cur_disabled,
818
-            ],
819
-            'CNT_tel_code'    => [
820
-                'type'       => 'TEXT',
821
-                'input_name' => 'cntry[' . $CNT_ISO . ']',
822
-                'class'      => 'small-text',
823
-            ],
824
-            'CNT_is_EU'       => [
825
-                'type'             => 'RADIO_BTN',
826
-                'input_name'       => 'cntry[' . $CNT_ISO . ']',
827
-                'class'            => '',
828
-                'options'          => $this->_yes_no_values,
829
-                'use_desc_4_label' => true,
830
-            ],
831
-        ];
832
-        $this->_template_args['inputs'] = EE_Question_Form_Input::generate_question_form_inputs_for_object(
833
-            $country,
834
-            $country_input_types
835
-        );
836
-        $country_details_settings       = EEH_Template::display_template(
837
-            GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php',
838
-            $this->_template_args,
839
-            true
840
-        );
841
-
842
-        if (defined('DOING_AJAX')) {
843
-            $notices = EE_Error::get_notices(false, false, false);
844
-            echo wp_json_encode(
845
-                [
846
-                    'return_data' => $country_details_settings,
847
-                    'success'     => $notices['success'],
848
-                    'errors'      => $notices['errors'],
849
-                ]
850
-            );
851
-            die();
852
-        }
853
-        return $country_details_settings;
854
-    }
855
-
856
-
857
-    /**
858
-     * @param string          $CNT_ISO
859
-     * @param EE_Country|null $country
860
-     * @return string
861
-     * @throws DomainException
862
-     * @throws EE_Error
863
-     * @throws InvalidArgumentException
864
-     * @throws InvalidDataTypeException
865
-     * @throws InvalidInterfaceException
866
-     * @throws ReflectionException
867
-     */
868
-    public function display_country_states(string $CNT_ISO = '', ?EE_Country $country = null): string
869
-    {
870
-        $CNT_ISO = $this->getCountryISO($CNT_ISO);
871
-        if (! $CNT_ISO) {
872
-            return '';
873
-        }
874
-        // for ajax
875
-        remove_all_filters('FHEE__EEH_Form_Fields__label_html');
876
-        remove_all_filters('FHEE__EEH_Form_Fields__input_html');
877
-        add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'state_form_field_label_wrap'], 10, 2);
878
-        add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'state_form_field_input__wrap'], 10);
879
-        $states = EEM_State::instance()->get_all_states_for_these_countries([$CNT_ISO => $CNT_ISO]);
880
-        if (empty($states)) {
881
-            /** @var EventEspresso\core\services\address\CountrySubRegionDao $countrySubRegionDao */
882
-            $countrySubRegionDao = $this->loader->getShared(
883
-                'EventEspresso\core\services\address\CountrySubRegionDao'
884
-            );
885
-            if ($countrySubRegionDao instanceof EventEspresso\core\services\address\CountrySubRegionDao) {
886
-                $country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country);
887
-                if ($countrySubRegionDao->saveCountrySubRegions($country)) {
888
-                    $states = EEM_State::instance()->get_all_states_for_these_countries([$CNT_ISO => $CNT_ISO]);
889
-                }
890
-            }
891
-        }
892
-        if (is_array($states)) {
893
-            foreach ($states as $STA_ID => $state) {
894
-                if ($state instanceof EE_State) {
895
-                    $inputs = EE_Question_Form_Input::generate_question_form_inputs_for_object(
896
-                        $state,
897
-                        [
898
-                            'STA_abbrev' => [
899
-                                'type'             => 'TEXT',
900
-                                'label'            => esc_html__('Code', 'event_espresso'),
901
-                                'input_name'       => 'states[' . $STA_ID . ']',
902
-                                'class'            => 'small-text',
903
-                                'add_mobile_label' => true,
904
-                            ],
905
-                            'STA_name'   => [
906
-                                'type'             => 'TEXT',
907
-                                'label'            => esc_html__('Name', 'event_espresso'),
908
-                                'input_name'       => 'states[' . $STA_ID . ']',
909
-                                'class'            => 'regular-text',
910
-                                'add_mobile_label' => true,
911
-                            ],
912
-                            'STA_active' => [
913
-                                'type'             => 'RADIO_BTN',
914
-                                'label'            => esc_html__(
915
-                                    'State Appears in Dropdown Select Lists',
916
-                                    'event_espresso'
917
-                                ),
918
-                                'input_name'       => 'states[' . $STA_ID . ']',
919
-                                'options'          => $this->_yes_no_values,
920
-                                'use_desc_4_label' => true,
921
-                                'add_mobile_label' => true,
922
-                            ],
923
-                        ]
924
-                    );
925
-
926
-                    $delete_state_url = EE_Admin_Page::add_query_args_and_nonce(
927
-                        [
928
-                            'action'     => 'delete_state',
929
-                            'STA_ID'     => $STA_ID,
930
-                            'CNT_ISO'    => $CNT_ISO,
931
-                            'STA_abbrev' => $state->abbrev(),
932
-                        ],
933
-                        GEN_SET_ADMIN_URL
934
-                    );
935
-
936
-                    $this->_template_args['states'][ $STA_ID ]['inputs']           = $inputs;
937
-                    $this->_template_args['states'][ $STA_ID ]['delete_state_url'] = $delete_state_url;
938
-                }
939
-            }
940
-        } else {
941
-            $this->_template_args['states'] = false;
942
-        }
943
-
944
-        $this->_template_args['add_new_state_url'] = EE_Admin_Page::add_query_args_and_nonce(
945
-            ['action' => 'add_new_state'],
946
-            GEN_SET_ADMIN_URL
947
-        );
948
-
949
-        $state_details_settings = EEH_Template::display_template(
950
-            GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php',
951
-            $this->_template_args,
952
-            true
953
-        );
954
-
955
-        if (defined('DOING_AJAX')) {
956
-            $notices = EE_Error::get_notices(false, false, false);
957
-            echo wp_json_encode(
958
-                [
959
-                    'return_data' => $state_details_settings,
960
-                    'success'     => $notices['success'],
961
-                    'errors'      => $notices['errors'],
962
-                ]
963
-            );
964
-            die();
965
-        }
966
-        return $state_details_settings;
967
-    }
968
-
969
-
970
-    /**
971
-     * @return void
972
-     * @throws EE_Error
973
-     * @throws InvalidArgumentException
974
-     * @throws InvalidDataTypeException
975
-     * @throws InvalidInterfaceException
976
-     * @throws ReflectionException
977
-     */
978
-    public function add_new_state()
979
-    {
980
-        $success = true;
981
-        $CNT_ISO = $this->getCountryISO('');
982
-        if (! $CNT_ISO) {
983
-            EE_Error::add_error(
984
-                esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
985
-                __FILE__,
986
-                __FUNCTION__,
987
-                __LINE__
988
-            );
989
-            $success = false;
990
-        }
991
-        $STA_abbrev = $this->request->getRequestParam('STA_abbrev');
992
-        if (! $STA_abbrev) {
993
-            EE_Error::add_error(
994
-                esc_html__('No State ISO code or an invalid State ISO code was received.', 'event_espresso'),
995
-                __FILE__,
996
-                __FUNCTION__,
997
-                __LINE__
998
-            );
999
-            $success = false;
1000
-        }
1001
-        $STA_name = $this->request->getRequestParam('STA_name');
1002
-        if (! $STA_name) {
1003
-            EE_Error::add_error(
1004
-                esc_html__('No State name or an invalid State name was received.', 'event_espresso'),
1005
-                __FILE__,
1006
-                __FUNCTION__,
1007
-                __LINE__
1008
-            );
1009
-            $success = false;
1010
-        }
1011
-
1012
-        if ($success) {
1013
-            $cols_n_values = [
1014
-                'CNT_ISO'    => $CNT_ISO,
1015
-                'STA_abbrev' => $STA_abbrev,
1016
-                'STA_name'   => $STA_name,
1017
-                'STA_active' => true,
1018
-            ];
1019
-            $success       = EEM_State::instance()->insert($cols_n_values);
1020
-            EE_Error::add_success(esc_html__('The State was added successfully.', 'event_espresso'));
1021
-        }
1022
-
1023
-        if (defined('DOING_AJAX')) {
1024
-            $notices = EE_Error::get_notices(false, false, false);
1025
-            echo wp_json_encode(array_merge($notices, ['return_data' => $CNT_ISO]));
1026
-            die();
1027
-        } else {
1028
-            $this->_redirect_after_action(
1029
-                $success,
1030
-                esc_html__('State', 'event_espresso'),
1031
-                'added',
1032
-                ['action' => 'country_settings']
1033
-            );
1034
-        }
1035
-    }
1036
-
1037
-
1038
-    /**
1039
-     * @return void
1040
-     * @throws EE_Error
1041
-     * @throws InvalidArgumentException
1042
-     * @throws InvalidDataTypeException
1043
-     * @throws InvalidInterfaceException
1044
-     * @throws ReflectionException
1045
-     */
1046
-    public function delete_state()
1047
-    {
1048
-        $CNT_ISO    = $this->getCountryISO();
1049
-        $STA_ID     = $this->request->getRequestParam('STA_ID');
1050
-        $STA_abbrev = $this->request->getRequestParam('STA_abbrev');
1051
-
1052
-        if (! $STA_ID) {
1053
-            EE_Error::add_error(
1054
-                esc_html__('No State ID or an invalid State ID was received.', 'event_espresso'),
1055
-                __FILE__,
1056
-                __FUNCTION__,
1057
-                __LINE__
1058
-            );
1059
-            return;
1060
-        }
1061
-
1062
-        $success = EEM_State::instance()->delete_by_ID($STA_ID);
1063
-        if ($success !== false) {
1064
-            do_action(
1065
-                'AHEE__General_Settings_Admin_Page__delete_state__state_deleted',
1066
-                $CNT_ISO,
1067
-                $STA_ID,
1068
-                ['STA_abbrev' => $STA_abbrev]
1069
-            );
1070
-            EE_Error::add_success(esc_html__('The State was deleted successfully.', 'event_espresso'));
1071
-        }
1072
-        if (defined('DOING_AJAX')) {
1073
-            $notices                = EE_Error::get_notices(false);
1074
-            $notices['return_data'] = true;
1075
-            echo wp_json_encode($notices);
1076
-            die();
1077
-        } else {
1078
-            $this->_redirect_after_action(
1079
-                $success,
1080
-                esc_html__('State', 'event_espresso'),
1081
-                'deleted',
1082
-                ['action' => 'country_settings']
1083
-            );
1084
-        }
1085
-    }
1086
-
1087
-
1088
-    /**
1089
-     *        _update_country_settings
1090
-     *
1091
-     * @return void
1092
-     * @throws EE_Error
1093
-     * @throws InvalidArgumentException
1094
-     * @throws InvalidDataTypeException
1095
-     * @throws InvalidInterfaceException
1096
-     * @throws ReflectionException
1097
-     */
1098
-    protected function _update_country_settings()
1099
-    {
1100
-        $CNT_ISO = $this->getCountryISO();
1101
-        if (! $CNT_ISO) {
1102
-            EE_Error::add_error(
1103
-                esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
1104
-                __FILE__,
1105
-                __FUNCTION__,
1106
-                __LINE__
1107
-            );
1108
-            return;
1109
-        }
1110
-
1111
-        $country = $this->verifyOrGetCountryFromIso($CNT_ISO);
1112
-
1113
-        $cols_n_values                    = [];
1114
-        $cols_n_values['CNT_ISO3']        = strtoupper(
1115
-            $this->request->getRequestParam('cntry', '', $country->ISO3())
1116
-        );
1117
-        $cols_n_values['CNT_name']        = $this->request->getRequestParam(
1118
-            "cntry[$CNT_ISO][CNT_name]",
1119
-            $country->name()
1120
-        );
1121
-        $cols_n_values['CNT_cur_code']    = strtoupper(
1122
-            $this->request->getRequestParam(
1123
-                "cntry[$CNT_ISO][CNT_cur_code]",
1124
-                $country->currency_code()
1125
-            )
1126
-        );
1127
-        $cols_n_values['CNT_cur_single']  = $this->request->getRequestParam(
1128
-            "cntry[$CNT_ISO][CNT_cur_single]",
1129
-            $country->currency_name_single()
1130
-        );
1131
-        $cols_n_values['CNT_cur_plural']  = $this->request->getRequestParam(
1132
-            "cntry[$CNT_ISO][CNT_cur_plural]",
1133
-            $country->currency_name_plural()
1134
-        );
1135
-        $cols_n_values['CNT_cur_sign']    = $this->request->getRequestParam(
1136
-            "cntry[$CNT_ISO][CNT_cur_sign]",
1137
-            $country->currency_sign()
1138
-        );
1139
-        $cols_n_values['CNT_cur_sign_b4'] = $this->request->getRequestParam(
1140
-            "cntry[$CNT_ISO][CNT_cur_sign_b4]",
1141
-            $country->currency_sign_before(),
1142
-            DataType::BOOL
1143
-        );
1144
-        $cols_n_values['CNT_cur_dec_plc'] = $this->request->getRequestParam(
1145
-            "cntry[$CNT_ISO][CNT_cur_dec_plc]",
1146
-            $country->currency_decimal_places()
1147
-        );
1148
-        $cols_n_values['CNT_cur_dec_mrk'] = $this->request->getRequestParam(
1149
-            "cntry[$CNT_ISO][CNT_cur_dec_mrk]",
1150
-            $country->currency_decimal_mark()
1151
-        );
1152
-        $cols_n_values['CNT_cur_thsnds']  = $this->request->getRequestParam(
1153
-            "cntry[$CNT_ISO][CNT_cur_thsnds]",
1154
-            $country->currency_thousands_separator()
1155
-        );
1156
-        $cols_n_values['CNT_tel_code']    = $this->request->getRequestParam(
1157
-            "cntry[$CNT_ISO][CNT_tel_code]",
1158
-            $country->telephoneCode()
1159
-        );
1160
-        $cols_n_values['CNT_active']      = $this->request->getRequestParam(
1161
-            "cntry[$CNT_ISO][CNT_active]",
1162
-            $country->isActive(),
1163
-            DataType::BOOL
1164
-        );
1165
-
1166
-        // allow filtering of country data
1167
-        $cols_n_values = apply_filters(
1168
-            'FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values',
1169
-            $cols_n_values
1170
-        );
1171
-
1172
-        // where values
1173
-        $where_cols_n_values = [['CNT_ISO' => $CNT_ISO]];
1174
-        // run the update
1175
-        $success = EEM_Country::instance()->update($cols_n_values, $where_cols_n_values);
1176
-
1177
-        // allow filtering of states data
1178
-        $states = apply_filters(
1179
-            'FHEE__General_Settings_Admin_Page___update_country_settings__states',
1180
-            $this->request->getRequestParam('states', [], DataType::STRING, true)
1181
-        );
1182
-
1183
-        if (! empty($states) && $success !== false) {
1184
-            // loop thru state data ( looks like : states[75][STA_name] )
1185
-            foreach ($states as $STA_ID => $state) {
1186
-                $cols_n_values = [
1187
-                    'CNT_ISO'    => $CNT_ISO,
1188
-                    'STA_abbrev' => sanitize_text_field($state['STA_abbrev']),
1189
-                    'STA_name'   => sanitize_text_field($state['STA_name']),
1190
-                    'STA_active' => filter_var($state['STA_active'], FILTER_VALIDATE_BOOLEAN),
1191
-                ];
1192
-                // where values
1193
-                $where_cols_n_values = [['STA_ID' => $STA_ID]];
1194
-                // run the update
1195
-                $success = EEM_State::instance()->update($cols_n_values, $where_cols_n_values);
1196
-                if ($success !== false) {
1197
-                    do_action(
1198
-                        'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved',
1199
-                        $CNT_ISO,
1200
-                        $STA_ID,
1201
-                        $cols_n_values
1202
-                    );
1203
-                }
1204
-            }
1205
-        }
1206
-        // check if country being edited matches org option country, and if so, then  update EE_Config with new settings
1207
-        if (
1208
-            isset(EE_Registry::instance()->CFG->organization->CNT_ISO)
1209
-            && $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO
1210
-        ) {
1211
-            EE_Registry::instance()->CFG->currency = new EE_Currency_Config($CNT_ISO);
1212
-            EE_Registry::instance()->CFG->update_espresso_config();
1213
-        }
1214
-
1215
-        if ($success !== false) {
1216
-            EE_Error::add_success(
1217
-                esc_html__('Country Settings updated successfully.', 'event_espresso')
1218
-            );
1219
-        }
1220
-        $this->_redirect_after_action(
1221
-            $success,
1222
-            '',
1223
-            '',
1224
-            ['action' => 'country_settings', 'country' => $CNT_ISO],
1225
-            true
1226
-        );
1227
-    }
1228
-
1229
-
1230
-    /**
1231
-     * form_form_field_label_wrap
1232
-     *
1233
-     * @param string $label
1234
-     * @return string
1235
-     */
1236
-    public function country_form_field_label_wrap(string $label): string
1237
-    {
1238
-        return '
23
+	/**
24
+	 * @var EE_Core_Config
25
+	 */
26
+	public $core_config;
27
+
28
+
29
+	/**
30
+	 * Initialize basic properties.
31
+	 */
32
+	protected function _init_page_props()
33
+	{
34
+		$this->page_slug        = GEN_SET_PG_SLUG;
35
+		$this->page_label       = GEN_SET_LABEL;
36
+		$this->_admin_base_url  = GEN_SET_ADMIN_URL;
37
+		$this->_admin_base_path = GEN_SET_ADMIN;
38
+	}
39
+
40
+
41
+	/**
42
+	 * Set ajax hooks
43
+	 */
44
+	protected function _ajax_hooks()
45
+	{
46
+		add_action('wp_ajax_espresso_display_country_settings', [$this, 'display_country_settings']);
47
+		add_action('wp_ajax_espresso_display_country_states', [$this, 'display_country_states']);
48
+		add_action('wp_ajax_espresso_delete_state', [$this, 'delete_state'], 10, 3);
49
+		add_action('wp_ajax_espresso_add_new_state', [$this, 'add_new_state']);
50
+	}
51
+
52
+
53
+	/**
54
+	 * More page properties initialization.
55
+	 */
56
+	protected function _define_page_props()
57
+	{
58
+		$this->_admin_page_title = GEN_SET_LABEL;
59
+		$this->_labels           = ['publishbox' => esc_html__('Update Settings', 'event_espresso')];
60
+	}
61
+
62
+
63
+	/**
64
+	 * Set page routes property.
65
+	 */
66
+	protected function _set_page_routes()
67
+	{
68
+		$this->_page_routes = [
69
+			'critical_pages'                => [
70
+				'func'       => '_espresso_page_settings',
71
+				'capability' => 'manage_options',
72
+			],
73
+			'update_espresso_page_settings' => [
74
+				'func'       => '_update_espresso_page_settings',
75
+				'capability' => 'manage_options',
76
+				'noheader'   => true,
77
+			],
78
+			'default'                       => [
79
+				'func'       => '_your_organization_settings',
80
+				'capability' => 'manage_options',
81
+			],
82
+
83
+			'update_your_organization_settings' => [
84
+				'func'       => '_update_your_organization_settings',
85
+				'capability' => 'manage_options',
86
+				'noheader'   => true,
87
+			],
88
+
89
+			'admin_option_settings' => [
90
+				'func'       => '_admin_option_settings',
91
+				'capability' => 'manage_options',
92
+			],
93
+
94
+			'update_admin_option_settings' => [
95
+				'func'       => '_update_admin_option_settings',
96
+				'capability' => 'manage_options',
97
+				'noheader'   => true,
98
+			],
99
+
100
+			'country_settings' => [
101
+				'func'       => '_country_settings',
102
+				'capability' => 'manage_options',
103
+			],
104
+
105
+			'update_country_settings' => [
106
+				'func'       => '_update_country_settings',
107
+				'capability' => 'manage_options',
108
+				'noheader'   => true,
109
+			],
110
+
111
+			'display_country_settings' => [
112
+				'func'       => 'display_country_settings',
113
+				'capability' => 'manage_options',
114
+				'noheader'   => true,
115
+			],
116
+
117
+			'add_new_state' => [
118
+				'func'       => 'add_new_state',
119
+				'capability' => 'manage_options',
120
+				'noheader'   => true,
121
+			],
122
+
123
+			'delete_state'            => [
124
+				'func'       => 'delete_state',
125
+				'capability' => 'manage_options',
126
+				'noheader'   => true,
127
+			],
128
+			'privacy_settings'        => [
129
+				'func'       => 'privacySettings',
130
+				'capability' => 'manage_options',
131
+			],
132
+			'update_privacy_settings' => [
133
+				'func'               => 'updatePrivacySettings',
134
+				'capability'         => 'manage_options',
135
+				'noheader'           => true,
136
+				'headers_sent_route' => 'privacy_settings',
137
+			],
138
+		];
139
+	}
140
+
141
+
142
+	/**
143
+	 * Set page configuration property
144
+	 */
145
+	protected function _set_page_config()
146
+	{
147
+		$this->_page_config = [
148
+			'critical_pages'        => [
149
+				'nav'           => [
150
+					'label' => esc_html__('Critical Pages', 'event_espresso'),
151
+					'order' => 50,
152
+				],
153
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
154
+				'help_tabs'     => [
155
+					'general_settings_critical_pages_help_tab' => [
156
+						'title'    => esc_html__('Critical Pages', 'event_espresso'),
157
+						'filename' => 'general_settings_critical_pages',
158
+					],
159
+				],
160
+				'require_nonce' => false,
161
+			],
162
+			'default'               => [
163
+				'nav'           => [
164
+					'label' => esc_html__('Your Organization', 'event_espresso'),
165
+					'order' => 20,
166
+				],
167
+				'help_tabs'     => [
168
+					'general_settings_your_organization_help_tab' => [
169
+						'title'    => esc_html__('Your Organization', 'event_espresso'),
170
+						'filename' => 'general_settings_your_organization',
171
+					],
172
+				],
173
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
174
+				'require_nonce' => false,
175
+			],
176
+			'admin_option_settings' => [
177
+				'nav'           => [
178
+					'label' => esc_html__('Admin Options', 'event_espresso'),
179
+					'order' => 60,
180
+				],
181
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
182
+				'help_tabs'     => [
183
+					'general_settings_admin_options_help_tab' => [
184
+						'title'    => esc_html__('Admin Options', 'event_espresso'),
185
+						'filename' => 'general_settings_admin_options',
186
+					],
187
+				],
188
+				'require_nonce' => false,
189
+			],
190
+			'country_settings'      => [
191
+				'nav'           => [
192
+					'label' => esc_html__('Countries', 'event_espresso'),
193
+					'order' => 70,
194
+				],
195
+				'help_tabs'     => [
196
+					'general_settings_countries_help_tab' => [
197
+						'title'    => esc_html__('Countries', 'event_espresso'),
198
+						'filename' => 'general_settings_countries',
199
+					],
200
+				],
201
+				'require_nonce' => false,
202
+			],
203
+			'privacy_settings'      => [
204
+				'nav'           => [
205
+					'label' => esc_html__('Privacy', 'event_espresso'),
206
+					'order' => 80,
207
+				],
208
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
209
+				'require_nonce' => false,
210
+			],
211
+		];
212
+	}
213
+
214
+
215
+	protected function _add_screen_options()
216
+	{
217
+	}
218
+
219
+
220
+	protected function _add_feature_pointers()
221
+	{
222
+	}
223
+
224
+
225
+	/**
226
+	 * Enqueue global scripts and styles for all routes in the General Settings Admin Pages.
227
+	 */
228
+	public function load_scripts_styles()
229
+	{
230
+		// styles
231
+		wp_enqueue_style('espresso-ui-theme');
232
+		// scripts
233
+		wp_enqueue_script('ee_admin_js');
234
+	}
235
+
236
+
237
+	/**
238
+	 * Execute logic running on `admin_init`
239
+	 */
240
+	public function admin_init()
241
+	{
242
+		$this->core_config = EE_Registry::instance()->CFG->core;
243
+
244
+		EE_Registry::$i18n_js_strings['invalid_server_response'] = wp_strip_all_tags(
245
+			esc_html__(
246
+				'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.',
247
+				'event_espresso'
248
+			)
249
+		);
250
+		EE_Registry::$i18n_js_strings['error_occurred']          = wp_strip_all_tags(
251
+			esc_html__(
252
+				'An error occurred! Please refresh the page and try again.',
253
+				'event_espresso'
254
+			)
255
+		);
256
+		EE_Registry::$i18n_js_strings['confirm_delete_state']    = wp_strip_all_tags(
257
+			esc_html__(
258
+				'Are you sure you want to delete this State / Province?',
259
+				'event_espresso'
260
+			)
261
+		);
262
+		EE_Registry::$i18n_js_strings['ajax_url']                = admin_url(
263
+			'admin-ajax.php?page=espresso_general_settings',
264
+			is_ssl() ? 'https://' : 'http://'
265
+		);
266
+	}
267
+
268
+
269
+	public function admin_notices()
270
+	{
271
+	}
272
+
273
+
274
+	public function admin_footer_scripts()
275
+	{
276
+	}
277
+
278
+
279
+	/**
280
+	 * Enqueue scripts and styles for the default route.
281
+	 */
282
+	public function load_scripts_styles_default()
283
+	{
284
+		// styles
285
+		wp_enqueue_style('thickbox');
286
+		// scripts
287
+		wp_enqueue_script('media-upload');
288
+		wp_enqueue_script('thickbox');
289
+		wp_register_script(
290
+			'organization_settings',
291
+			GEN_SET_ASSETS_URL . 'your_organization_settings.js',
292
+			['jquery', 'media-upload', 'thickbox'],
293
+			EVENT_ESPRESSO_VERSION,
294
+			true
295
+		);
296
+		wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', [], EVENT_ESPRESSO_VERSION);
297
+		wp_enqueue_script('organization_settings');
298
+		wp_enqueue_style('organization-css');
299
+		$confirm_image_delete = [
300
+			'text' => wp_strip_all_tags(
301
+				esc_html__(
302
+					'Do you really want to delete this image? Please remember to save your settings to complete the removal.',
303
+					'event_espresso'
304
+				)
305
+			),
306
+		];
307
+		wp_localize_script('organization_settings', 'confirm_image_delete', $confirm_image_delete);
308
+	}
309
+
310
+
311
+	/**
312
+	 * Enqueue scripts and styles for the country settings route.
313
+	 */
314
+	public function load_scripts_styles_country_settings()
315
+	{
316
+		// scripts
317
+		wp_register_script(
318
+			'gen_settings_countries',
319
+			GEN_SET_ASSETS_URL . 'gen_settings_countries.js',
320
+			['ee_admin_js'],
321
+			EVENT_ESPRESSO_VERSION,
322
+			true
323
+		);
324
+		wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', [], EVENT_ESPRESSO_VERSION);
325
+		wp_enqueue_script('gen_settings_countries');
326
+		wp_enqueue_style('organization-css');
327
+	}
328
+
329
+
330
+	/*************        Espresso Pages        *************/
331
+	/**
332
+	 * _espresso_page_settings
333
+	 *
334
+	 * @throws EE_Error
335
+	 * @throws DomainException
336
+	 * @throws DomainException
337
+	 * @throws InvalidDataTypeException
338
+	 * @throws InvalidArgumentException
339
+	 */
340
+	protected function _espresso_page_settings()
341
+	{
342
+		// Check to make sure all of the main pages are set up properly,
343
+		// if not create the default pages and display an admin notice
344
+		EEH_Activation::verify_default_pages_exist();
345
+		$this->_transient_garbage_collection();
346
+
347
+		$this->_template_args['values'] = $this->_yes_no_values;
348
+
349
+		$this->_template_args['reg_page_id']  = $this->core_config->reg_page_id ?? null;
350
+		$this->_template_args['reg_page_obj'] = isset($this->core_config->reg_page_id)
351
+			? get_post($this->core_config->reg_page_id)
352
+			: false;
353
+
354
+		$this->_template_args['txn_page_id']  = $this->core_config->txn_page_id ?? null;
355
+		$this->_template_args['txn_page_obj'] = isset($this->core_config->txn_page_id)
356
+			? get_post($this->core_config->txn_page_id)
357
+			: false;
358
+
359
+		$this->_template_args['thank_you_page_id']  = $this->core_config->thank_you_page_id ?? null;
360
+		$this->_template_args['thank_you_page_obj'] = isset($this->core_config->thank_you_page_id)
361
+			? get_post($this->core_config->thank_you_page_id)
362
+			: false;
363
+
364
+		$this->_template_args['cancel_page_id']  = $this->core_config->cancel_page_id ?? null;
365
+		$this->_template_args['cancel_page_obj'] = isset($this->core_config->cancel_page_id)
366
+			? get_post($this->core_config->cancel_page_id)
367
+			: false;
368
+
369
+		$this->_set_add_edit_form_tags('update_espresso_page_settings');
370
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
371
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
372
+			GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php',
373
+			$this->_template_args,
374
+			true
375
+		);
376
+		$this->display_admin_page_with_sidebar();
377
+	}
378
+
379
+
380
+	/**
381
+	 * Handler for updating espresso page settings.
382
+	 *
383
+	 * @throws EE_Error
384
+	 */
385
+	protected function _update_espresso_page_settings()
386
+	{
387
+		// capture incoming request data && set page IDs
388
+		$this->core_config->reg_page_id       = $this->request->getRequestParam(
389
+			'reg_page_id',
390
+			$this->core_config->reg_page_id,
391
+			DataType::INT
392
+		);
393
+		$this->core_config->txn_page_id       = $this->request->getRequestParam(
394
+			'txn_page_id',
395
+			$this->core_config->txn_page_id,
396
+			DataType::INT
397
+		);
398
+		$this->core_config->thank_you_page_id = $this->request->getRequestParam(
399
+			'thank_you_page_id',
400
+			$this->core_config->thank_you_page_id,
401
+			DataType::INT
402
+		);
403
+		$this->core_config->cancel_page_id    = $this->request->getRequestParam(
404
+			'cancel_page_id',
405
+			$this->core_config->cancel_page_id,
406
+			DataType::INT
407
+		);
408
+
409
+		$this->core_config = apply_filters(
410
+			'FHEE__General_Settings_Admin_Page___update_espresso_page_settings__CFG_core',
411
+			$this->core_config,
412
+			$this->request->requestParams()
413
+		);
414
+
415
+		$what = esc_html__('Critical Pages & Shortcodes', 'event_espresso');
416
+		$this->_redirect_after_action(
417
+			$this->_update_espresso_configuration(
418
+				$what,
419
+				$this->core_config,
420
+				__FILE__,
421
+				__FUNCTION__,
422
+				__LINE__
423
+			),
424
+			$what,
425
+			'',
426
+			[
427
+				'action' => 'critical_pages',
428
+			],
429
+			true
430
+		);
431
+	}
432
+
433
+
434
+	/*************        Your Organization        *************/
435
+
436
+
437
+	/**
438
+	 * @throws DomainException
439
+	 * @throws EE_Error
440
+	 * @throws InvalidArgumentException
441
+	 * @throws InvalidDataTypeException
442
+	 * @throws InvalidInterfaceException
443
+	 */
444
+	protected function _your_organization_settings()
445
+	{
446
+		$this->_template_args['admin_page_content'] = '';
447
+		try {
448
+			/** @var OrganizationSettings $organization_settings_form */
449
+			$organization_settings_form = $this->loader->getShared(OrganizationSettings::class);
450
+
451
+			$this->_template_args['admin_page_content'] = EEH_HTML::div(
452
+				$organization_settings_form->display(),
453
+				'',
454
+				'padding'
455
+			);
456
+		} catch (Exception $e) {
457
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
458
+		}
459
+		$this->_set_add_edit_form_tags('update_your_organization_settings');
460
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
461
+		$this->display_admin_page_with_sidebar();
462
+	}
463
+
464
+
465
+	/**
466
+	 * Handler for updating organization settings.
467
+	 *
468
+	 * @throws EE_Error
469
+	 */
470
+	protected function _update_your_organization_settings()
471
+	{
472
+		try {
473
+			/** @var OrganizationSettings $organization_settings_form */
474
+			$organization_settings_form = $this->loader->getShared(OrganizationSettings::class);
475
+
476
+			$success = $organization_settings_form->process($this->request->requestParams());
477
+
478
+			EE_Registry::instance()->CFG = apply_filters(
479
+				'FHEE__General_Settings_Admin_Page___update_your_organization_settings__CFG',
480
+				EE_Registry::instance()->CFG
481
+			);
482
+		} catch (Exception $e) {
483
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
484
+			$success = false;
485
+		}
486
+
487
+		if ($success) {
488
+			$success = $this->_update_espresso_configuration(
489
+				esc_html__('Your Organization Settings', 'event_espresso'),
490
+				EE_Registry::instance()->CFG,
491
+				__FILE__,
492
+				__FUNCTION__,
493
+				__LINE__
494
+			);
495
+		}
496
+
497
+		$this->_redirect_after_action($success, '', '', ['action' => 'default'], true);
498
+	}
499
+
500
+
501
+
502
+	/*************        Admin Options        *************/
503
+
504
+
505
+	/**
506
+	 * _admin_option_settings
507
+	 *
508
+	 * @throws EE_Error
509
+	 * @throws LogicException
510
+	 */
511
+	protected function _admin_option_settings()
512
+	{
513
+		$this->_template_args['admin_page_content'] = '';
514
+		try {
515
+			$admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
516
+			// still need this for the old school form in Extend_General_Settings_Admin_Page
517
+			$this->_template_args['values'] = $this->_yes_no_values;
518
+			// also need to account for the do_action that was in the old template
519
+			$admin_options_settings_form->setTemplateArgs($this->_template_args);
520
+			$this->_template_args['admin_page_content'] = $admin_options_settings_form->display();
521
+		} catch (Exception $e) {
522
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
523
+		}
524
+		$this->_set_add_edit_form_tags('update_admin_option_settings');
525
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
526
+		$this->display_admin_page_with_sidebar();
527
+	}
528
+
529
+
530
+	/**
531
+	 * _update_admin_option_settings
532
+	 *
533
+	 * @throws EE_Error
534
+	 * @throws InvalidDataTypeException
535
+	 * @throws InvalidFormSubmissionException
536
+	 * @throws InvalidArgumentException
537
+	 * @throws LogicException
538
+	 */
539
+	protected function _update_admin_option_settings()
540
+	{
541
+		try {
542
+			$admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance());
543
+			$admin_options_settings_form->process(
544
+				$this->request->getRequestParam(
545
+					$admin_options_settings_form->slug(),
546
+					[],
547
+					DataType::OBJECT // need to change this to ARRAY after min PHP version gets bumped to 7+
548
+				)
549
+			);
550
+			EE_Registry::instance()->CFG->admin = apply_filters(
551
+				'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin',
552
+				EE_Registry::instance()->CFG->admin
553
+			);
554
+		} catch (Exception $e) {
555
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
556
+		}
557
+		$this->_redirect_after_action(
558
+			apply_filters(
559
+				'FHEE__General_Settings_Admin_Page___update_admin_option_settings__success',
560
+				$this->_update_espresso_configuration(
561
+					esc_html__('Admin Options', 'event_espresso'),
562
+					EE_Registry::instance()->CFG->admin,
563
+					__FILE__,
564
+					__FUNCTION__,
565
+					__LINE__
566
+				)
567
+			),
568
+			esc_html__('Admin Options', 'event_espresso'),
569
+			'updated',
570
+			['action' => 'admin_option_settings']
571
+		);
572
+	}
573
+
574
+
575
+	/*************        Countries        *************/
576
+
577
+
578
+	/**
579
+	 * @param string|null $default
580
+	 * @return string
581
+	 */
582
+	protected function getCountryISO(?string $default = null): string
583
+	{
584
+		$default = $default ?? $this->getCountryIsoForSite();
585
+		$CNT_ISO = $this->request->getRequestParam('country', $default);
586
+		$CNT_ISO = $this->request->getRequestParam('CNT_ISO', $CNT_ISO);
587
+		return strtoupper($CNT_ISO);
588
+	}
589
+
590
+
591
+	/**
592
+	 * @return string
593
+	 */
594
+	protected function getCountryIsoForSite(): string
595
+	{
596
+		return ! empty(EE_Registry::instance()->CFG->organization->CNT_ISO)
597
+			? EE_Registry::instance()->CFG->organization->CNT_ISO
598
+			: 'US';
599
+	}
600
+
601
+
602
+	/**
603
+	 * @param string          $CNT_ISO
604
+	 * @param EE_Country|null $country
605
+	 * @return EE_Base_Class|EE_Country
606
+	 * @throws EE_Error
607
+	 * @throws InvalidArgumentException
608
+	 * @throws InvalidDataTypeException
609
+	 * @throws InvalidInterfaceException
610
+	 * @throws ReflectionException
611
+	 */
612
+	protected function verifyOrGetCountryFromIso(string $CNT_ISO, ?EE_Country $country = null)
613
+	{
614
+		/** @var EE_Country $country */
615
+		return $country instanceof EE_Country && $country->ID() === $CNT_ISO
616
+			? $country
617
+			: EEM_Country::instance()->get_one_by_ID($CNT_ISO);
618
+	}
619
+
620
+
621
+	/**
622
+	 * Output Country Settings view.
623
+	 *
624
+	 * @throws DomainException
625
+	 * @throws EE_Error
626
+	 * @throws InvalidArgumentException
627
+	 * @throws InvalidDataTypeException
628
+	 * @throws InvalidInterfaceException
629
+	 * @throws ReflectionException
630
+	 */
631
+	protected function _country_settings()
632
+	{
633
+		$CNT_ISO = $this->getCountryISO();
634
+
635
+		$this->_template_args['values']    = $this->_yes_no_values;
636
+		$this->_template_args['countries'] = new EE_Question_Form_Input(
637
+			EE_Question::new_instance(
638
+				[
639
+					'QST_ID'           => 0,
640
+					'QST_display_text' => esc_html__('Select Country', 'event_espresso'),
641
+					'QST_system'       => 'admin-country',
642
+				]
643
+			),
644
+			EE_Answer::new_instance(
645
+				[
646
+					'ANS_ID'    => 0,
647
+					'ANS_value' => $CNT_ISO,
648
+				]
649
+			),
650
+			[
651
+				'input_id'       => 'country',
652
+				'input_name'     => 'country',
653
+				'input_prefix'   => '',
654
+				'append_qstn_id' => false,
655
+			]
656
+		);
657
+
658
+		$country = $this->verifyOrGetCountryFromIso($CNT_ISO);
659
+		add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'country_form_field_label_wrap'], 10);
660
+		add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'country_form_field_input__wrap'], 10);
661
+		$this->_template_args['country_details_settings'] = $this->display_country_settings(
662
+			$country->ID(),
663
+			$country
664
+		);
665
+		$this->_template_args['country_states_settings']  = $this->display_country_states(
666
+			$country->ID(),
667
+			$country
668
+		);
669
+		$this->_template_args['CNT_name_for_site']        = $country->name();
670
+
671
+		$this->_set_add_edit_form_tags('update_country_settings');
672
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
673
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
674
+			GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php',
675
+			$this->_template_args,
676
+			true
677
+		);
678
+		$this->display_admin_page_with_no_sidebar();
679
+	}
680
+
681
+
682
+	/**
683
+	 * @param string          $CNT_ISO
684
+	 * @param EE_Country|null $country
685
+	 * @return string
686
+	 * @throws DomainException
687
+	 * @throws EE_Error
688
+	 * @throws InvalidArgumentException
689
+	 * @throws InvalidDataTypeException
690
+	 * @throws InvalidInterfaceException
691
+	 * @throws ReflectionException
692
+	 */
693
+	public function display_country_settings(string $CNT_ISO = '', ?EE_Country $country = null): string
694
+	{
695
+		$CNT_ISO          = $this->getCountryISO($CNT_ISO);
696
+		$CNT_ISO_for_site = $this->getCountryIsoForSite();
697
+
698
+		if (! $CNT_ISO) {
699
+			return '';
700
+		}
701
+
702
+		// for ajax
703
+		remove_all_filters('FHEE__EEH_Form_Fields__label_html');
704
+		remove_all_filters('FHEE__EEH_Form_Fields__input_html');
705
+		add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'country_form_field_label_wrap'], 10, 2);
706
+		add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'country_form_field_input__wrap'], 10, 2);
707
+		$country                                  = $this->verifyOrGetCountryFromIso($CNT_ISO, $country);
708
+		$CNT_cur_disabled                         = $CNT_ISO !== $CNT_ISO_for_site;
709
+		$this->_template_args['CNT_cur_disabled'] = $CNT_cur_disabled;
710
+
711
+		$country_input_types            = [
712
+			'CNT_active'      => [
713
+				'type'             => 'RADIO_BTN',
714
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
715
+				'class'            => '',
716
+				'options'          => $this->_yes_no_values,
717
+				'use_desc_4_label' => true,
718
+			],
719
+			'CNT_ISO'         => [
720
+				'type'       => 'TEXT',
721
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
722
+				'class'      => 'small-text',
723
+			],
724
+			'CNT_ISO3'        => [
725
+				'type'       => 'TEXT',
726
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
727
+				'class'      => 'small-text',
728
+			],
729
+			// 'RGN_ID'          => [
730
+			//     'type'       => 'TEXT',
731
+			//     'input_name' => 'cntry[' . $CNT_ISO . ']',
732
+			//     'class'      => 'ee-input-size--small',
733
+			// ],
734
+			'CNT_name'        => [
735
+				'type'       => 'TEXT',
736
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
737
+				'class'      => 'regular-text',
738
+			],
739
+			'CNT_cur_code'    => [
740
+				'type'       => 'TEXT',
741
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
742
+				'class'      => 'small-text',
743
+				'disabled'   => $CNT_cur_disabled,
744
+			],
745
+			'CNT_cur_single'  => [
746
+				'type'       => 'TEXT',
747
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
748
+				'class'      => 'medium-text',
749
+				'disabled'   => $CNT_cur_disabled,
750
+			],
751
+			'CNT_cur_plural'  => [
752
+				'type'       => 'TEXT',
753
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
754
+				'class'      => 'medium-text',
755
+				'disabled'   => $CNT_cur_disabled,
756
+			],
757
+			'CNT_cur_sign'    => [
758
+				'type'         => 'TEXT',
759
+				'input_name'   => 'cntry[' . $CNT_ISO . ']',
760
+				'class'        => 'small-text',
761
+				'htmlentities' => false,
762
+				'disabled'     => $CNT_cur_disabled,
763
+			],
764
+			'CNT_cur_sign_b4' => [
765
+				'type'             => 'RADIO_BTN',
766
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
767
+				'class'            => '',
768
+				'options'          => $this->_yes_no_values,
769
+				'use_desc_4_label' => true,
770
+				'disabled'         => $CNT_cur_disabled,
771
+			],
772
+			'CNT_cur_dec_plc' => [
773
+				'type'       => 'RADIO_BTN',
774
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
775
+				'class'      => '',
776
+				'options'    => [
777
+					['id' => 0, 'text' => ''],
778
+					['id' => 1, 'text' => ''],
779
+					['id' => 2, 'text' => ''],
780
+					['id' => 3, 'text' => ''],
781
+				],
782
+				'disabled'   => $CNT_cur_disabled,
783
+			],
784
+			'CNT_cur_dec_mrk' => [
785
+				'type'             => 'RADIO_BTN',
786
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
787
+				'class'            => '',
788
+				'options'          => [
789
+					[
790
+						'id'   => ',',
791
+						'text' => esc_html__(', (comma)', 'event_espresso'),
792
+					],
793
+					['id' => '.', 'text' => esc_html__('. (decimal)', 'event_espresso')],
794
+				],
795
+				'use_desc_4_label' => true,
796
+				'disabled'         => $CNT_cur_disabled,
797
+			],
798
+			'CNT_cur_thsnds'  => [
799
+				'type'             => 'RADIO_BTN',
800
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
801
+				'class'            => '',
802
+				'options'          => [
803
+					[
804
+						'id'   => ',',
805
+						'text' => esc_html__(', (comma)', 'event_espresso'),
806
+					],
807
+					[
808
+						'id'   => '.',
809
+						'text' => esc_html__('. (decimal)', 'event_espresso'),
810
+					],
811
+					[
812
+						'id'   => ' ',
813
+						'text' => esc_html__('(space)', 'event_espresso'),
814
+					],
815
+				],
816
+				'use_desc_4_label' => true,
817
+				'disabled'         => $CNT_cur_disabled,
818
+			],
819
+			'CNT_tel_code'    => [
820
+				'type'       => 'TEXT',
821
+				'input_name' => 'cntry[' . $CNT_ISO . ']',
822
+				'class'      => 'small-text',
823
+			],
824
+			'CNT_is_EU'       => [
825
+				'type'             => 'RADIO_BTN',
826
+				'input_name'       => 'cntry[' . $CNT_ISO . ']',
827
+				'class'            => '',
828
+				'options'          => $this->_yes_no_values,
829
+				'use_desc_4_label' => true,
830
+			],
831
+		];
832
+		$this->_template_args['inputs'] = EE_Question_Form_Input::generate_question_form_inputs_for_object(
833
+			$country,
834
+			$country_input_types
835
+		);
836
+		$country_details_settings       = EEH_Template::display_template(
837
+			GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php',
838
+			$this->_template_args,
839
+			true
840
+		);
841
+
842
+		if (defined('DOING_AJAX')) {
843
+			$notices = EE_Error::get_notices(false, false, false);
844
+			echo wp_json_encode(
845
+				[
846
+					'return_data' => $country_details_settings,
847
+					'success'     => $notices['success'],
848
+					'errors'      => $notices['errors'],
849
+				]
850
+			);
851
+			die();
852
+		}
853
+		return $country_details_settings;
854
+	}
855
+
856
+
857
+	/**
858
+	 * @param string          $CNT_ISO
859
+	 * @param EE_Country|null $country
860
+	 * @return string
861
+	 * @throws DomainException
862
+	 * @throws EE_Error
863
+	 * @throws InvalidArgumentException
864
+	 * @throws InvalidDataTypeException
865
+	 * @throws InvalidInterfaceException
866
+	 * @throws ReflectionException
867
+	 */
868
+	public function display_country_states(string $CNT_ISO = '', ?EE_Country $country = null): string
869
+	{
870
+		$CNT_ISO = $this->getCountryISO($CNT_ISO);
871
+		if (! $CNT_ISO) {
872
+			return '';
873
+		}
874
+		// for ajax
875
+		remove_all_filters('FHEE__EEH_Form_Fields__label_html');
876
+		remove_all_filters('FHEE__EEH_Form_Fields__input_html');
877
+		add_filter('FHEE__EEH_Form_Fields__label_html', [$this, 'state_form_field_label_wrap'], 10, 2);
878
+		add_filter('FHEE__EEH_Form_Fields__input_html', [$this, 'state_form_field_input__wrap'], 10);
879
+		$states = EEM_State::instance()->get_all_states_for_these_countries([$CNT_ISO => $CNT_ISO]);
880
+		if (empty($states)) {
881
+			/** @var EventEspresso\core\services\address\CountrySubRegionDao $countrySubRegionDao */
882
+			$countrySubRegionDao = $this->loader->getShared(
883
+				'EventEspresso\core\services\address\CountrySubRegionDao'
884
+			);
885
+			if ($countrySubRegionDao instanceof EventEspresso\core\services\address\CountrySubRegionDao) {
886
+				$country = $this->verifyOrGetCountryFromIso($CNT_ISO, $country);
887
+				if ($countrySubRegionDao->saveCountrySubRegions($country)) {
888
+					$states = EEM_State::instance()->get_all_states_for_these_countries([$CNT_ISO => $CNT_ISO]);
889
+				}
890
+			}
891
+		}
892
+		if (is_array($states)) {
893
+			foreach ($states as $STA_ID => $state) {
894
+				if ($state instanceof EE_State) {
895
+					$inputs = EE_Question_Form_Input::generate_question_form_inputs_for_object(
896
+						$state,
897
+						[
898
+							'STA_abbrev' => [
899
+								'type'             => 'TEXT',
900
+								'label'            => esc_html__('Code', 'event_espresso'),
901
+								'input_name'       => 'states[' . $STA_ID . ']',
902
+								'class'            => 'small-text',
903
+								'add_mobile_label' => true,
904
+							],
905
+							'STA_name'   => [
906
+								'type'             => 'TEXT',
907
+								'label'            => esc_html__('Name', 'event_espresso'),
908
+								'input_name'       => 'states[' . $STA_ID . ']',
909
+								'class'            => 'regular-text',
910
+								'add_mobile_label' => true,
911
+							],
912
+							'STA_active' => [
913
+								'type'             => 'RADIO_BTN',
914
+								'label'            => esc_html__(
915
+									'State Appears in Dropdown Select Lists',
916
+									'event_espresso'
917
+								),
918
+								'input_name'       => 'states[' . $STA_ID . ']',
919
+								'options'          => $this->_yes_no_values,
920
+								'use_desc_4_label' => true,
921
+								'add_mobile_label' => true,
922
+							],
923
+						]
924
+					);
925
+
926
+					$delete_state_url = EE_Admin_Page::add_query_args_and_nonce(
927
+						[
928
+							'action'     => 'delete_state',
929
+							'STA_ID'     => $STA_ID,
930
+							'CNT_ISO'    => $CNT_ISO,
931
+							'STA_abbrev' => $state->abbrev(),
932
+						],
933
+						GEN_SET_ADMIN_URL
934
+					);
935
+
936
+					$this->_template_args['states'][ $STA_ID ]['inputs']           = $inputs;
937
+					$this->_template_args['states'][ $STA_ID ]['delete_state_url'] = $delete_state_url;
938
+				}
939
+			}
940
+		} else {
941
+			$this->_template_args['states'] = false;
942
+		}
943
+
944
+		$this->_template_args['add_new_state_url'] = EE_Admin_Page::add_query_args_and_nonce(
945
+			['action' => 'add_new_state'],
946
+			GEN_SET_ADMIN_URL
947
+		);
948
+
949
+		$state_details_settings = EEH_Template::display_template(
950
+			GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php',
951
+			$this->_template_args,
952
+			true
953
+		);
954
+
955
+		if (defined('DOING_AJAX')) {
956
+			$notices = EE_Error::get_notices(false, false, false);
957
+			echo wp_json_encode(
958
+				[
959
+					'return_data' => $state_details_settings,
960
+					'success'     => $notices['success'],
961
+					'errors'      => $notices['errors'],
962
+				]
963
+			);
964
+			die();
965
+		}
966
+		return $state_details_settings;
967
+	}
968
+
969
+
970
+	/**
971
+	 * @return void
972
+	 * @throws EE_Error
973
+	 * @throws InvalidArgumentException
974
+	 * @throws InvalidDataTypeException
975
+	 * @throws InvalidInterfaceException
976
+	 * @throws ReflectionException
977
+	 */
978
+	public function add_new_state()
979
+	{
980
+		$success = true;
981
+		$CNT_ISO = $this->getCountryISO('');
982
+		if (! $CNT_ISO) {
983
+			EE_Error::add_error(
984
+				esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
985
+				__FILE__,
986
+				__FUNCTION__,
987
+				__LINE__
988
+			);
989
+			$success = false;
990
+		}
991
+		$STA_abbrev = $this->request->getRequestParam('STA_abbrev');
992
+		if (! $STA_abbrev) {
993
+			EE_Error::add_error(
994
+				esc_html__('No State ISO code or an invalid State ISO code was received.', 'event_espresso'),
995
+				__FILE__,
996
+				__FUNCTION__,
997
+				__LINE__
998
+			);
999
+			$success = false;
1000
+		}
1001
+		$STA_name = $this->request->getRequestParam('STA_name');
1002
+		if (! $STA_name) {
1003
+			EE_Error::add_error(
1004
+				esc_html__('No State name or an invalid State name was received.', 'event_espresso'),
1005
+				__FILE__,
1006
+				__FUNCTION__,
1007
+				__LINE__
1008
+			);
1009
+			$success = false;
1010
+		}
1011
+
1012
+		if ($success) {
1013
+			$cols_n_values = [
1014
+				'CNT_ISO'    => $CNT_ISO,
1015
+				'STA_abbrev' => $STA_abbrev,
1016
+				'STA_name'   => $STA_name,
1017
+				'STA_active' => true,
1018
+			];
1019
+			$success       = EEM_State::instance()->insert($cols_n_values);
1020
+			EE_Error::add_success(esc_html__('The State was added successfully.', 'event_espresso'));
1021
+		}
1022
+
1023
+		if (defined('DOING_AJAX')) {
1024
+			$notices = EE_Error::get_notices(false, false, false);
1025
+			echo wp_json_encode(array_merge($notices, ['return_data' => $CNT_ISO]));
1026
+			die();
1027
+		} else {
1028
+			$this->_redirect_after_action(
1029
+				$success,
1030
+				esc_html__('State', 'event_espresso'),
1031
+				'added',
1032
+				['action' => 'country_settings']
1033
+			);
1034
+		}
1035
+	}
1036
+
1037
+
1038
+	/**
1039
+	 * @return void
1040
+	 * @throws EE_Error
1041
+	 * @throws InvalidArgumentException
1042
+	 * @throws InvalidDataTypeException
1043
+	 * @throws InvalidInterfaceException
1044
+	 * @throws ReflectionException
1045
+	 */
1046
+	public function delete_state()
1047
+	{
1048
+		$CNT_ISO    = $this->getCountryISO();
1049
+		$STA_ID     = $this->request->getRequestParam('STA_ID');
1050
+		$STA_abbrev = $this->request->getRequestParam('STA_abbrev');
1051
+
1052
+		if (! $STA_ID) {
1053
+			EE_Error::add_error(
1054
+				esc_html__('No State ID or an invalid State ID was received.', 'event_espresso'),
1055
+				__FILE__,
1056
+				__FUNCTION__,
1057
+				__LINE__
1058
+			);
1059
+			return;
1060
+		}
1061
+
1062
+		$success = EEM_State::instance()->delete_by_ID($STA_ID);
1063
+		if ($success !== false) {
1064
+			do_action(
1065
+				'AHEE__General_Settings_Admin_Page__delete_state__state_deleted',
1066
+				$CNT_ISO,
1067
+				$STA_ID,
1068
+				['STA_abbrev' => $STA_abbrev]
1069
+			);
1070
+			EE_Error::add_success(esc_html__('The State was deleted successfully.', 'event_espresso'));
1071
+		}
1072
+		if (defined('DOING_AJAX')) {
1073
+			$notices                = EE_Error::get_notices(false);
1074
+			$notices['return_data'] = true;
1075
+			echo wp_json_encode($notices);
1076
+			die();
1077
+		} else {
1078
+			$this->_redirect_after_action(
1079
+				$success,
1080
+				esc_html__('State', 'event_espresso'),
1081
+				'deleted',
1082
+				['action' => 'country_settings']
1083
+			);
1084
+		}
1085
+	}
1086
+
1087
+
1088
+	/**
1089
+	 *        _update_country_settings
1090
+	 *
1091
+	 * @return void
1092
+	 * @throws EE_Error
1093
+	 * @throws InvalidArgumentException
1094
+	 * @throws InvalidDataTypeException
1095
+	 * @throws InvalidInterfaceException
1096
+	 * @throws ReflectionException
1097
+	 */
1098
+	protected function _update_country_settings()
1099
+	{
1100
+		$CNT_ISO = $this->getCountryISO();
1101
+		if (! $CNT_ISO) {
1102
+			EE_Error::add_error(
1103
+				esc_html__('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'),
1104
+				__FILE__,
1105
+				__FUNCTION__,
1106
+				__LINE__
1107
+			);
1108
+			return;
1109
+		}
1110
+
1111
+		$country = $this->verifyOrGetCountryFromIso($CNT_ISO);
1112
+
1113
+		$cols_n_values                    = [];
1114
+		$cols_n_values['CNT_ISO3']        = strtoupper(
1115
+			$this->request->getRequestParam('cntry', '', $country->ISO3())
1116
+		);
1117
+		$cols_n_values['CNT_name']        = $this->request->getRequestParam(
1118
+			"cntry[$CNT_ISO][CNT_name]",
1119
+			$country->name()
1120
+		);
1121
+		$cols_n_values['CNT_cur_code']    = strtoupper(
1122
+			$this->request->getRequestParam(
1123
+				"cntry[$CNT_ISO][CNT_cur_code]",
1124
+				$country->currency_code()
1125
+			)
1126
+		);
1127
+		$cols_n_values['CNT_cur_single']  = $this->request->getRequestParam(
1128
+			"cntry[$CNT_ISO][CNT_cur_single]",
1129
+			$country->currency_name_single()
1130
+		);
1131
+		$cols_n_values['CNT_cur_plural']  = $this->request->getRequestParam(
1132
+			"cntry[$CNT_ISO][CNT_cur_plural]",
1133
+			$country->currency_name_plural()
1134
+		);
1135
+		$cols_n_values['CNT_cur_sign']    = $this->request->getRequestParam(
1136
+			"cntry[$CNT_ISO][CNT_cur_sign]",
1137
+			$country->currency_sign()
1138
+		);
1139
+		$cols_n_values['CNT_cur_sign_b4'] = $this->request->getRequestParam(
1140
+			"cntry[$CNT_ISO][CNT_cur_sign_b4]",
1141
+			$country->currency_sign_before(),
1142
+			DataType::BOOL
1143
+		);
1144
+		$cols_n_values['CNT_cur_dec_plc'] = $this->request->getRequestParam(
1145
+			"cntry[$CNT_ISO][CNT_cur_dec_plc]",
1146
+			$country->currency_decimal_places()
1147
+		);
1148
+		$cols_n_values['CNT_cur_dec_mrk'] = $this->request->getRequestParam(
1149
+			"cntry[$CNT_ISO][CNT_cur_dec_mrk]",
1150
+			$country->currency_decimal_mark()
1151
+		);
1152
+		$cols_n_values['CNT_cur_thsnds']  = $this->request->getRequestParam(
1153
+			"cntry[$CNT_ISO][CNT_cur_thsnds]",
1154
+			$country->currency_thousands_separator()
1155
+		);
1156
+		$cols_n_values['CNT_tel_code']    = $this->request->getRequestParam(
1157
+			"cntry[$CNT_ISO][CNT_tel_code]",
1158
+			$country->telephoneCode()
1159
+		);
1160
+		$cols_n_values['CNT_active']      = $this->request->getRequestParam(
1161
+			"cntry[$CNT_ISO][CNT_active]",
1162
+			$country->isActive(),
1163
+			DataType::BOOL
1164
+		);
1165
+
1166
+		// allow filtering of country data
1167
+		$cols_n_values = apply_filters(
1168
+			'FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values',
1169
+			$cols_n_values
1170
+		);
1171
+
1172
+		// where values
1173
+		$where_cols_n_values = [['CNT_ISO' => $CNT_ISO]];
1174
+		// run the update
1175
+		$success = EEM_Country::instance()->update($cols_n_values, $where_cols_n_values);
1176
+
1177
+		// allow filtering of states data
1178
+		$states = apply_filters(
1179
+			'FHEE__General_Settings_Admin_Page___update_country_settings__states',
1180
+			$this->request->getRequestParam('states', [], DataType::STRING, true)
1181
+		);
1182
+
1183
+		if (! empty($states) && $success !== false) {
1184
+			// loop thru state data ( looks like : states[75][STA_name] )
1185
+			foreach ($states as $STA_ID => $state) {
1186
+				$cols_n_values = [
1187
+					'CNT_ISO'    => $CNT_ISO,
1188
+					'STA_abbrev' => sanitize_text_field($state['STA_abbrev']),
1189
+					'STA_name'   => sanitize_text_field($state['STA_name']),
1190
+					'STA_active' => filter_var($state['STA_active'], FILTER_VALIDATE_BOOLEAN),
1191
+				];
1192
+				// where values
1193
+				$where_cols_n_values = [['STA_ID' => $STA_ID]];
1194
+				// run the update
1195
+				$success = EEM_State::instance()->update($cols_n_values, $where_cols_n_values);
1196
+				if ($success !== false) {
1197
+					do_action(
1198
+						'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved',
1199
+						$CNT_ISO,
1200
+						$STA_ID,
1201
+						$cols_n_values
1202
+					);
1203
+				}
1204
+			}
1205
+		}
1206
+		// check if country being edited matches org option country, and if so, then  update EE_Config with new settings
1207
+		if (
1208
+			isset(EE_Registry::instance()->CFG->organization->CNT_ISO)
1209
+			&& $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO
1210
+		) {
1211
+			EE_Registry::instance()->CFG->currency = new EE_Currency_Config($CNT_ISO);
1212
+			EE_Registry::instance()->CFG->update_espresso_config();
1213
+		}
1214
+
1215
+		if ($success !== false) {
1216
+			EE_Error::add_success(
1217
+				esc_html__('Country Settings updated successfully.', 'event_espresso')
1218
+			);
1219
+		}
1220
+		$this->_redirect_after_action(
1221
+			$success,
1222
+			'',
1223
+			'',
1224
+			['action' => 'country_settings', 'country' => $CNT_ISO],
1225
+			true
1226
+		);
1227
+	}
1228
+
1229
+
1230
+	/**
1231
+	 * form_form_field_label_wrap
1232
+	 *
1233
+	 * @param string $label
1234
+	 * @return string
1235
+	 */
1236
+	public function country_form_field_label_wrap(string $label): string
1237
+	{
1238
+		return '
1239 1239
 			<tr>
1240 1240
 				<th>
1241 1241
 					' . $label . '
1242 1242
 				</th>';
1243
-    }
1244
-
1245
-
1246
-    /**
1247
-     * form_form_field_input__wrap
1248
-     *
1249
-     * @param string $input
1250
-     * @return string
1251
-     */
1252
-    public function country_form_field_input__wrap(string $input): string
1253
-    {
1254
-        return '
1243
+	}
1244
+
1245
+
1246
+	/**
1247
+	 * form_form_field_input__wrap
1248
+	 *
1249
+	 * @param string $input
1250
+	 * @return string
1251
+	 */
1252
+	public function country_form_field_input__wrap(string $input): string
1253
+	{
1254
+		return '
1255 1255
 				<td class="general-settings-country-input-td">
1256 1256
 					' . $input . '
1257 1257
 				</td>
1258 1258
 			</tr>';
1259
-    }
1260
-
1261
-
1262
-    /**
1263
-     * form_form_field_label_wrap
1264
-     *
1265
-     * @param string $label
1266
-     * @param string $required_text
1267
-     * @return string
1268
-     */
1269
-    public function state_form_field_label_wrap(string $label, string $required_text): string
1270
-    {
1271
-        return $required_text;
1272
-    }
1273
-
1274
-
1275
-    /**
1276
-     * form_form_field_input__wrap
1277
-     *
1278
-     * @param string $input
1279
-     * @return string
1280
-     */
1281
-    public function state_form_field_input__wrap(string $input): string
1282
-    {
1283
-        return '
1259
+	}
1260
+
1261
+
1262
+	/**
1263
+	 * form_form_field_label_wrap
1264
+	 *
1265
+	 * @param string $label
1266
+	 * @param string $required_text
1267
+	 * @return string
1268
+	 */
1269
+	public function state_form_field_label_wrap(string $label, string $required_text): string
1270
+	{
1271
+		return $required_text;
1272
+	}
1273
+
1274
+
1275
+	/**
1276
+	 * form_form_field_input__wrap
1277
+	 *
1278
+	 * @param string $input
1279
+	 * @return string
1280
+	 */
1281
+	public function state_form_field_input__wrap(string $input): string
1282
+	{
1283
+		return '
1284 1284
 				<td class="general-settings-country-state-input-td">
1285 1285
 					' . $input . '
1286 1286
 				</td>';
1287
-    }
1288
-
1289
-
1290
-    /***********/
1291
-
1292
-
1293
-    /**
1294
-     * displays edit and view links for critical EE pages
1295
-     *
1296
-     * @param int $ee_page_id
1297
-     * @return string
1298
-     */
1299
-    public static function edit_view_links(int $ee_page_id): string
1300
-    {
1301
-        $edit_url = add_query_arg(
1302
-            ['post' => $ee_page_id, 'action' => 'edit'],
1303
-            admin_url('post.php')
1304
-        );
1305
-        $links    = '<a href="' . esc_url_raw($edit_url) . '" >' . esc_html__('Edit', 'event_espresso') . '</a>';
1306
-        $links    .= ' &nbsp;|&nbsp; ';
1307
-        $links    .= '<a href="' . get_permalink($ee_page_id) . '" >' . esc_html__('View', 'event_espresso') . '</a>';
1308
-
1309
-        return $links;
1310
-    }
1311
-
1312
-
1313
-    /**
1314
-     * displays page and shortcode status for critical EE pages
1315
-     *
1316
-     * @param WP_Post $ee_page
1317
-     * @param string  $shortcode
1318
-     * @return string
1319
-     */
1320
-    public static function page_and_shortcode_status(WP_Post $ee_page, string $shortcode): string
1321
-    {
1322
-        // page status
1323
-        if (isset($ee_page->post_status) && $ee_page->post_status == 'publish') {
1324
-            $pg_colour = 'green';
1325
-            $pg_status = sprintf(esc_html__('Page%sStatus%sOK', 'event_espresso'), '&nbsp;', '&nbsp;');
1326
-        } else {
1327
-            $pg_colour = 'red';
1328
-            $pg_status = sprintf(esc_html__('Page%sVisibility%sProblem', 'event_espresso'), '&nbsp;', '&nbsp;');
1329
-        }
1330
-
1331
-        // shortcode status
1332
-        if (isset($ee_page->post_content) && strpos($ee_page->post_content, $shortcode) !== false) {
1333
-            $sc_colour = 'green';
1334
-            $sc_status = sprintf(esc_html__('Shortcode%sOK', 'event_espresso'), '&nbsp;');
1335
-        } else {
1336
-            $sc_colour = 'red';
1337
-            $sc_status = sprintf(esc_html__('Shortcode%sProblem', 'event_espresso'), '&nbsp;');
1338
-        }
1339
-
1340
-        return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>'
1341
-               . $pg_status
1342
-               . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>';
1343
-    }
1344
-
1345
-
1346
-    /**
1347
-     * generates a dropdown of all parent pages - copied from WP core
1348
-     *
1349
-     * @param int  $default
1350
-     * @param int  $parent
1351
-     * @param int  $level
1352
-     * @param bool $echo
1353
-     * @return string;
1354
-     */
1355
-    public static function page_settings_dropdown(
1356
-        int $default = 0,
1357
-        int $parent = 0,
1358
-        int $level = 0,
1359
-        bool $echo = true
1360
-    ): string {
1361
-        global $wpdb;
1362
-        $items  = $wpdb->get_results(
1363
-            $wpdb->prepare(
1364
-                "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",
1365
-                $parent
1366
-            )
1367
-        );
1368
-        $output = '';
1369
-
1370
-        if ($items) {
1371
-            $level = absint($level);
1372
-            foreach ($items as $item) {
1373
-                $ID         = absint($item->ID);
1374
-                $post_title = wp_strip_all_tags($item->post_title);
1375
-                $pad        = str_repeat('&nbsp;', $level * 3);
1376
-                $option     = "\n\t";
1377
-                $option     .= '<option class="level-' . $level . '" ';
1378
-                $option     .= 'value="' . $ID . '" ';
1379
-                $option     .= $ID === absint($default) ? ' selected' : '';
1380
-                $option     .= '>';
1381
-                $option     .= "$pad {$post_title}";
1382
-                $option     .= '</option>';
1383
-                $output     .= $option;
1384
-                ob_start();
1385
-                parent_dropdown($default, $item->ID, $level + 1);
1386
-                $output .= ob_get_clean();
1387
-            }
1388
-        }
1389
-        if ($echo) {
1390
-            echo wp_kses($output, AllowedTags::getAllowedTags());
1391
-            return '';
1392
-        }
1393
-        return $output;
1394
-    }
1395
-
1396
-
1397
-    /**
1398
-     * Loads the scripts for the privacy settings form
1399
-     */
1400
-    public function load_scripts_styles_privacy_settings()
1401
-    {
1402
-        $form_handler = $this->loader->getShared(
1403
-            'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'
1404
-        );
1405
-        $form_handler->enqueueStylesAndScripts();
1406
-    }
1407
-
1408
-
1409
-    /**
1410
-     * display the privacy settings form
1411
-     *
1412
-     * @throws EE_Error
1413
-     */
1414
-    public function privacySettings()
1415
-    {
1416
-        $this->_set_add_edit_form_tags('update_privacy_settings');
1417
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
1418
-        $form_handler                               = $this->loader->getShared(
1419
-            'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'
1420
-        );
1421
-        $this->_template_args['admin_page_content'] = EEH_HTML::div(
1422
-            $form_handler->display(),
1423
-            '',
1424
-            'padding'
1425
-        );
1426
-        $this->display_admin_page_with_sidebar();
1427
-    }
1428
-
1429
-
1430
-    /**
1431
-     * Update the privacy settings from form data
1432
-     *
1433
-     * @throws EE_Error
1434
-     */
1435
-    public function updatePrivacySettings()
1436
-    {
1437
-        $form_handler = $this->loader->getShared(
1438
-            'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'
1439
-        );
1440
-        $success      = $form_handler->process($this->get_request_data());
1441
-        $this->_redirect_after_action(
1442
-            $success,
1443
-            esc_html__('Registration Form Options', 'event_espresso'),
1444
-            'updated',
1445
-            ['action' => 'privacy_settings']
1446
-        );
1447
-    }
1287
+	}
1288
+
1289
+
1290
+	/***********/
1291
+
1292
+
1293
+	/**
1294
+	 * displays edit and view links for critical EE pages
1295
+	 *
1296
+	 * @param int $ee_page_id
1297
+	 * @return string
1298
+	 */
1299
+	public static function edit_view_links(int $ee_page_id): string
1300
+	{
1301
+		$edit_url = add_query_arg(
1302
+			['post' => $ee_page_id, 'action' => 'edit'],
1303
+			admin_url('post.php')
1304
+		);
1305
+		$links    = '<a href="' . esc_url_raw($edit_url) . '" >' . esc_html__('Edit', 'event_espresso') . '</a>';
1306
+		$links    .= ' &nbsp;|&nbsp; ';
1307
+		$links    .= '<a href="' . get_permalink($ee_page_id) . '" >' . esc_html__('View', 'event_espresso') . '</a>';
1308
+
1309
+		return $links;
1310
+	}
1311
+
1312
+
1313
+	/**
1314
+	 * displays page and shortcode status for critical EE pages
1315
+	 *
1316
+	 * @param WP_Post $ee_page
1317
+	 * @param string  $shortcode
1318
+	 * @return string
1319
+	 */
1320
+	public static function page_and_shortcode_status(WP_Post $ee_page, string $shortcode): string
1321
+	{
1322
+		// page status
1323
+		if (isset($ee_page->post_status) && $ee_page->post_status == 'publish') {
1324
+			$pg_colour = 'green';
1325
+			$pg_status = sprintf(esc_html__('Page%sStatus%sOK', 'event_espresso'), '&nbsp;', '&nbsp;');
1326
+		} else {
1327
+			$pg_colour = 'red';
1328
+			$pg_status = sprintf(esc_html__('Page%sVisibility%sProblem', 'event_espresso'), '&nbsp;', '&nbsp;');
1329
+		}
1330
+
1331
+		// shortcode status
1332
+		if (isset($ee_page->post_content) && strpos($ee_page->post_content, $shortcode) !== false) {
1333
+			$sc_colour = 'green';
1334
+			$sc_status = sprintf(esc_html__('Shortcode%sOK', 'event_espresso'), '&nbsp;');
1335
+		} else {
1336
+			$sc_colour = 'red';
1337
+			$sc_status = sprintf(esc_html__('Shortcode%sProblem', 'event_espresso'), '&nbsp;');
1338
+		}
1339
+
1340
+		return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>'
1341
+			   . $pg_status
1342
+			   . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>';
1343
+	}
1344
+
1345
+
1346
+	/**
1347
+	 * generates a dropdown of all parent pages - copied from WP core
1348
+	 *
1349
+	 * @param int  $default
1350
+	 * @param int  $parent
1351
+	 * @param int  $level
1352
+	 * @param bool $echo
1353
+	 * @return string;
1354
+	 */
1355
+	public static function page_settings_dropdown(
1356
+		int $default = 0,
1357
+		int $parent = 0,
1358
+		int $level = 0,
1359
+		bool $echo = true
1360
+	): string {
1361
+		global $wpdb;
1362
+		$items  = $wpdb->get_results(
1363
+			$wpdb->prepare(
1364
+				"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",
1365
+				$parent
1366
+			)
1367
+		);
1368
+		$output = '';
1369
+
1370
+		if ($items) {
1371
+			$level = absint($level);
1372
+			foreach ($items as $item) {
1373
+				$ID         = absint($item->ID);
1374
+				$post_title = wp_strip_all_tags($item->post_title);
1375
+				$pad        = str_repeat('&nbsp;', $level * 3);
1376
+				$option     = "\n\t";
1377
+				$option     .= '<option class="level-' . $level . '" ';
1378
+				$option     .= 'value="' . $ID . '" ';
1379
+				$option     .= $ID === absint($default) ? ' selected' : '';
1380
+				$option     .= '>';
1381
+				$option     .= "$pad {$post_title}";
1382
+				$option     .= '</option>';
1383
+				$output     .= $option;
1384
+				ob_start();
1385
+				parent_dropdown($default, $item->ID, $level + 1);
1386
+				$output .= ob_get_clean();
1387
+			}
1388
+		}
1389
+		if ($echo) {
1390
+			echo wp_kses($output, AllowedTags::getAllowedTags());
1391
+			return '';
1392
+		}
1393
+		return $output;
1394
+	}
1395
+
1396
+
1397
+	/**
1398
+	 * Loads the scripts for the privacy settings form
1399
+	 */
1400
+	public function load_scripts_styles_privacy_settings()
1401
+	{
1402
+		$form_handler = $this->loader->getShared(
1403
+			'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'
1404
+		);
1405
+		$form_handler->enqueueStylesAndScripts();
1406
+	}
1407
+
1408
+
1409
+	/**
1410
+	 * display the privacy settings form
1411
+	 *
1412
+	 * @throws EE_Error
1413
+	 */
1414
+	public function privacySettings()
1415
+	{
1416
+		$this->_set_add_edit_form_tags('update_privacy_settings');
1417
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
1418
+		$form_handler                               = $this->loader->getShared(
1419
+			'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'
1420
+		);
1421
+		$this->_template_args['admin_page_content'] = EEH_HTML::div(
1422
+			$form_handler->display(),
1423
+			'',
1424
+			'padding'
1425
+		);
1426
+		$this->display_admin_page_with_sidebar();
1427
+	}
1428
+
1429
+
1430
+	/**
1431
+	 * Update the privacy settings from form data
1432
+	 *
1433
+	 * @throws EE_Error
1434
+	 */
1435
+	public function updatePrivacySettings()
1436
+	{
1437
+		$form_handler = $this->loader->getShared(
1438
+			'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'
1439
+		);
1440
+		$success      = $form_handler->process($this->get_request_data());
1441
+		$this->_redirect_after_action(
1442
+			$success,
1443
+			esc_html__('Registration Form Options', 'event_espresso'),
1444
+			'updated',
1445
+			['action' => 'privacy_settings']
1446
+		);
1447
+	}
1448 1448
 }
Please login to merge, or discard this patch.