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