Completed
Branch add-new-state-button (28021a)
by
unknown
09:54 queued 07:31
created
modules/add_new_state/EED_Add_New_State.module.php 2 patches
Indentation   +808 added lines, -808 removed lines patch added patch discarded remove patch
@@ -17,812 +17,812 @@
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * @return EED_Add_New_State|EED_Module
22
-     * @throws EE_Error
23
-     * @throws ReflectionException
24
-     */
25
-    public static function instance()
26
-    {
27
-        return parent::get_instance(__CLASS__);
28
-    }
29
-
30
-
31
-    /**
32
-     * set_hooks - for hooking into EE Core, other modules, etc
33
-     *
34
-     * @return void
35
-     */
36
-    public static function set_hooks()
37
-    {
38
-        add_action('wp_loaded', ['EED_Add_New_State', 'set_definitions'], 2);
39
-        add_action('wp_enqueue_scripts', ['EED_Add_New_State', 'translate_js_strings'], 0);
40
-        add_action('wp_enqueue_scripts', ['EED_Add_New_State', 'wp_enqueue_scripts'], 10);
41
-        add_filter(
42
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
43
-            ['EED_Add_New_State', 'display_add_new_state_micro_form'],
44
-            1,
45
-            1
46
-        );
47
-        add_filter(
48
-            'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
49
-            ['EED_Add_New_State', 'display_add_new_state_micro_form'],
50
-            1,
51
-            1
52
-        );
53
-        add_filter(
54
-            'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
55
-            ['EED_Add_New_State', 'unset_new_state_request_params'],
56
-            10,
57
-            1
58
-        );
59
-        add_filter(
60
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
61
-            ['EED_Add_New_State', 'inject_new_reg_state_into_options'],
62
-            10,
63
-            5
64
-        );
65
-        add_filter(
66
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
67
-            ['EED_Add_New_State', 'inject_new_reg_country_into_options'],
68
-            10,
69
-            5
70
-        );
71
-        add_filter(
72
-            'FHEE__EE_State_Select_Input____construct__state_options',
73
-            ['EED_Add_New_State', 'state_options'],
74
-            10,
75
-            1
76
-        );
77
-        add_filter(
78
-            'FHEE__EE_Country_Select_Input____construct__country_options',
79
-            ['EED_Add_New_State', 'country_options'],
80
-            10,
81
-            1
82
-        );
83
-    }
84
-
85
-
86
-    /**
87
-     * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
88
-     *
89
-     * @return void
90
-     */
91
-    public static function set_hooks_admin()
92
-    {
93
-        add_action('wp_loaded', ['EED_Add_New_State', 'set_definitions'], 2);
94
-        add_filter(
95
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
96
-            ['EED_Add_New_State', 'display_add_new_state_micro_form'],
97
-            1,
98
-            1
99
-        );
100
-        add_filter(
101
-            'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
102
-            ['EED_Add_New_State', 'display_add_new_state_micro_form'],
103
-            1,
104
-            1
105
-        );
106
-        add_action('wp_ajax_espresso_add_new_state', ['EED_Add_New_State', 'add_new_state']);
107
-        add_action('wp_ajax_nopriv_espresso_add_new_state', ['EED_Add_New_State', 'add_new_state']);
108
-        add_filter(
109
-            'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
110
-            ['EED_Add_New_State', 'unset_new_state_request_params'],
111
-            10,
112
-            1
113
-        );
114
-        add_action(
115
-            'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved',
116
-            ['EED_Add_New_State', 'update_country_settings'],
117
-            10,
118
-            3
119
-        );
120
-        add_action(
121
-            'AHEE__General_Settings_Admin_Page__delete_state__state_deleted',
122
-            ['EED_Add_New_State', 'update_country_settings'],
123
-            10,
124
-            3
125
-        );
126
-        add_filter(
127
-            'FHEE__EE_State_Select_Input____construct__state_options',
128
-            ['EED_Add_New_State', 'state_options'],
129
-            10,
130
-            1
131
-        );
132
-        add_filter(
133
-            'FHEE__EE_Country_Select_Input____construct__country_options',
134
-            ['EED_Add_New_State', 'country_options'],
135
-            10,
136
-            1
137
-        );
138
-        add_filter(
139
-            'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data',
140
-            ['EED_Add_New_State', 'filter_checkout_request_params'],
141
-            10,
142
-            1
143
-        );
144
-        add_filter(
145
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
146
-            ['EED_Add_New_State', 'inject_new_reg_state_into_options'],
147
-            10,
148
-            5
149
-        );
150
-        add_filter(
151
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
152
-            ['EED_Add_New_State', 'inject_new_reg_country_into_options'],
153
-            10,
154
-            5
155
-        );
156
-    }
157
-
158
-
159
-    /**
160
-     * @return void
161
-     */
162
-    public static function set_definitions()
163
-    {
164
-        define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
165
-        define(
166
-            'ANS_TEMPLATES_PATH',
167
-            str_replace(
168
-                '\\',
169
-                '/',
170
-                plugin_dir_path(__FILE__)
171
-            ) . 'templates/'
172
-        );
173
-    }
174
-
175
-
176
-    /**
177
-     * @param WP $WP
178
-     * @return void
179
-     */
180
-    public function run($WP)
181
-    {
182
-    }
183
-
184
-
185
-    /**
186
-     * @return void
187
-     */
188
-    public static function translate_js_strings()
189
-    {
190
-        EE_Registry::$i18n_js_strings['ans_no_country']        = esc_html__(
191
-            'In order to proceed, you need to select the Country that your State/Province belongs to.',
192
-            'event_espresso'
193
-        );
194
-        EE_Registry::$i18n_js_strings['ans_no_name']           = esc_html__(
195
-            'In order to proceed, you need to enter the name of your State/Province.',
196
-            'event_espresso'
197
-        );
198
-        EE_Registry::$i18n_js_strings['ans_no_abbreviation']   = esc_html__(
199
-            'In order to proceed, you need to enter an abbreviation for the name of your State/Province.',
200
-            'event_espresso'
201
-        );
202
-        EE_Registry::$i18n_js_strings['ans_save_success']      = esc_html__(
203
-            'The new state was successfully saved to the database.',
204
-            'event_espresso'
205
-        );
206
-        EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__(
207
-            'An unknown error has occurred on the server while saving the new state to the database.',
208
-            'event_espresso'
209
-        );
210
-    }
211
-
212
-
213
-    /**
214
-     * @return void
215
-     */
216
-    public static function wp_enqueue_scripts()
217
-    {
218
-        if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) {
219
-            wp_register_script(
220
-                'add_new_state',
221
-                ANS_ASSETS_URL . 'add_new_state.js',
222
-                ['espresso_core', 'single_page_checkout'],
223
-                EVENT_ESPRESSO_VERSION,
224
-                true
225
-            );
226
-            wp_enqueue_script('add_new_state');
227
-        }
228
-    }
229
-
230
-
231
-    /**
232
-     * display_add_new_state_micro_form
233
-     *
234
-     * @param EE_Form_Section_Proper $question_group_reg_form
235
-     * @return EE_Form_Section_Proper
236
-     * @throws EE_Error
237
-     * @throws ReflectionException
238
-     */
239
-    public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form)
240
-    {
241
-        $request = self::getRequest();
242
-        // only add the 'new_state_micro_form' when displaying reg forms,
243
-        // not during processing since we process the 'new_state_micro_form' in it's own AJAX request
244
-        $action = $request->getRequestParam('action');
245
-        // is the "state" question in this form section?
246
-        $input = $question_group_reg_form->get_subsection('state');
247
-        if ($action === 'process_reg_step' || $action === 'update_reg_step') {
248
-            // ok then all we need to do is make sure the input's HTML name is consistent
249
-            // by forcing it to set it now, like it did while getting the form for display
250
-            if ($input instanceof EE_State_Select_Input) {
251
-                $input->html_name();
252
-            }
253
-            return $question_group_reg_form;
254
-        }
255
-        // we're only doing this for state select inputs
256
-        if (
257
-            $input instanceof EE_State_Select_Input
258
-            && ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy
259
-        ) {
260
-            // grab any set values from the request
261
-            $country_name        = str_replace('state', 'nsmf_new_state_country', $input->html_name());
262
-            $state_name          = str_replace('state', 'nsmf_new_state_name', $input->html_name());
263
-            $abbrv_name          = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name());
264
-            $new_state_submit_id = str_replace('state', 'new_state', $input->html_id());
265
-            $country_options     = [];
266
-            $countries           = EEM_Country::instance()->get_all_countries();
267
-            if (! empty($countries)) {
268
-                foreach ($countries as $country) {
269
-                    if ($country instanceof EE_Country) {
270
-                        $country_options[ $country->ID() ] = $country->name();
271
-                    }
272
-                }
273
-            }
274
-            $new_state_micro_form = new EE_Form_Section_Proper(
275
-                [
276
-                    'name'            => 'new_state_micro_form',
277
-                    'html_id'         => 'new_state_micro_form',
278
-                    'layout_strategy' => new EE_Div_Per_Section_Layout(),
279
-                    'subsections'     => [
280
-                        // add hidden input to indicate that a new state is being added
281
-                        'add_new_state'               => new EE_Hidden_Input(
282
-                            [
283
-                                'html_name' => str_replace(
284
-                                    'state',
285
-                                    'nsmf_add_new_state',
286
-                                    $input->html_name()
287
-                                ),
288
-                                'html_id'   => str_replace(
289
-                                    'state',
290
-                                    'nsmf_add_new_state',
291
-                                    $input->html_id()
292
-                                ),
293
-                                'default'   => 0,
294
-                            ]
295
-                        ),
296
-                        // add link for displaying hidden container
297
-                        'click_here_link'             => new EE_Form_Section_HTML(
298
-                            apply_filters(
299
-                                'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link',
300
-                                EEH_HTML::link(
301
-                                    '',
302
-                                    esc_html__('click here to add a new state/province', 'event_espresso'),
303
-                                    '',
304
-                                    'display-' . $input->html_id(),
305
-                                    'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js',
306
-                                    '',
307
-                                    'data-target="' . $input->html_id() . '"'
308
-                                )
309
-                            )
310
-                        ),
311
-                        // add initial html for hidden container
312
-                        'add_new_state_micro_form'    => new EE_Form_Section_HTML(
313
-                            apply_filters(
314
-                                'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form',
315
-                                EEH_HTML::div(
316
-                                    '',
317
-                                    $input->html_id() . '-dv',
318
-                                    'ee-form-add-new-state-dv',
319
-                                    'display: none;'
320
-                                ) .
321
-                                EEH_HTML::h6(
322
-                                    esc_html__(
323
-                                        'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:',
324
-                                        'event_espresso'
325
-                                    )
326
-                                ) .
327
-                                EEH_HTML::ul() .
328
-                                EEH_HTML::li(
329
-                                    esc_html__(
330
-                                        'first select the Country that your State/Province belongs to',
331
-                                        'event_espresso'
332
-                                    )
333
-                                ) .
334
-                                EEH_HTML::li(
335
-                                    esc_html__('enter the name of your State/Province', 'event_espresso')
336
-                                ) .
337
-                                EEH_HTML::li(
338
-                                    esc_html__(
339
-                                        'enter a two to six letter abbreviation for the name of your State/Province',
340
-                                        'event_espresso'
341
-                                    )
342
-                                ) .
343
-                                EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) .
344
-                                EEH_HTML::ulx()
345
-                            )
346
-                        ),
347
-                        // NEW STATE COUNTRY
348
-                        'new_state_country'           => new EE_Country_Select_Input(
349
-                            $country_options,
350
-                            [
351
-                                'html_name'       => $country_name,
352
-                                'html_id'         => str_replace(
353
-                                    'state',
354
-                                    'nsmf_new_state_country',
355
-                                    $input->html_id()
356
-                                ),
357
-                                'html_class'      => $input->html_class() . ' new-state-country',
358
-                                'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'),
359
-                                'default'         => $request->getRequestParam($country_name),
360
-                                'required'        => false,
361
-                            ]
362
-                        ),
363
-                        // NEW STATE NAME
364
-                        'new_state_name'              => new EE_Text_Input(
365
-                            [
366
-                                'html_name'       => $state_name,
367
-                                'html_id'         => str_replace(
368
-                                    'state',
369
-                                    'nsmf_new_state_name',
370
-                                    $input->html_id()
371
-                                ),
372
-                                'html_class'      => $input->html_class() . ' new-state-state',
373
-                                'html_label_text' => esc_html__(
374
-                                    'New State/Province Name',
375
-                                    'event_espresso'
376
-                                ),
377
-                                'default'         => $request->getRequestParam($state_name),
378
-                                'required'        => false,
379
-                            ]
380
-                        ),
381
-                        // NEW STATE NAME
382
-                        'new_state_abbrv'             => new EE_Text_Input(
383
-                            [
384
-                                'html_name'             => $abbrv_name,
385
-                                'html_id'               => str_replace(
386
-                                    'state',
387
-                                    'nsmf_new_state_abbrv',
388
-                                    $input->html_id()
389
-                                ),
390
-                                'html_class'            => $input->html_class() . ' new-state-abbrv',
391
-                                'html_label_text'       => esc_html__(
392
-                                    'New State/Province Abbreviation',
393
-                                    'event_espresso'
394
-                                ) . ' *',
395
-                                'other_html_attributes' => 'size="24"',
396
-                                'default'               => $request->getRequestParam($abbrv_name),
397
-                                'required'              => false,
398
-                            ]
399
-                        ),
400
-                        // "submit" button
401
-                        'add_new_state_submit_button' => new EE_Form_Section_HTML(
402
-                            apply_filters(
403
-                                'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button',
404
-                                EEH_HTML::div(
405
-                                    EEH_HTML::button(
406
-                                        esc_html__('ADD', 'event_espresso'),
407
-                                        'ee-form-add-new-state-submit button button-secondary',
408
-                                        '',
409
-                                        'submit-' . $new_state_submit_id,
410
-                                        '',
411
-                                        'data-target="' . $new_state_submit_id . '"'
412
-                                        . ' data-value-field-name="' . $input->valueFieldName() . '"'
413
-                                    ),
414
-                                    '',
415
-                                    'ee-form-add-new-state-submit-dv'
416
-                                )
417
-                            )
418
-                        ),
419
-                        // extra info
420
-                        'add_new_state_extra'         => new EE_Form_Section_HTML(
421
-                            apply_filters(
422
-                                'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra',
423
-                                EEH_HTML::br()
424
-                                .
425
-                                EEH_HTML::div('', '', 'small-text')
426
-                                .
427
-                                EEH_HTML::strong(
428
-                                    '* ' .
429
-                                    esc_html__(
430
-                                        'Don\'t know your State/Province Abbreviation?',
431
-                                        'event_espresso'
432
-                                    )
433
-                                )
434
-                                .
435
-                                EEH_HTML::br()
436
-                                .
437
-                                sprintf(
438
-                                    esc_html__(
439
-                                        'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).',
440
-                                        'event_espresso'
441
-                                    ),
442
-                                    EEH_HTML::link(
443
-                                        'https://en.wikipedia.org/wiki/ISO_3166-2',
444
-                                        'https://en.wikipedia.org/wiki/ISO_3166-2',
445
-                                        '',
446
-                                        '',
447
-                                        'ee-form-add-new-state-wiki-lnk',
448
-                                        '',
449
-                                        'target="_blank"'
450
-                                    )
451
-                                )
452
-                                .
453
-                                EEH_HTML::divx()
454
-                                .
455
-                                EEH_HTML::br()
456
-                                .
457
-                                EEH_HTML::link(
458
-                                    '',
459
-                                    esc_html__('cancel new State/Province', 'event_espresso'),
460
-                                    '',
461
-                                    'hide-' . $input->html_id(),
462
-                                    'ee-form-cancel-new-state-lnk smaller-text',
463
-                                    '',
464
-                                    'data-target="' . $input->html_id() . '"'
465
-                                )
466
-                                .
467
-                                EEH_HTML::divx()
468
-                                .
469
-                                EEH_HTML::br()
470
-                            )
471
-                        ),
472
-                    ],
473
-                ]
474
-            );
475
-            $question_group_reg_form->add_subsections(
476
-                ['new_state_micro_form' => $new_state_micro_form],
477
-                'state',
478
-                false
479
-            );
480
-        }
481
-        return $question_group_reg_form;
482
-    }
483
-
484
-
485
-    /**
486
-     * set_new_state_input_width
487
-     *
488
-     * @return int|string
489
-     * @throws EE_Error
490
-     * @throws InvalidArgumentException
491
-     * @throws InvalidDataTypeException
492
-     * @throws InvalidInterfaceException
493
-     * @throws ReflectionException
494
-     */
495
-    public static function add_new_state()
496
-    {
497
-        $request = self::getRequest();
498
-        if ($request->getRequestParam('nsmf_add_new_state', 0, 'int') === 1) {
499
-            EE_Registry::instance()->load_model('State');
500
-            // grab country ISO code, new state name, and new state abbreviation
501
-            $state_country = $request->getRequestParam('nsmf_new_state_country');
502
-            $state_name    = $request->getRequestParam('nsmf_new_state_name');
503
-            $state_abbr    = $request->getRequestParam('nsmf_new_state_abbrv');
504
-            if ($state_country && $state_name && $state_abbr) {
505
-                $new_state = EED_Add_New_State::save_new_state_to_db(
506
-                    [
507
-                        'CNT_ISO'    => strtoupper($state_country),
508
-                        'STA_abbrev' => strtoupper($state_abbr),
509
-                        'STA_name'   => ucwords($state_name),
510
-                        'STA_active' => false,
511
-                    ]
512
-                );
513
-                if ($new_state instanceof EE_State) {
514
-                    // clean house
515
-                    $request->unSetRequestParams(
516
-                        [
517
-                            'nsmf_add_new_state',
518
-                            'nsmf_new_state_country',
519
-                            'nsmf_new_state_name',
520
-                            'nsmf_new_state_abbrv',
521
-                        ]
522
-                    );
523
-                    // get any existing new states
524
-                    $new_states                     = EE_Registry::instance()->SSN->get_session_data('nsmf_new_states');
525
-                    $new_states[ $new_state->ID() ] = $new_state;
526
-                    EE_Registry::instance()->SSN->set_session_data(
527
-                        ['nsmf_new_states' => $new_states]
528
-                    );
529
-                    if ($request->isAjax()) {
530
-                        echo wp_json_encode(
531
-                            [
532
-                                'success'      => true,
533
-                                'id'           => $new_state->ID(),
534
-                                'name'         => $new_state->name(),
535
-                                'abbrev'       => $new_state->abbrev(),
536
-                                'country_iso'  => $new_state->country_iso(),
537
-                                'country_name' => $new_state->country()->name(),
538
-                            ]
539
-                        );
540
-                        exit();
541
-                    }
542
-                    return $new_state->ID();
543
-                }
544
-            } else {
545
-                $error = esc_html__(
546
-                    'A new State/Province could not be added because invalid or missing data was received.',
547
-                    'event_espresso'
548
-                );
549
-                if ($request->isAjax()) {
550
-                    echo wp_json_encode(['error' => $error]);
551
-                    exit();
552
-                }
553
-                EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
554
-            }
555
-        }
556
-        return false;
557
-    }
558
-
559
-
560
-    /**
561
-     * recursively drills down through request params to remove any that were added by this module
562
-     *
563
-     * @param array $request_params
564
-     * @return array
565
-     */
566
-    public static function filter_checkout_request_params($request_params)
567
-    {
568
-        foreach ($request_params as $form_section) {
569
-            if (is_array($form_section)) {
570
-                EED_Add_New_State::unset_new_state_request_params($form_section);
571
-                EED_Add_New_State::filter_checkout_request_params($form_section);
572
-            }
573
-        }
574
-        return $request_params;
575
-    }
576
-
577
-
578
-    /**
579
-     * @param array $request_params
580
-     * @return array
581
-     */
582
-    public static function unset_new_state_request_params($request_params)
583
-    {
584
-        unset(
585
-            $request_params['new_state_micro_form'],
586
-            $request_params['new_state_micro_add_new_state'],
587
-            $request_params['new_state_micro_new_state_country'],
588
-            $request_params['new_state_micro_new_state_name'],
589
-            $request_params['new_state_micro_new_state_abbrv']
590
-        );
591
-        return $request_params;
592
-    }
593
-
594
-
595
-    /**
596
-     * @param array $props_n_values
597
-     * @return EE_State|null
598
-     * @throws EE_Error
599
-     * @throws ReflectionException
600
-     */
601
-    public static function save_new_state_to_db($props_n_values = [])
602
-    {
603
-        /** @var EE_State[] $existing_state */
604
-        $existing_state = EEM_State::instance()->get_all([$props_n_values, 'limit' => 1]);
605
-        if (! empty($existing_state)) {
606
-            return array_pop($existing_state);
607
-        }
608
-        $new_state = EE_State::new_instance($props_n_values);
609
-        if ($new_state instanceof EE_State) {
610
-            $country_settings_url = add_query_arg(
611
-                [
612
-                    'page'    => 'espresso_general_settings',
613
-                    'action'  => 'country_settings',
614
-                    'country' => $new_state->country_iso(),
615
-                ],
616
-                admin_url('admin.php')
617
-            );
618
-            // if not non-ajax admin
619
-            new PersistentAdminNotice(
620
-                'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(),
621
-                sprintf(
622
-                    esc_html__(
623
-                        'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.',
624
-                        'event_espresso'
625
-                    ),
626
-                    '<b>' . $new_state->name() . '</b>',
627
-                    '<b>' . $new_state->abbrev() . '</b>',
628
-                    '<b>' . $new_state->country()->name() . '</b>',
629
-                    '<a href="'
630
-                    . $country_settings_url
631
-                    . '">'
632
-                    . esc_html__(
633
-                        'Event Espresso - General Settings > Countries Tab',
634
-                        'event_espresso'
635
-                    )
636
-                    . '</a>',
637
-                    '<br />'
638
-                )
639
-            );
640
-            $new_state->save();
641
-            EEM_State::instance()->reset_cached_states();
642
-            return $new_state;
643
-        }
644
-        return null;
645
-    }
646
-
647
-
648
-    /**
649
-     * @param string $CNT_ISO
650
-     * @param string $STA_ID
651
-     * @param array  $cols_n_values
652
-     * @return void
653
-     * @throws DomainException
654
-     * @throws EE_Error
655
-     * @throws InvalidArgumentException
656
-     * @throws InvalidDataTypeException
657
-     * @throws InvalidInterfaceException
658
-     */
659
-    public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = [])
660
-    {
661
-        if (! $CNT_ISO) {
662
-            EE_Error::add_error(
663
-                esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'),
664
-                __FILE__,
665
-                __FUNCTION__,
666
-                __LINE__
667
-            );
668
-        }
669
-        $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev']
670
-            : false;
671
-        if (! $STA_abbrev && ! empty($STA_ID)) {
672
-            $state = EEM_State::instance()->get_one_by_ID($STA_ID);
673
-            if ($state instanceof EE_State) {
674
-                $STA_abbrev = $state->abbrev();
675
-            }
676
-        }
677
-        if (! $STA_abbrev) {
678
-            EE_Error::add_error(
679
-                esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'),
680
-                __FILE__,
681
-                __FUNCTION__,
682
-                __LINE__
683
-            );
684
-        }
685
-        /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */
686
-        $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
687
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
688
-        );
689
-        $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true);
690
-    }
691
-
692
-
693
-    /**
694
-     * @param EE_State[]                            $state_options
695
-     * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step
696
-     * @param EE_Registration                       $registration
697
-     * @param EE_Question                           $question
698
-     * @param                                       $answer
699
-     * @return array
700
-     * @throws EE_Error
701
-     * @throws ReflectionException
702
-     */
703
-    public static function inject_new_reg_state_into_options(
704
-        array $state_options,
705
-        EE_SPCO_Reg_Step_Attendee_Information $reg_step,
706
-        EE_Registration $registration,
707
-        EE_Question $question,
708
-        $answer
709
-    ) {
710
-        if (
711
-            $answer instanceof EE_Answer && $question instanceof EE_Question
712
-            && $question->type() === EEM_Question::QST_type_state
713
-        ) {
714
-            $STA_ID = $answer->value();
715
-            if (! empty($STA_ID)) {
716
-                $state = EEM_State::instance()->get_one_by_ID($STA_ID);
717
-                if ($state instanceof EE_State) {
718
-                    $country = $state->country();
719
-                    if ($country instanceof EE_Country) {
720
-                        if (! isset($state_options[ $country->name() ])) {
721
-                            $state_options[ $country->name() ] = [];
722
-                        }
723
-                        if (! isset($state_options[ $country->name() ][ $STA_ID ])) {
724
-                            $state_options[ $country->name() ][ $STA_ID ] = $state->name();
725
-                        }
726
-                    }
727
-                }
728
-            }
729
-        }
730
-        return $state_options;
731
-    }
732
-
733
-
734
-    /**
735
-     * @param EE_Country[]                          $country_options
736
-     * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step
737
-     * @param EE_Registration                       $registration
738
-     * @param EE_Question                           $question
739
-     * @param                                       $answer
740
-     * @return array
741
-     * @throws EE_Error
742
-     * @throws ReflectionException
743
-     */
744
-    public static function inject_new_reg_country_into_options(
745
-        array $country_options,
746
-        EE_SPCO_Reg_Step_Attendee_Information $reg_step,
747
-        EE_Registration $registration,
748
-        EE_Question $question,
749
-        $answer
750
-    ) {
751
-        if (
752
-            $answer instanceof EE_Answer && $question instanceof EE_Question
753
-            && $question->type()
754
-               === EEM_Question::QST_type_country
755
-        ) {
756
-            $CNT_ISO = $answer->value();
757
-            if (! empty($CNT_ISO)) {
758
-                $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
759
-                if ($country instanceof EE_Country) {
760
-                    if (! isset($country_options[ $CNT_ISO ])) {
761
-                        $country_options[ $CNT_ISO ] = $country->name();
762
-                    }
763
-                }
764
-            }
765
-        }
766
-        return $country_options;
767
-    }
768
-
769
-
770
-    /**
771
-     * @param EE_State[] $state_options
772
-     * @return array
773
-     * @throws EE_Error
774
-     * @throws ReflectionException
775
-     */
776
-    public static function state_options($state_options = [])
777
-    {
778
-        $new_states = EED_Add_New_State::_get_new_states();
779
-        foreach ($new_states as $new_state) {
780
-            if (
781
-                $new_state instanceof EE_State
782
-                && $new_state->country() instanceof EE_Country
783
-            ) {
784
-                $state_options[ $new_state->country()->name() ][ $new_state->ID() ] = $new_state->name();
785
-            }
786
-        }
787
-        return $state_options;
788
-    }
789
-
790
-
791
-    /**
792
-     * @return array
793
-     * @throws InvalidArgumentException
794
-     * @throws InvalidDataTypeException
795
-     * @throws InvalidInterfaceException
796
-     */
797
-    protected static function _get_new_states()
798
-    {
799
-        $new_states = [];
800
-        if (EE_Registry::instance()->SSN instanceof EE_Session) {
801
-            $new_states = EE_Registry::instance()->SSN->get_session_data(
802
-                'nsmf_new_states'
803
-            );
804
-        }
805
-        return is_array($new_states) ? $new_states : [];
806
-    }
807
-
808
-
809
-    /**
810
-     * @param EE_Country[] $country_options
811
-     * @return array
812
-     * @throws EE_Error
813
-     * @throws ReflectionException
814
-     */
815
-    public static function country_options($country_options = [])
816
-    {
817
-        $new_states = EED_Add_New_State::_get_new_states();
818
-        foreach ($new_states as $new_state) {
819
-            if (
820
-                $new_state instanceof EE_State
821
-                && $new_state->country() instanceof EE_Country
822
-            ) {
823
-                $country_options[ $new_state->country()->ID() ] = $new_state->country()->name();
824
-            }
825
-        }
826
-        return $country_options;
827
-    }
20
+	/**
21
+	 * @return EED_Add_New_State|EED_Module
22
+	 * @throws EE_Error
23
+	 * @throws ReflectionException
24
+	 */
25
+	public static function instance()
26
+	{
27
+		return parent::get_instance(__CLASS__);
28
+	}
29
+
30
+
31
+	/**
32
+	 * set_hooks - for hooking into EE Core, other modules, etc
33
+	 *
34
+	 * @return void
35
+	 */
36
+	public static function set_hooks()
37
+	{
38
+		add_action('wp_loaded', ['EED_Add_New_State', 'set_definitions'], 2);
39
+		add_action('wp_enqueue_scripts', ['EED_Add_New_State', 'translate_js_strings'], 0);
40
+		add_action('wp_enqueue_scripts', ['EED_Add_New_State', 'wp_enqueue_scripts'], 10);
41
+		add_filter(
42
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
43
+			['EED_Add_New_State', 'display_add_new_state_micro_form'],
44
+			1,
45
+			1
46
+		);
47
+		add_filter(
48
+			'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
49
+			['EED_Add_New_State', 'display_add_new_state_micro_form'],
50
+			1,
51
+			1
52
+		);
53
+		add_filter(
54
+			'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
55
+			['EED_Add_New_State', 'unset_new_state_request_params'],
56
+			10,
57
+			1
58
+		);
59
+		add_filter(
60
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
61
+			['EED_Add_New_State', 'inject_new_reg_state_into_options'],
62
+			10,
63
+			5
64
+		);
65
+		add_filter(
66
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
67
+			['EED_Add_New_State', 'inject_new_reg_country_into_options'],
68
+			10,
69
+			5
70
+		);
71
+		add_filter(
72
+			'FHEE__EE_State_Select_Input____construct__state_options',
73
+			['EED_Add_New_State', 'state_options'],
74
+			10,
75
+			1
76
+		);
77
+		add_filter(
78
+			'FHEE__EE_Country_Select_Input____construct__country_options',
79
+			['EED_Add_New_State', 'country_options'],
80
+			10,
81
+			1
82
+		);
83
+	}
84
+
85
+
86
+	/**
87
+	 * set_hooks_admin - for hooking into EE Admin Core, other modules, etc
88
+	 *
89
+	 * @return void
90
+	 */
91
+	public static function set_hooks_admin()
92
+	{
93
+		add_action('wp_loaded', ['EED_Add_New_State', 'set_definitions'], 2);
94
+		add_filter(
95
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
96
+			['EED_Add_New_State', 'display_add_new_state_micro_form'],
97
+			1,
98
+			1
99
+		);
100
+		add_filter(
101
+			'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form',
102
+			['EED_Add_New_State', 'display_add_new_state_micro_form'],
103
+			1,
104
+			1
105
+		);
106
+		add_action('wp_ajax_espresso_add_new_state', ['EED_Add_New_State', 'add_new_state']);
107
+		add_action('wp_ajax_nopriv_espresso_add_new_state', ['EED_Add_New_State', 'add_new_state']);
108
+		add_filter(
109
+			'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
110
+			['EED_Add_New_State', 'unset_new_state_request_params'],
111
+			10,
112
+			1
113
+		);
114
+		add_action(
115
+			'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved',
116
+			['EED_Add_New_State', 'update_country_settings'],
117
+			10,
118
+			3
119
+		);
120
+		add_action(
121
+			'AHEE__General_Settings_Admin_Page__delete_state__state_deleted',
122
+			['EED_Add_New_State', 'update_country_settings'],
123
+			10,
124
+			3
125
+		);
126
+		add_filter(
127
+			'FHEE__EE_State_Select_Input____construct__state_options',
128
+			['EED_Add_New_State', 'state_options'],
129
+			10,
130
+			1
131
+		);
132
+		add_filter(
133
+			'FHEE__EE_Country_Select_Input____construct__country_options',
134
+			['EED_Add_New_State', 'country_options'],
135
+			10,
136
+			1
137
+		);
138
+		add_filter(
139
+			'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data',
140
+			['EED_Add_New_State', 'filter_checkout_request_params'],
141
+			10,
142
+			1
143
+		);
144
+		add_filter(
145
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
146
+			['EED_Add_New_State', 'inject_new_reg_state_into_options'],
147
+			10,
148
+			5
149
+		);
150
+		add_filter(
151
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
152
+			['EED_Add_New_State', 'inject_new_reg_country_into_options'],
153
+			10,
154
+			5
155
+		);
156
+	}
157
+
158
+
159
+	/**
160
+	 * @return void
161
+	 */
162
+	public static function set_definitions()
163
+	{
164
+		define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
165
+		define(
166
+			'ANS_TEMPLATES_PATH',
167
+			str_replace(
168
+				'\\',
169
+				'/',
170
+				plugin_dir_path(__FILE__)
171
+			) . 'templates/'
172
+		);
173
+	}
174
+
175
+
176
+	/**
177
+	 * @param WP $WP
178
+	 * @return void
179
+	 */
180
+	public function run($WP)
181
+	{
182
+	}
183
+
184
+
185
+	/**
186
+	 * @return void
187
+	 */
188
+	public static function translate_js_strings()
189
+	{
190
+		EE_Registry::$i18n_js_strings['ans_no_country']        = esc_html__(
191
+			'In order to proceed, you need to select the Country that your State/Province belongs to.',
192
+			'event_espresso'
193
+		);
194
+		EE_Registry::$i18n_js_strings['ans_no_name']           = esc_html__(
195
+			'In order to proceed, you need to enter the name of your State/Province.',
196
+			'event_espresso'
197
+		);
198
+		EE_Registry::$i18n_js_strings['ans_no_abbreviation']   = esc_html__(
199
+			'In order to proceed, you need to enter an abbreviation for the name of your State/Province.',
200
+			'event_espresso'
201
+		);
202
+		EE_Registry::$i18n_js_strings['ans_save_success']      = esc_html__(
203
+			'The new state was successfully saved to the database.',
204
+			'event_espresso'
205
+		);
206
+		EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__(
207
+			'An unknown error has occurred on the server while saving the new state to the database.',
208
+			'event_espresso'
209
+		);
210
+	}
211
+
212
+
213
+	/**
214
+	 * @return void
215
+	 */
216
+	public static function wp_enqueue_scripts()
217
+	{
218
+		if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) {
219
+			wp_register_script(
220
+				'add_new_state',
221
+				ANS_ASSETS_URL . 'add_new_state.js',
222
+				['espresso_core', 'single_page_checkout'],
223
+				EVENT_ESPRESSO_VERSION,
224
+				true
225
+			);
226
+			wp_enqueue_script('add_new_state');
227
+		}
228
+	}
229
+
230
+
231
+	/**
232
+	 * display_add_new_state_micro_form
233
+	 *
234
+	 * @param EE_Form_Section_Proper $question_group_reg_form
235
+	 * @return EE_Form_Section_Proper
236
+	 * @throws EE_Error
237
+	 * @throws ReflectionException
238
+	 */
239
+	public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form)
240
+	{
241
+		$request = self::getRequest();
242
+		// only add the 'new_state_micro_form' when displaying reg forms,
243
+		// not during processing since we process the 'new_state_micro_form' in it's own AJAX request
244
+		$action = $request->getRequestParam('action');
245
+		// is the "state" question in this form section?
246
+		$input = $question_group_reg_form->get_subsection('state');
247
+		if ($action === 'process_reg_step' || $action === 'update_reg_step') {
248
+			// ok then all we need to do is make sure the input's HTML name is consistent
249
+			// by forcing it to set it now, like it did while getting the form for display
250
+			if ($input instanceof EE_State_Select_Input) {
251
+				$input->html_name();
252
+			}
253
+			return $question_group_reg_form;
254
+		}
255
+		// we're only doing this for state select inputs
256
+		if (
257
+			$input instanceof EE_State_Select_Input
258
+			&& ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy
259
+		) {
260
+			// grab any set values from the request
261
+			$country_name        = str_replace('state', 'nsmf_new_state_country', $input->html_name());
262
+			$state_name          = str_replace('state', 'nsmf_new_state_name', $input->html_name());
263
+			$abbrv_name          = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name());
264
+			$new_state_submit_id = str_replace('state', 'new_state', $input->html_id());
265
+			$country_options     = [];
266
+			$countries           = EEM_Country::instance()->get_all_countries();
267
+			if (! empty($countries)) {
268
+				foreach ($countries as $country) {
269
+					if ($country instanceof EE_Country) {
270
+						$country_options[ $country->ID() ] = $country->name();
271
+					}
272
+				}
273
+			}
274
+			$new_state_micro_form = new EE_Form_Section_Proper(
275
+				[
276
+					'name'            => 'new_state_micro_form',
277
+					'html_id'         => 'new_state_micro_form',
278
+					'layout_strategy' => new EE_Div_Per_Section_Layout(),
279
+					'subsections'     => [
280
+						// add hidden input to indicate that a new state is being added
281
+						'add_new_state'               => new EE_Hidden_Input(
282
+							[
283
+								'html_name' => str_replace(
284
+									'state',
285
+									'nsmf_add_new_state',
286
+									$input->html_name()
287
+								),
288
+								'html_id'   => str_replace(
289
+									'state',
290
+									'nsmf_add_new_state',
291
+									$input->html_id()
292
+								),
293
+								'default'   => 0,
294
+							]
295
+						),
296
+						// add link for displaying hidden container
297
+						'click_here_link'             => new EE_Form_Section_HTML(
298
+							apply_filters(
299
+								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link',
300
+								EEH_HTML::link(
301
+									'',
302
+									esc_html__('click here to add a new state/province', 'event_espresso'),
303
+									'',
304
+									'display-' . $input->html_id(),
305
+									'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js',
306
+									'',
307
+									'data-target="' . $input->html_id() . '"'
308
+								)
309
+							)
310
+						),
311
+						// add initial html for hidden container
312
+						'add_new_state_micro_form'    => new EE_Form_Section_HTML(
313
+							apply_filters(
314
+								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form',
315
+								EEH_HTML::div(
316
+									'',
317
+									$input->html_id() . '-dv',
318
+									'ee-form-add-new-state-dv',
319
+									'display: none;'
320
+								) .
321
+								EEH_HTML::h6(
322
+									esc_html__(
323
+										'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:',
324
+										'event_espresso'
325
+									)
326
+								) .
327
+								EEH_HTML::ul() .
328
+								EEH_HTML::li(
329
+									esc_html__(
330
+										'first select the Country that your State/Province belongs to',
331
+										'event_espresso'
332
+									)
333
+								) .
334
+								EEH_HTML::li(
335
+									esc_html__('enter the name of your State/Province', 'event_espresso')
336
+								) .
337
+								EEH_HTML::li(
338
+									esc_html__(
339
+										'enter a two to six letter abbreviation for the name of your State/Province',
340
+										'event_espresso'
341
+									)
342
+								) .
343
+								EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) .
344
+								EEH_HTML::ulx()
345
+							)
346
+						),
347
+						// NEW STATE COUNTRY
348
+						'new_state_country'           => new EE_Country_Select_Input(
349
+							$country_options,
350
+							[
351
+								'html_name'       => $country_name,
352
+								'html_id'         => str_replace(
353
+									'state',
354
+									'nsmf_new_state_country',
355
+									$input->html_id()
356
+								),
357
+								'html_class'      => $input->html_class() . ' new-state-country',
358
+								'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'),
359
+								'default'         => $request->getRequestParam($country_name),
360
+								'required'        => false,
361
+							]
362
+						),
363
+						// NEW STATE NAME
364
+						'new_state_name'              => new EE_Text_Input(
365
+							[
366
+								'html_name'       => $state_name,
367
+								'html_id'         => str_replace(
368
+									'state',
369
+									'nsmf_new_state_name',
370
+									$input->html_id()
371
+								),
372
+								'html_class'      => $input->html_class() . ' new-state-state',
373
+								'html_label_text' => esc_html__(
374
+									'New State/Province Name',
375
+									'event_espresso'
376
+								),
377
+								'default'         => $request->getRequestParam($state_name),
378
+								'required'        => false,
379
+							]
380
+						),
381
+						// NEW STATE NAME
382
+						'new_state_abbrv'             => new EE_Text_Input(
383
+							[
384
+								'html_name'             => $abbrv_name,
385
+								'html_id'               => str_replace(
386
+									'state',
387
+									'nsmf_new_state_abbrv',
388
+									$input->html_id()
389
+								),
390
+								'html_class'            => $input->html_class() . ' new-state-abbrv',
391
+								'html_label_text'       => esc_html__(
392
+									'New State/Province Abbreviation',
393
+									'event_espresso'
394
+								) . ' *',
395
+								'other_html_attributes' => 'size="24"',
396
+								'default'               => $request->getRequestParam($abbrv_name),
397
+								'required'              => false,
398
+							]
399
+						),
400
+						// "submit" button
401
+						'add_new_state_submit_button' => new EE_Form_Section_HTML(
402
+							apply_filters(
403
+								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button',
404
+								EEH_HTML::div(
405
+									EEH_HTML::button(
406
+										esc_html__('ADD', 'event_espresso'),
407
+										'ee-form-add-new-state-submit button button-secondary',
408
+										'',
409
+										'submit-' . $new_state_submit_id,
410
+										'',
411
+										'data-target="' . $new_state_submit_id . '"'
412
+										. ' data-value-field-name="' . $input->valueFieldName() . '"'
413
+									),
414
+									'',
415
+									'ee-form-add-new-state-submit-dv'
416
+								)
417
+							)
418
+						),
419
+						// extra info
420
+						'add_new_state_extra'         => new EE_Form_Section_HTML(
421
+							apply_filters(
422
+								'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra',
423
+								EEH_HTML::br()
424
+								.
425
+								EEH_HTML::div('', '', 'small-text')
426
+								.
427
+								EEH_HTML::strong(
428
+									'* ' .
429
+									esc_html__(
430
+										'Don\'t know your State/Province Abbreviation?',
431
+										'event_espresso'
432
+									)
433
+								)
434
+								.
435
+								EEH_HTML::br()
436
+								.
437
+								sprintf(
438
+									esc_html__(
439
+										'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).',
440
+										'event_espresso'
441
+									),
442
+									EEH_HTML::link(
443
+										'https://en.wikipedia.org/wiki/ISO_3166-2',
444
+										'https://en.wikipedia.org/wiki/ISO_3166-2',
445
+										'',
446
+										'',
447
+										'ee-form-add-new-state-wiki-lnk',
448
+										'',
449
+										'target="_blank"'
450
+									)
451
+								)
452
+								.
453
+								EEH_HTML::divx()
454
+								.
455
+								EEH_HTML::br()
456
+								.
457
+								EEH_HTML::link(
458
+									'',
459
+									esc_html__('cancel new State/Province', 'event_espresso'),
460
+									'',
461
+									'hide-' . $input->html_id(),
462
+									'ee-form-cancel-new-state-lnk smaller-text',
463
+									'',
464
+									'data-target="' . $input->html_id() . '"'
465
+								)
466
+								.
467
+								EEH_HTML::divx()
468
+								.
469
+								EEH_HTML::br()
470
+							)
471
+						),
472
+					],
473
+				]
474
+			);
475
+			$question_group_reg_form->add_subsections(
476
+				['new_state_micro_form' => $new_state_micro_form],
477
+				'state',
478
+				false
479
+			);
480
+		}
481
+		return $question_group_reg_form;
482
+	}
483
+
484
+
485
+	/**
486
+	 * set_new_state_input_width
487
+	 *
488
+	 * @return int|string
489
+	 * @throws EE_Error
490
+	 * @throws InvalidArgumentException
491
+	 * @throws InvalidDataTypeException
492
+	 * @throws InvalidInterfaceException
493
+	 * @throws ReflectionException
494
+	 */
495
+	public static function add_new_state()
496
+	{
497
+		$request = self::getRequest();
498
+		if ($request->getRequestParam('nsmf_add_new_state', 0, 'int') === 1) {
499
+			EE_Registry::instance()->load_model('State');
500
+			// grab country ISO code, new state name, and new state abbreviation
501
+			$state_country = $request->getRequestParam('nsmf_new_state_country');
502
+			$state_name    = $request->getRequestParam('nsmf_new_state_name');
503
+			$state_abbr    = $request->getRequestParam('nsmf_new_state_abbrv');
504
+			if ($state_country && $state_name && $state_abbr) {
505
+				$new_state = EED_Add_New_State::save_new_state_to_db(
506
+					[
507
+						'CNT_ISO'    => strtoupper($state_country),
508
+						'STA_abbrev' => strtoupper($state_abbr),
509
+						'STA_name'   => ucwords($state_name),
510
+						'STA_active' => false,
511
+					]
512
+				);
513
+				if ($new_state instanceof EE_State) {
514
+					// clean house
515
+					$request->unSetRequestParams(
516
+						[
517
+							'nsmf_add_new_state',
518
+							'nsmf_new_state_country',
519
+							'nsmf_new_state_name',
520
+							'nsmf_new_state_abbrv',
521
+						]
522
+					);
523
+					// get any existing new states
524
+					$new_states                     = EE_Registry::instance()->SSN->get_session_data('nsmf_new_states');
525
+					$new_states[ $new_state->ID() ] = $new_state;
526
+					EE_Registry::instance()->SSN->set_session_data(
527
+						['nsmf_new_states' => $new_states]
528
+					);
529
+					if ($request->isAjax()) {
530
+						echo wp_json_encode(
531
+							[
532
+								'success'      => true,
533
+								'id'           => $new_state->ID(),
534
+								'name'         => $new_state->name(),
535
+								'abbrev'       => $new_state->abbrev(),
536
+								'country_iso'  => $new_state->country_iso(),
537
+								'country_name' => $new_state->country()->name(),
538
+							]
539
+						);
540
+						exit();
541
+					}
542
+					return $new_state->ID();
543
+				}
544
+			} else {
545
+				$error = esc_html__(
546
+					'A new State/Province could not be added because invalid or missing data was received.',
547
+					'event_espresso'
548
+				);
549
+				if ($request->isAjax()) {
550
+					echo wp_json_encode(['error' => $error]);
551
+					exit();
552
+				}
553
+				EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
554
+			}
555
+		}
556
+		return false;
557
+	}
558
+
559
+
560
+	/**
561
+	 * recursively drills down through request params to remove any that were added by this module
562
+	 *
563
+	 * @param array $request_params
564
+	 * @return array
565
+	 */
566
+	public static function filter_checkout_request_params($request_params)
567
+	{
568
+		foreach ($request_params as $form_section) {
569
+			if (is_array($form_section)) {
570
+				EED_Add_New_State::unset_new_state_request_params($form_section);
571
+				EED_Add_New_State::filter_checkout_request_params($form_section);
572
+			}
573
+		}
574
+		return $request_params;
575
+	}
576
+
577
+
578
+	/**
579
+	 * @param array $request_params
580
+	 * @return array
581
+	 */
582
+	public static function unset_new_state_request_params($request_params)
583
+	{
584
+		unset(
585
+			$request_params['new_state_micro_form'],
586
+			$request_params['new_state_micro_add_new_state'],
587
+			$request_params['new_state_micro_new_state_country'],
588
+			$request_params['new_state_micro_new_state_name'],
589
+			$request_params['new_state_micro_new_state_abbrv']
590
+		);
591
+		return $request_params;
592
+	}
593
+
594
+
595
+	/**
596
+	 * @param array $props_n_values
597
+	 * @return EE_State|null
598
+	 * @throws EE_Error
599
+	 * @throws ReflectionException
600
+	 */
601
+	public static function save_new_state_to_db($props_n_values = [])
602
+	{
603
+		/** @var EE_State[] $existing_state */
604
+		$existing_state = EEM_State::instance()->get_all([$props_n_values, 'limit' => 1]);
605
+		if (! empty($existing_state)) {
606
+			return array_pop($existing_state);
607
+		}
608
+		$new_state = EE_State::new_instance($props_n_values);
609
+		if ($new_state instanceof EE_State) {
610
+			$country_settings_url = add_query_arg(
611
+				[
612
+					'page'    => 'espresso_general_settings',
613
+					'action'  => 'country_settings',
614
+					'country' => $new_state->country_iso(),
615
+				],
616
+				admin_url('admin.php')
617
+			);
618
+			// if not non-ajax admin
619
+			new PersistentAdminNotice(
620
+				'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(),
621
+				sprintf(
622
+					esc_html__(
623
+						'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.',
624
+						'event_espresso'
625
+					),
626
+					'<b>' . $new_state->name() . '</b>',
627
+					'<b>' . $new_state->abbrev() . '</b>',
628
+					'<b>' . $new_state->country()->name() . '</b>',
629
+					'<a href="'
630
+					. $country_settings_url
631
+					. '">'
632
+					. esc_html__(
633
+						'Event Espresso - General Settings > Countries Tab',
634
+						'event_espresso'
635
+					)
636
+					. '</a>',
637
+					'<br />'
638
+				)
639
+			);
640
+			$new_state->save();
641
+			EEM_State::instance()->reset_cached_states();
642
+			return $new_state;
643
+		}
644
+		return null;
645
+	}
646
+
647
+
648
+	/**
649
+	 * @param string $CNT_ISO
650
+	 * @param string $STA_ID
651
+	 * @param array  $cols_n_values
652
+	 * @return void
653
+	 * @throws DomainException
654
+	 * @throws EE_Error
655
+	 * @throws InvalidArgumentException
656
+	 * @throws InvalidDataTypeException
657
+	 * @throws InvalidInterfaceException
658
+	 */
659
+	public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = [])
660
+	{
661
+		if (! $CNT_ISO) {
662
+			EE_Error::add_error(
663
+				esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'),
664
+				__FILE__,
665
+				__FUNCTION__,
666
+				__LINE__
667
+			);
668
+		}
669
+		$STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev']
670
+			: false;
671
+		if (! $STA_abbrev && ! empty($STA_ID)) {
672
+			$state = EEM_State::instance()->get_one_by_ID($STA_ID);
673
+			if ($state instanceof EE_State) {
674
+				$STA_abbrev = $state->abbrev();
675
+			}
676
+		}
677
+		if (! $STA_abbrev) {
678
+			EE_Error::add_error(
679
+				esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'),
680
+				__FILE__,
681
+				__FUNCTION__,
682
+				__LINE__
683
+			);
684
+		}
685
+		/** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */
686
+		$persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
687
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
688
+		);
689
+		$persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true);
690
+	}
691
+
692
+
693
+	/**
694
+	 * @param EE_State[]                            $state_options
695
+	 * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step
696
+	 * @param EE_Registration                       $registration
697
+	 * @param EE_Question                           $question
698
+	 * @param                                       $answer
699
+	 * @return array
700
+	 * @throws EE_Error
701
+	 * @throws ReflectionException
702
+	 */
703
+	public static function inject_new_reg_state_into_options(
704
+		array $state_options,
705
+		EE_SPCO_Reg_Step_Attendee_Information $reg_step,
706
+		EE_Registration $registration,
707
+		EE_Question $question,
708
+		$answer
709
+	) {
710
+		if (
711
+			$answer instanceof EE_Answer && $question instanceof EE_Question
712
+			&& $question->type() === EEM_Question::QST_type_state
713
+		) {
714
+			$STA_ID = $answer->value();
715
+			if (! empty($STA_ID)) {
716
+				$state = EEM_State::instance()->get_one_by_ID($STA_ID);
717
+				if ($state instanceof EE_State) {
718
+					$country = $state->country();
719
+					if ($country instanceof EE_Country) {
720
+						if (! isset($state_options[ $country->name() ])) {
721
+							$state_options[ $country->name() ] = [];
722
+						}
723
+						if (! isset($state_options[ $country->name() ][ $STA_ID ])) {
724
+							$state_options[ $country->name() ][ $STA_ID ] = $state->name();
725
+						}
726
+					}
727
+				}
728
+			}
729
+		}
730
+		return $state_options;
731
+	}
732
+
733
+
734
+	/**
735
+	 * @param EE_Country[]                          $country_options
736
+	 * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step
737
+	 * @param EE_Registration                       $registration
738
+	 * @param EE_Question                           $question
739
+	 * @param                                       $answer
740
+	 * @return array
741
+	 * @throws EE_Error
742
+	 * @throws ReflectionException
743
+	 */
744
+	public static function inject_new_reg_country_into_options(
745
+		array $country_options,
746
+		EE_SPCO_Reg_Step_Attendee_Information $reg_step,
747
+		EE_Registration $registration,
748
+		EE_Question $question,
749
+		$answer
750
+	) {
751
+		if (
752
+			$answer instanceof EE_Answer && $question instanceof EE_Question
753
+			&& $question->type()
754
+			   === EEM_Question::QST_type_country
755
+		) {
756
+			$CNT_ISO = $answer->value();
757
+			if (! empty($CNT_ISO)) {
758
+				$country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
759
+				if ($country instanceof EE_Country) {
760
+					if (! isset($country_options[ $CNT_ISO ])) {
761
+						$country_options[ $CNT_ISO ] = $country->name();
762
+					}
763
+				}
764
+			}
765
+		}
766
+		return $country_options;
767
+	}
768
+
769
+
770
+	/**
771
+	 * @param EE_State[] $state_options
772
+	 * @return array
773
+	 * @throws EE_Error
774
+	 * @throws ReflectionException
775
+	 */
776
+	public static function state_options($state_options = [])
777
+	{
778
+		$new_states = EED_Add_New_State::_get_new_states();
779
+		foreach ($new_states as $new_state) {
780
+			if (
781
+				$new_state instanceof EE_State
782
+				&& $new_state->country() instanceof EE_Country
783
+			) {
784
+				$state_options[ $new_state->country()->name() ][ $new_state->ID() ] = $new_state->name();
785
+			}
786
+		}
787
+		return $state_options;
788
+	}
789
+
790
+
791
+	/**
792
+	 * @return array
793
+	 * @throws InvalidArgumentException
794
+	 * @throws InvalidDataTypeException
795
+	 * @throws InvalidInterfaceException
796
+	 */
797
+	protected static function _get_new_states()
798
+	{
799
+		$new_states = [];
800
+		if (EE_Registry::instance()->SSN instanceof EE_Session) {
801
+			$new_states = EE_Registry::instance()->SSN->get_session_data(
802
+				'nsmf_new_states'
803
+			);
804
+		}
805
+		return is_array($new_states) ? $new_states : [];
806
+	}
807
+
808
+
809
+	/**
810
+	 * @param EE_Country[] $country_options
811
+	 * @return array
812
+	 * @throws EE_Error
813
+	 * @throws ReflectionException
814
+	 */
815
+	public static function country_options($country_options = [])
816
+	{
817
+		$new_states = EED_Add_New_State::_get_new_states();
818
+		foreach ($new_states as $new_state) {
819
+			if (
820
+				$new_state instanceof EE_State
821
+				&& $new_state->country() instanceof EE_Country
822
+			) {
823
+				$country_options[ $new_state->country()->ID() ] = $new_state->country()->name();
824
+			}
825
+		}
826
+		return $country_options;
827
+	}
828 828
 }
Please login to merge, or discard this patch.
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -161,14 +161,14 @@  discard block
 block discarded – undo
161 161
      */
162 162
     public static function set_definitions()
163 163
     {
164
-        define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/');
164
+        define('ANS_ASSETS_URL', plugin_dir_url(__FILE__).'assets/');
165 165
         define(
166 166
             'ANS_TEMPLATES_PATH',
167 167
             str_replace(
168 168
                 '\\',
169 169
                 '/',
170 170
                 plugin_dir_path(__FILE__)
171
-            ) . 'templates/'
171
+            ).'templates/'
172 172
         );
173 173
     }
174 174
 
@@ -187,19 +187,19 @@  discard block
 block discarded – undo
187 187
      */
188 188
     public static function translate_js_strings()
189 189
     {
190
-        EE_Registry::$i18n_js_strings['ans_no_country']        = esc_html__(
190
+        EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__(
191 191
             'In order to proceed, you need to select the Country that your State/Province belongs to.',
192 192
             'event_espresso'
193 193
         );
194
-        EE_Registry::$i18n_js_strings['ans_no_name']           = esc_html__(
194
+        EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__(
195 195
             'In order to proceed, you need to enter the name of your State/Province.',
196 196
             'event_espresso'
197 197
         );
198
-        EE_Registry::$i18n_js_strings['ans_no_abbreviation']   = esc_html__(
198
+        EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__(
199 199
             'In order to proceed, you need to enter an abbreviation for the name of your State/Province.',
200 200
             'event_espresso'
201 201
         );
202
-        EE_Registry::$i18n_js_strings['ans_save_success']      = esc_html__(
202
+        EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__(
203 203
             'The new state was successfully saved to the database.',
204 204
             'event_espresso'
205 205
         );
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
         if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) {
219 219
             wp_register_script(
220 220
                 'add_new_state',
221
-                ANS_ASSETS_URL . 'add_new_state.js',
221
+                ANS_ASSETS_URL.'add_new_state.js',
222 222
                 ['espresso_core', 'single_page_checkout'],
223 223
                 EVENT_ESPRESSO_VERSION,
224 224
                 true
@@ -264,10 +264,10 @@  discard block
 block discarded – undo
264 264
             $new_state_submit_id = str_replace('state', 'new_state', $input->html_id());
265 265
             $country_options     = [];
266 266
             $countries           = EEM_Country::instance()->get_all_countries();
267
-            if (! empty($countries)) {
267
+            if ( ! empty($countries)) {
268 268
                 foreach ($countries as $country) {
269 269
                     if ($country instanceof EE_Country) {
270
-                        $country_options[ $country->ID() ] = $country->name();
270
+                        $country_options[$country->ID()] = $country->name();
271 271
                     }
272 272
                 }
273 273
             }
@@ -301,10 +301,10 @@  discard block
 block discarded – undo
301 301
                                     '',
302 302
                                     esc_html__('click here to add a new state/province', 'event_espresso'),
303 303
                                     '',
304
-                                    'display-' . $input->html_id(),
304
+                                    'display-'.$input->html_id(),
305 305
                                     'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js',
306 306
                                     '',
307
-                                    'data-target="' . $input->html_id() . '"'
307
+                                    'data-target="'.$input->html_id().'"'
308 308
                                 )
309 309
                             )
310 310
                         ),
@@ -314,33 +314,33 @@  discard block
 block discarded – undo
314 314
                                 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form',
315 315
                                 EEH_HTML::div(
316 316
                                     '',
317
-                                    $input->html_id() . '-dv',
317
+                                    $input->html_id().'-dv',
318 318
                                     'ee-form-add-new-state-dv',
319 319
                                     'display: none;'
320
-                                ) .
320
+                                ).
321 321
                                 EEH_HTML::h6(
322 322
                                     esc_html__(
323 323
                                         'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:',
324 324
                                         'event_espresso'
325 325
                                     )
326
-                                ) .
327
-                                EEH_HTML::ul() .
326
+                                ).
327
+                                EEH_HTML::ul().
328 328
                                 EEH_HTML::li(
329 329
                                     esc_html__(
330 330
                                         'first select the Country that your State/Province belongs to',
331 331
                                         'event_espresso'
332 332
                                     )
333
-                                ) .
333
+                                ).
334 334
                                 EEH_HTML::li(
335 335
                                     esc_html__('enter the name of your State/Province', 'event_espresso')
336
-                                ) .
336
+                                ).
337 337
                                 EEH_HTML::li(
338 338
                                     esc_html__(
339 339
                                         'enter a two to six letter abbreviation for the name of your State/Province',
340 340
                                         'event_espresso'
341 341
                                     )
342
-                                ) .
343
-                                EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) .
342
+                                ).
343
+                                EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')).
344 344
                                 EEH_HTML::ulx()
345 345
                             )
346 346
                         ),
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
                                     'nsmf_new_state_country',
355 355
                                     $input->html_id()
356 356
                                 ),
357
-                                'html_class'      => $input->html_class() . ' new-state-country',
357
+                                'html_class'      => $input->html_class().' new-state-country',
358 358
                                 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'),
359 359
                                 'default'         => $request->getRequestParam($country_name),
360 360
                                 'required'        => false,
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
                                     'nsmf_new_state_name',
370 370
                                     $input->html_id()
371 371
                                 ),
372
-                                'html_class'      => $input->html_class() . ' new-state-state',
372
+                                'html_class'      => $input->html_class().' new-state-state',
373 373
                                 'html_label_text' => esc_html__(
374 374
                                     'New State/Province Name',
375 375
                                     'event_espresso'
@@ -387,11 +387,11 @@  discard block
 block discarded – undo
387 387
                                     'nsmf_new_state_abbrv',
388 388
                                     $input->html_id()
389 389
                                 ),
390
-                                'html_class'            => $input->html_class() . ' new-state-abbrv',
390
+                                'html_class'            => $input->html_class().' new-state-abbrv',
391 391
                                 'html_label_text'       => esc_html__(
392 392
                                     'New State/Province Abbreviation',
393 393
                                     'event_espresso'
394
-                                ) . ' *',
394
+                                ).' *',
395 395
                                 'other_html_attributes' => 'size="24"',
396 396
                                 'default'               => $request->getRequestParam($abbrv_name),
397 397
                                 'required'              => false,
@@ -406,10 +406,10 @@  discard block
 block discarded – undo
406 406
                                         esc_html__('ADD', 'event_espresso'),
407 407
                                         'ee-form-add-new-state-submit button button-secondary',
408 408
                                         '',
409
-                                        'submit-' . $new_state_submit_id,
409
+                                        'submit-'.$new_state_submit_id,
410 410
                                         '',
411
-                                        'data-target="' . $new_state_submit_id . '"'
412
-                                        . ' data-value-field-name="' . $input->valueFieldName() . '"'
411
+                                        'data-target="'.$new_state_submit_id.'"'
412
+                                        . ' data-value-field-name="'.$input->valueFieldName().'"'
413 413
                                     ),
414 414
                                     '',
415 415
                                     'ee-form-add-new-state-submit-dv'
@@ -425,7 +425,7 @@  discard block
 block discarded – undo
425 425
                                 EEH_HTML::div('', '', 'small-text')
426 426
                                 .
427 427
                                 EEH_HTML::strong(
428
-                                    '* ' .
428
+                                    '* '.
429 429
                                     esc_html__(
430 430
                                         'Don\'t know your State/Province Abbreviation?',
431 431
                                         'event_espresso'
@@ -458,10 +458,10 @@  discard block
 block discarded – undo
458 458
                                     '',
459 459
                                     esc_html__('cancel new State/Province', 'event_espresso'),
460 460
                                     '',
461
-                                    'hide-' . $input->html_id(),
461
+                                    'hide-'.$input->html_id(),
462 462
                                     'ee-form-cancel-new-state-lnk smaller-text',
463 463
                                     '',
464
-                                    'data-target="' . $input->html_id() . '"'
464
+                                    'data-target="'.$input->html_id().'"'
465 465
                                 )
466 466
                                 .
467 467
                                 EEH_HTML::divx()
@@ -522,7 +522,7 @@  discard block
 block discarded – undo
522 522
                     );
523 523
                     // get any existing new states
524 524
                     $new_states                     = EE_Registry::instance()->SSN->get_session_data('nsmf_new_states');
525
-                    $new_states[ $new_state->ID() ] = $new_state;
525
+                    $new_states[$new_state->ID()] = $new_state;
526 526
                     EE_Registry::instance()->SSN->set_session_data(
527 527
                         ['nsmf_new_states' => $new_states]
528 528
                     );
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
     {
603 603
         /** @var EE_State[] $existing_state */
604 604
         $existing_state = EEM_State::instance()->get_all([$props_n_values, 'limit' => 1]);
605
-        if (! empty($existing_state)) {
605
+        if ( ! empty($existing_state)) {
606 606
             return array_pop($existing_state);
607 607
         }
608 608
         $new_state = EE_State::new_instance($props_n_values);
@@ -617,15 +617,15 @@  discard block
 block discarded – undo
617 617
             );
618 618
             // if not non-ajax admin
619 619
             new PersistentAdminNotice(
620
-                'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(),
620
+                'new-state-added-'.$new_state->country_iso().'-'.$new_state->abbrev(),
621 621
                 sprintf(
622 622
                     esc_html__(
623 623
                         'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.',
624 624
                         'event_espresso'
625 625
                     ),
626
-                    '<b>' . $new_state->name() . '</b>',
627
-                    '<b>' . $new_state->abbrev() . '</b>',
628
-                    '<b>' . $new_state->country()->name() . '</b>',
626
+                    '<b>'.$new_state->name().'</b>',
627
+                    '<b>'.$new_state->abbrev().'</b>',
628
+                    '<b>'.$new_state->country()->name().'</b>',
629 629
                     '<a href="'
630 630
                     . $country_settings_url
631 631
                     . '">'
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
      */
659 659
     public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = [])
660 660
     {
661
-        if (! $CNT_ISO) {
661
+        if ( ! $CNT_ISO) {
662 662
             EE_Error::add_error(
663 663
                 esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'),
664 664
                 __FILE__,
@@ -668,13 +668,13 @@  discard block
 block discarded – undo
668 668
         }
669 669
         $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev']
670 670
             : false;
671
-        if (! $STA_abbrev && ! empty($STA_ID)) {
671
+        if ( ! $STA_abbrev && ! empty($STA_ID)) {
672 672
             $state = EEM_State::instance()->get_one_by_ID($STA_ID);
673 673
             if ($state instanceof EE_State) {
674 674
                 $STA_abbrev = $state->abbrev();
675 675
             }
676 676
         }
677
-        if (! $STA_abbrev) {
677
+        if ( ! $STA_abbrev) {
678 678
             EE_Error::add_error(
679 679
                 esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'),
680 680
                 __FILE__,
@@ -686,7 +686,7 @@  discard block
 block discarded – undo
686 686
         $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
687 687
             'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
688 688
         );
689
-        $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true);
689
+        $persistent_admin_notice_manager->dismissNotice($CNT_ISO.'-'.$STA_abbrev, true, true);
690 690
     }
691 691
 
692 692
 
@@ -712,16 +712,16 @@  discard block
 block discarded – undo
712 712
             && $question->type() === EEM_Question::QST_type_state
713 713
         ) {
714 714
             $STA_ID = $answer->value();
715
-            if (! empty($STA_ID)) {
715
+            if ( ! empty($STA_ID)) {
716 716
                 $state = EEM_State::instance()->get_one_by_ID($STA_ID);
717 717
                 if ($state instanceof EE_State) {
718 718
                     $country = $state->country();
719 719
                     if ($country instanceof EE_Country) {
720
-                        if (! isset($state_options[ $country->name() ])) {
721
-                            $state_options[ $country->name() ] = [];
720
+                        if ( ! isset($state_options[$country->name()])) {
721
+                            $state_options[$country->name()] = [];
722 722
                         }
723
-                        if (! isset($state_options[ $country->name() ][ $STA_ID ])) {
724
-                            $state_options[ $country->name() ][ $STA_ID ] = $state->name();
723
+                        if ( ! isset($state_options[$country->name()][$STA_ID])) {
724
+                            $state_options[$country->name()][$STA_ID] = $state->name();
725 725
                         }
726 726
                     }
727 727
                 }
@@ -754,11 +754,11 @@  discard block
 block discarded – undo
754 754
                === EEM_Question::QST_type_country
755 755
         ) {
756 756
             $CNT_ISO = $answer->value();
757
-            if (! empty($CNT_ISO)) {
757
+            if ( ! empty($CNT_ISO)) {
758 758
                 $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO);
759 759
                 if ($country instanceof EE_Country) {
760
-                    if (! isset($country_options[ $CNT_ISO ])) {
761
-                        $country_options[ $CNT_ISO ] = $country->name();
760
+                    if ( ! isset($country_options[$CNT_ISO])) {
761
+                        $country_options[$CNT_ISO] = $country->name();
762 762
                     }
763 763
                 }
764 764
             }
@@ -781,7 +781,7 @@  discard block
 block discarded – undo
781 781
                 $new_state instanceof EE_State
782 782
                 && $new_state->country() instanceof EE_Country
783 783
             ) {
784
-                $state_options[ $new_state->country()->name() ][ $new_state->ID() ] = $new_state->name();
784
+                $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name();
785 785
             }
786 786
         }
787 787
         return $state_options;
@@ -820,7 +820,7 @@  discard block
 block discarded – undo
820 820
                 $new_state instanceof EE_State
821 821
                 && $new_state->country() instanceof EE_Country
822 822
             ) {
823
-                $country_options[ $new_state->country()->ID() ] = $new_state->country()->name();
823
+                $country_options[$new_state->country()->ID()] = $new_state->country()->name();
824 824
             }
825 825
         }
826 826
         return $country_options;
Please login to merge, or discard this patch.
form_sections/strategies/layout/EE_Div_Per_Section_Layout.strategy.php 2 patches
Indentation   +162 added lines, -162 removed lines patch added patch discarded remove patch
@@ -12,166 +12,166 @@
 block discarded – undo
12 12
 class EE_Div_Per_Section_Layout extends EE_Form_Section_Layout_Base
13 13
 {
14 14
 
15
-    /**
16
-     * opening div tag for a form
17
-     *
18
-     * @return string
19
-     */
20
-    public function layout_form_begin()
21
-    {
22
-        return EEH_HTML::div(
23
-            '',
24
-            $this->_form_section->html_id(),
25
-            $this->_form_section->html_class(),
26
-            $this->_form_section->html_style()
27
-        );
28
-    }
29
-
30
-
31
-
32
-    /**
33
-     * Lays out the row for the input, including label and errors
34
-     *
35
-     * @param EE_Form_Input_Base $input
36
-     * @return string
37
-     * @throws \EE_Error
38
-     */
39
-    public function layout_input($input)
40
-    {
41
-        $html = '';
42
-        // set something unique for the id
43
-        $html_id = (string) $input->html_id() !== ''
44
-            ? (string) $input->html_id()
45
-            : spl_object_hash($input);
46
-        // and add a generic input type class
47
-        $html_class = $this->processHtmlClasses(
48
-            sanitize_key(str_replace('_', '-', get_class($input))),
49
-            '-dv'
50
-        );
51
-        if ($input instanceof EE_Hidden_Input) {
52
-            $html .= EEH_HTML::nl() . $input->get_html_for_input();
53
-        } elseif ($input instanceof EE_Submit_Input) {
54
-            $input_class = $this->processHtmlClasses($input->html_class(), '-submit-dv');
55
-            $html .= EEH_HTML::div(
56
-                $input->get_html_for_input(),
57
-                $html_id . '-submit-dv',
58
-                "$input_class $html_class"
59
-            );
60
-        } elseif ($input instanceof EE_Select_Input) {
61
-            $input_class = $this->processHtmlClasses($input->html_class(), '-input-dv');
62
-            $html .= EEH_HTML::div(
63
-                EEH_HTML::nl(1) . $input->get_html_for_label() .
64
-                EEH_HTML::nl() . $input->get_html_for_errors() .
65
-                EEH_HTML::nl() . $input->get_html_for_input() .
66
-                EEH_HTML::nl() . $input->get_html_for_help(),
67
-                $html_id . '-input-dv',
68
-                "$input_class $html_class"
69
-            );
70
-        } elseif ($input instanceof EE_Form_Input_With_Options_Base) {
71
-            $input_class = $this->processHtmlClasses($input->html_class(), '-input-dv');
72
-            $html .= EEH_HTML::div(
73
-                EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) .
74
-                EEH_HTML::nl() . $input->get_html_for_errors() .
75
-                EEH_HTML::nl() . $input->get_html_for_input() .
76
-                EEH_HTML::nl() . $input->get_html_for_help(),
77
-                $html_id . '-input-dv',
78
-                "$input_class $html_class"
79
-            );
80
-        } else {
81
-            $input_class = $this->processHtmlClasses($input->html_class(), '-input-dv');
82
-            $html .= EEH_HTML::div(
83
-                EEH_HTML::nl(1) . $input->get_html_for_label() .
84
-                EEH_HTML::nl() . $input->get_html_for_errors() .
85
-                EEH_HTML::nl() . $input->get_html_for_input() .
86
-                EEH_HTML::nl() . $input->get_html_for_help(),
87
-                $html_id . '-input-dv',
88
-                "$input_class $html_class"
89
-            );
90
-        }
91
-        return $html;
92
-    }
93
-
94
-
95
-    /**
96
-     * appends one or more css classes in a string with the provided suffix
97
-     *
98
-     * @param array|string $classes
99
-     * @param string $suffix
100
-     * @return string
101
-     * @since $VID:$
102
-     */
103
-    private function processHtmlClasses($classes, string $suffix): string
104
-    {
105
-        $html_classes = [];
106
-        $classes = is_string($classes) ? explode(' ', $classes) : $classes;
107
-        $classes = (array) $classes;
108
-        foreach ($classes as $class) {
109
-            // don't append suffix if class already has "-js" suffix
110
-            $html_classes[] = strpos($class, '-js') !== strlen($class) - 3
111
-                ? "$class$suffix"
112
-                : $class;
113
-        }
114
-        return implode(' ', $html_classes);
115
-    }
116
-
117
-
118
-
119
-    /**
120
-     *
121
-     * _display_label_for_option_type_question
122
-     * Gets the HTML for the 'label', which is just text for this (because labels
123
-     * should be for each input)
124
-     *
125
-     * @param EE_Form_Input_With_Options_Base $input
126
-     * @return string
127
-     */
128
-    protected function _display_label_for_option_type_question(EE_Form_Input_With_Options_Base $input)
129
-    {
130
-        if ($input->display_html_label_text()) {
131
-            $html_label_text = $input->html_label_text();
132
-            $label_html = EEH_HTML::div(
133
-                $input->required()
134
-                    ? $html_label_text . EEH_HTML::span('*', '', 'ee-asterisk')
135
-                    : $html_label_text,
136
-                $input->html_label_id(),
137
-                $input->required()
138
-                    ? 'ee-required-label ' . $input->html_label_class()
139
-                    : $input->html_label_class(),
140
-                $input->html_label_style(),
141
-                $input->other_html_attributes()
142
-            );
143
-            // if no content was provided to EEH_HTML::div() above (ie: an empty label),
144
-            // then we need to close the div manually
145
-            if (empty($html_label_text)) {
146
-                $label_html .= EEH_HTML::divx($input->html_label_id(), $input->html_label_class());
147
-            }
148
-            return $label_html;
149
-        }
150
-        return '';
151
-    }
152
-
153
-
154
-
155
-    /**
156
-     * Lays out a row for the subsection
157
-     *
158
-     * @param EE_Form_Section_Proper $form_section
159
-     * @return string
160
-     */
161
-    public function layout_subsection($form_section)
162
-    {
163
-        return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1);
164
-    }
165
-
166
-
167
-
168
-    /**
169
-     * closing div tag for a form
170
-     *
171
-     * @return string
172
-     */
173
-    public function layout_form_end()
174
-    {
175
-        return EEH_HTML::divx($this->_form_section->html_id(), $this->_form_section->html_class());
176
-    }
15
+	/**
16
+	 * opening div tag for a form
17
+	 *
18
+	 * @return string
19
+	 */
20
+	public function layout_form_begin()
21
+	{
22
+		return EEH_HTML::div(
23
+			'',
24
+			$this->_form_section->html_id(),
25
+			$this->_form_section->html_class(),
26
+			$this->_form_section->html_style()
27
+		);
28
+	}
29
+
30
+
31
+
32
+	/**
33
+	 * Lays out the row for the input, including label and errors
34
+	 *
35
+	 * @param EE_Form_Input_Base $input
36
+	 * @return string
37
+	 * @throws \EE_Error
38
+	 */
39
+	public function layout_input($input)
40
+	{
41
+		$html = '';
42
+		// set something unique for the id
43
+		$html_id = (string) $input->html_id() !== ''
44
+			? (string) $input->html_id()
45
+			: spl_object_hash($input);
46
+		// and add a generic input type class
47
+		$html_class = $this->processHtmlClasses(
48
+			sanitize_key(str_replace('_', '-', get_class($input))),
49
+			'-dv'
50
+		);
51
+		if ($input instanceof EE_Hidden_Input) {
52
+			$html .= EEH_HTML::nl() . $input->get_html_for_input();
53
+		} elseif ($input instanceof EE_Submit_Input) {
54
+			$input_class = $this->processHtmlClasses($input->html_class(), '-submit-dv');
55
+			$html .= EEH_HTML::div(
56
+				$input->get_html_for_input(),
57
+				$html_id . '-submit-dv',
58
+				"$input_class $html_class"
59
+			);
60
+		} elseif ($input instanceof EE_Select_Input) {
61
+			$input_class = $this->processHtmlClasses($input->html_class(), '-input-dv');
62
+			$html .= EEH_HTML::div(
63
+				EEH_HTML::nl(1) . $input->get_html_for_label() .
64
+				EEH_HTML::nl() . $input->get_html_for_errors() .
65
+				EEH_HTML::nl() . $input->get_html_for_input() .
66
+				EEH_HTML::nl() . $input->get_html_for_help(),
67
+				$html_id . '-input-dv',
68
+				"$input_class $html_class"
69
+			);
70
+		} elseif ($input instanceof EE_Form_Input_With_Options_Base) {
71
+			$input_class = $this->processHtmlClasses($input->html_class(), '-input-dv');
72
+			$html .= EEH_HTML::div(
73
+				EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) .
74
+				EEH_HTML::nl() . $input->get_html_for_errors() .
75
+				EEH_HTML::nl() . $input->get_html_for_input() .
76
+				EEH_HTML::nl() . $input->get_html_for_help(),
77
+				$html_id . '-input-dv',
78
+				"$input_class $html_class"
79
+			);
80
+		} else {
81
+			$input_class = $this->processHtmlClasses($input->html_class(), '-input-dv');
82
+			$html .= EEH_HTML::div(
83
+				EEH_HTML::nl(1) . $input->get_html_for_label() .
84
+				EEH_HTML::nl() . $input->get_html_for_errors() .
85
+				EEH_HTML::nl() . $input->get_html_for_input() .
86
+				EEH_HTML::nl() . $input->get_html_for_help(),
87
+				$html_id . '-input-dv',
88
+				"$input_class $html_class"
89
+			);
90
+		}
91
+		return $html;
92
+	}
93
+
94
+
95
+	/**
96
+	 * appends one or more css classes in a string with the provided suffix
97
+	 *
98
+	 * @param array|string $classes
99
+	 * @param string $suffix
100
+	 * @return string
101
+	 * @since $VID:$
102
+	 */
103
+	private function processHtmlClasses($classes, string $suffix): string
104
+	{
105
+		$html_classes = [];
106
+		$classes = is_string($classes) ? explode(' ', $classes) : $classes;
107
+		$classes = (array) $classes;
108
+		foreach ($classes as $class) {
109
+			// don't append suffix if class already has "-js" suffix
110
+			$html_classes[] = strpos($class, '-js') !== strlen($class) - 3
111
+				? "$class$suffix"
112
+				: $class;
113
+		}
114
+		return implode(' ', $html_classes);
115
+	}
116
+
117
+
118
+
119
+	/**
120
+	 *
121
+	 * _display_label_for_option_type_question
122
+	 * Gets the HTML for the 'label', which is just text for this (because labels
123
+	 * should be for each input)
124
+	 *
125
+	 * @param EE_Form_Input_With_Options_Base $input
126
+	 * @return string
127
+	 */
128
+	protected function _display_label_for_option_type_question(EE_Form_Input_With_Options_Base $input)
129
+	{
130
+		if ($input->display_html_label_text()) {
131
+			$html_label_text = $input->html_label_text();
132
+			$label_html = EEH_HTML::div(
133
+				$input->required()
134
+					? $html_label_text . EEH_HTML::span('*', '', 'ee-asterisk')
135
+					: $html_label_text,
136
+				$input->html_label_id(),
137
+				$input->required()
138
+					? 'ee-required-label ' . $input->html_label_class()
139
+					: $input->html_label_class(),
140
+				$input->html_label_style(),
141
+				$input->other_html_attributes()
142
+			);
143
+			// if no content was provided to EEH_HTML::div() above (ie: an empty label),
144
+			// then we need to close the div manually
145
+			if (empty($html_label_text)) {
146
+				$label_html .= EEH_HTML::divx($input->html_label_id(), $input->html_label_class());
147
+			}
148
+			return $label_html;
149
+		}
150
+		return '';
151
+	}
152
+
153
+
154
+
155
+	/**
156
+	 * Lays out a row for the subsection
157
+	 *
158
+	 * @param EE_Form_Section_Proper $form_section
159
+	 * @return string
160
+	 */
161
+	public function layout_subsection($form_section)
162
+	{
163
+		return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1);
164
+	}
165
+
166
+
167
+
168
+	/**
169
+	 * closing div tag for a form
170
+	 *
171
+	 * @return string
172
+	 */
173
+	public function layout_form_end()
174
+	{
175
+		return EEH_HTML::divx($this->_form_section->html_id(), $this->_form_section->html_class());
176
+	}
177 177
 }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -49,42 +49,42 @@  discard block
 block discarded – undo
49 49
             '-dv'
50 50
         );
51 51
         if ($input instanceof EE_Hidden_Input) {
52
-            $html .= EEH_HTML::nl() . $input->get_html_for_input();
52
+            $html .= EEH_HTML::nl().$input->get_html_for_input();
53 53
         } elseif ($input instanceof EE_Submit_Input) {
54 54
             $input_class = $this->processHtmlClasses($input->html_class(), '-submit-dv');
55 55
             $html .= EEH_HTML::div(
56 56
                 $input->get_html_for_input(),
57
-                $html_id . '-submit-dv',
57
+                $html_id.'-submit-dv',
58 58
                 "$input_class $html_class"
59 59
             );
60 60
         } elseif ($input instanceof EE_Select_Input) {
61 61
             $input_class = $this->processHtmlClasses($input->html_class(), '-input-dv');
62 62
             $html .= EEH_HTML::div(
63
-                EEH_HTML::nl(1) . $input->get_html_for_label() .
64
-                EEH_HTML::nl() . $input->get_html_for_errors() .
65
-                EEH_HTML::nl() . $input->get_html_for_input() .
66
-                EEH_HTML::nl() . $input->get_html_for_help(),
67
-                $html_id . '-input-dv',
63
+                EEH_HTML::nl(1).$input->get_html_for_label().
64
+                EEH_HTML::nl().$input->get_html_for_errors().
65
+                EEH_HTML::nl().$input->get_html_for_input().
66
+                EEH_HTML::nl().$input->get_html_for_help(),
67
+                $html_id.'-input-dv',
68 68
                 "$input_class $html_class"
69 69
             );
70 70
         } elseif ($input instanceof EE_Form_Input_With_Options_Base) {
71 71
             $input_class = $this->processHtmlClasses($input->html_class(), '-input-dv');
72 72
             $html .= EEH_HTML::div(
73
-                EEH_HTML::nl() . $this->_display_label_for_option_type_question($input) .
74
-                EEH_HTML::nl() . $input->get_html_for_errors() .
75
-                EEH_HTML::nl() . $input->get_html_for_input() .
76
-                EEH_HTML::nl() . $input->get_html_for_help(),
77
-                $html_id . '-input-dv',
73
+                EEH_HTML::nl().$this->_display_label_for_option_type_question($input).
74
+                EEH_HTML::nl().$input->get_html_for_errors().
75
+                EEH_HTML::nl().$input->get_html_for_input().
76
+                EEH_HTML::nl().$input->get_html_for_help(),
77
+                $html_id.'-input-dv',
78 78
                 "$input_class $html_class"
79 79
             );
80 80
         } else {
81 81
             $input_class = $this->processHtmlClasses($input->html_class(), '-input-dv');
82 82
             $html .= EEH_HTML::div(
83
-                EEH_HTML::nl(1) . $input->get_html_for_label() .
84
-                EEH_HTML::nl() . $input->get_html_for_errors() .
85
-                EEH_HTML::nl() . $input->get_html_for_input() .
86
-                EEH_HTML::nl() . $input->get_html_for_help(),
87
-                $html_id . '-input-dv',
83
+                EEH_HTML::nl(1).$input->get_html_for_label().
84
+                EEH_HTML::nl().$input->get_html_for_errors().
85
+                EEH_HTML::nl().$input->get_html_for_input().
86
+                EEH_HTML::nl().$input->get_html_for_help(),
87
+                $html_id.'-input-dv',
88 88
                 "$input_class $html_class"
89 89
             );
90 90
         }
@@ -131,11 +131,11 @@  discard block
 block discarded – undo
131 131
             $html_label_text = $input->html_label_text();
132 132
             $label_html = EEH_HTML::div(
133 133
                 $input->required()
134
-                    ? $html_label_text . EEH_HTML::span('*', '', 'ee-asterisk')
134
+                    ? $html_label_text.EEH_HTML::span('*', '', 'ee-asterisk')
135 135
                     : $html_label_text,
136 136
                 $input->html_label_id(),
137 137
                 $input->required()
138
-                    ? 'ee-required-label ' . $input->html_label_class()
138
+                    ? 'ee-required-label '.$input->html_label_class()
139 139
                     : $input->html_label_class(),
140 140
                 $input->html_label_style(),
141 141
                 $input->other_html_attributes()
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
      */
161 161
     public function layout_subsection($form_section)
162 162
     {
163
-        return EEH_HTML::nl(1) . $form_section->get_html() . EEH_HTML::nl(-1);
163
+        return EEH_HTML::nl(1).$form_section->get_html().EEH_HTML::nl(-1);
164 164
     }
165 165
 
166 166
 
Please login to merge, or discard this patch.
core/helpers/EEH_HTML.helper.php 2 patches
Indentation   +891 added lines, -891 removed lines patch added patch discarded remove patch
@@ -1,905 +1,905 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
  /**
4
- *
5
- * Class EEH_HTML
6
- *
4
+  *
5
+  * Class EEH_HTML
6
+  *
7 7
   * Sometimes when writing PHP you need to generate some standard HTML,
8 8
   * but either not enough to warrant creating a template file,
9 9
   * or the amount of PHP conditionals and/or loops peppered throughout the HTML
10 10
   * just make it really ugly and difficult to read.
11 11
   * This class simply adds a bunch of methods for generating basic HTML tags.
12 12
   * Most of the methods have the same name as the HTML tag they generate, and most have the same set of parameters.
13
- *
14
- * @package         Event Espresso
15
- * @subpackage    core
16
- * @author              Brent Christensen
17
- *
18
- *
19
- */
13
+  *
14
+  * @package         Event Espresso
15
+  * @subpackage    core
16
+  * @author              Brent Christensen
17
+  *
18
+  *
19
+  */
20 20
 class EEH_HTML
21 21
 {
22 22
 
23
-    /**
24
-     *  instance of the EEH_Autoloader object
25
-     *  @var    $_instance
26
-     *  @access     private
27
-     */
28
-    private static $_instance;
29
-
30
-    /**
31
-     *  @var array  $_indent
32
-     *  @access     private
33
-     */
34
-    private static $_indent = array();
35
-
36
-
37
-
38
-    /**
39
-     *  @singleton method used to instantiate class object
40
-     *  @access public
41
-     *  @return EEH_HTML
42
-     */
43
-    public static function instance()
44
-    {
45
-        // check if class object is instantiated, and instantiated properly
46
-        if (! self::$_instance instanceof EEH_HTML) {
47
-            self::$_instance = new EEH_HTML();
48
-        }
49
-        return self::$_instance;
50
-    }
51
-
52
-
53
-
54
-    /**
55
-     *  class constructor
56
-     *
57
-     * @access    private
58
-     * @return \EEH_HTML
59
-     */
60
-    private function __construct()
61
-    {
62
-        // set some initial formatting for table indentation
63
-        EEH_HTML::$_indent = array(
64
-            'table'     => 0,
65
-            'thead' => 1,
66
-            'tbody' => 1,
67
-            'tr'    => 2,
68
-            'th'    => 3,
69
-            'td'    => 3,
70
-            'div'   => 0,
71
-            'h1'    => 0,
72
-            'h2'    => 0,
73
-            'h3'    => 0,
74
-            'h4'    => 0,
75
-            'h5'    => 0,
76
-            'h6'    => 0,
77
-            'p'     => 0,
78
-            'ul'    => 0,
79
-            'li'    => 1
80
-        );
81
-    }
82
-
83
-
84
-
85
-    /**
86
-     * Generates an opening HTML <XX> tag and adds any passed attributes
87
-     * if passed content, it will also add that, as well as the closing </XX> tag
88
-     *
89
-     * @access protected
90
-     * @param string $tag
91
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
92
-     * @param string $id - html id attribute
93
-     * @param string $class - html class attribute
94
-     * @param string $style - html style attribute for applying inline styles
95
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
96
-     * @param bool   $force_close
97
-     * @return string
98
-     */
99
-    protected static function _open_tag(
100
-        $tag = 'div',
101
-        $content = '',
102
-        $id = '',
103
-        $class = '',
104
-        $style = '',
105
-        $other_attributes = '',
106
-        $force_close = false
107
-    ) {
108
-        $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
109
-        $attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
110
-        $attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
111
-        $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
112
-        $html = EEH_HTML::nl(0, $tag) . '<' . $tag . $attributes . '>';
113
-        $html .= ! empty($content) ? EEH_HTML::nl(1, $tag) . $content : '';
114
-        $indent = ! empty($content) || $force_close ? true : false;
115
-        $html .= ! empty($content) || $force_close ? EEH_HTML::_close_tag($tag, $id, $class, $indent) : '';
116
-        return $html;
117
-    }
118
-
119
-
120
-
121
-    /**
122
-     * Generates HTML closing </XX> tag - if passed the id or class attribute
123
-     * used for the opening tag, will append a comment
124
-     *
23
+	/**
24
+	 *  instance of the EEH_Autoloader object
25
+	 *  @var    $_instance
26
+	 *  @access     private
27
+	 */
28
+	private static $_instance;
29
+
30
+	/**
31
+	 *  @var array  $_indent
32
+	 *  @access     private
33
+	 */
34
+	private static $_indent = array();
35
+
36
+
37
+
38
+	/**
39
+	 *  @singleton method used to instantiate class object
40
+	 *  @access public
41
+	 *  @return EEH_HTML
42
+	 */
43
+	public static function instance()
44
+	{
45
+		// check if class object is instantiated, and instantiated properly
46
+		if (! self::$_instance instanceof EEH_HTML) {
47
+			self::$_instance = new EEH_HTML();
48
+		}
49
+		return self::$_instance;
50
+	}
51
+
52
+
53
+
54
+	/**
55
+	 *  class constructor
56
+	 *
57
+	 * @access    private
58
+	 * @return \EEH_HTML
59
+	 */
60
+	private function __construct()
61
+	{
62
+		// set some initial formatting for table indentation
63
+		EEH_HTML::$_indent = array(
64
+			'table'     => 0,
65
+			'thead' => 1,
66
+			'tbody' => 1,
67
+			'tr'    => 2,
68
+			'th'    => 3,
69
+			'td'    => 3,
70
+			'div'   => 0,
71
+			'h1'    => 0,
72
+			'h2'    => 0,
73
+			'h3'    => 0,
74
+			'h4'    => 0,
75
+			'h5'    => 0,
76
+			'h6'    => 0,
77
+			'p'     => 0,
78
+			'ul'    => 0,
79
+			'li'    => 1
80
+		);
81
+	}
82
+
83
+
84
+
85
+	/**
86
+	 * Generates an opening HTML <XX> tag and adds any passed attributes
87
+	 * if passed content, it will also add that, as well as the closing </XX> tag
88
+	 *
89
+	 * @access protected
90
+	 * @param string $tag
91
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
92
+	 * @param string $id - html id attribute
93
+	 * @param string $class - html class attribute
94
+	 * @param string $style - html style attribute for applying inline styles
95
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
96
+	 * @param bool   $force_close
97
+	 * @return string
98
+	 */
99
+	protected static function _open_tag(
100
+		$tag = 'div',
101
+		$content = '',
102
+		$id = '',
103
+		$class = '',
104
+		$style = '',
105
+		$other_attributes = '',
106
+		$force_close = false
107
+	) {
108
+		$attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
109
+		$attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
110
+		$attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
111
+		$attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
112
+		$html = EEH_HTML::nl(0, $tag) . '<' . $tag . $attributes . '>';
113
+		$html .= ! empty($content) ? EEH_HTML::nl(1, $tag) . $content : '';
114
+		$indent = ! empty($content) || $force_close ? true : false;
115
+		$html .= ! empty($content) || $force_close ? EEH_HTML::_close_tag($tag, $id, $class, $indent) : '';
116
+		return $html;
117
+	}
118
+
119
+
120
+
121
+	/**
122
+	 * Generates HTML closing </XX> tag - if passed the id or class attribute
123
+	 * used for the opening tag, will append a comment
124
+	 *
125 125
 *@access protected
126
-     * @param string $tag
127
-     * @param string $id - html id attribute
128
-     * @param string $class - html class attribute
129
-     * @param bool   $indent
130
-     * @return string
131
-     */
132
-    protected static function _close_tag($tag = 'div', $id = '', $class = '', $indent = true)
133
-    {
134
-        $comment = '';
135
-        if ($id) {
136
-            $comment = EEH_HTML::comment('close ' . $id) . EEH_HTML::nl(0, $tag);
137
-        } elseif ($class) {
138
-            $comment = EEH_HTML::comment('close ' . $class) . EEH_HTML::nl(0, $tag);
139
-        }
140
-        $html = $indent ? EEH_HTML::nl(-1, $tag) : '';
141
-        $html .= '</' . $tag . '>' . $comment;
142
-        return $html;
143
-    }
144
-
145
-
146
-
147
-    /**
148
-     *  div - generates HTML opening <div> tag and adds any passed attributes
149
-     *  to add an id use:       echo EEH_HTML::div( 'this is some content', 'footer' );
150
-     *  to add a class use:     echo EEH_HTML::div( 'this is some content', '', 'float_left' );
151
-     *  to add a both an id and a class use:    echo EEH_HTML::div( 'this is some content', 'footer', 'float_left' );
152
-     *
153
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
154
-     * @param string $id - html id attribute
155
-     * @param string $class - html class attribute
156
-     * @param string $style - html style attribute for applying inline styles
157
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
158
-     * @return string
159
-     */
160
-    public static function div($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
161
-    {
162
-        return EEH_HTML::_open_tag('div', $content, $id, $class, $style, $other_attributes);
163
-    }
164
-
165
-
166
-
167
-    /**
168
-     * Generates HTML closing </div> tag - if passed the id or class attribute used for the opening div tag, will append a comment
169
-     * usage: echo EEH_HTML::divx();
170
-     *
171
-     * @param string $id - html id attribute
172
-     * @param string $class - html class attribute
173
-     * @return string
174
-     */
175
-    public static function divx($id = '', $class = '')
176
-    {
177
-        return EEH_HTML::_close_tag('div', $id, $class);
178
-    }
179
-
180
-
181
-
182
-    /**
183
-     * Generates HTML <h1></h1> tags, inserts content, and adds any passed attributes
184
-     * usage: echo EEH_HTML::h1( 'This is a Heading' );
185
-     *
186
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
187
-     * @param string $id - html id attribute
188
-     * @param string $class - html class attribute
189
-     * @param string $style - html style attribute for applying inline styles
190
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
191
-     * @return string
192
-     */
193
-    public static function h1($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
194
-    {
195
-        return EEH_HTML::_open_tag('h1', $content, $id, $class, $style, $other_attributes, true);
196
-    }
197
-
198
-
199
-
200
-    /**
201
-     * Generates HTML <h2></h2> tags, inserts content, and adds any passed attributes
202
-     * usage: echo EEH_HTML::h2( 'This is a Heading' );
203
-     *
204
-     * @param string $content          - inserted after opening tag, and appends closing tag, otherwise tag is left open
205
-     * @param string $id               - html id attribute
206
-     * @param string $class            - html class attribute
207
-     * @param string $style            - html style attribute for applying inline styles
208
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
209
-     * @return string
210
-     */
211
-    public static function h2($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
212
-    {
213
-        return EEH_HTML::_open_tag('h2', $content, $id, $class, $style, $other_attributes, true);
214
-    }
215
-
216
-
217
-
218
-    /**
219
-     * Generates HTML <h3></h3> tags, inserts content, and adds any passed attributes
220
-     * usage: echo EEH_HTML::h3( 'This is a Heading' );
221
-     *
222
-     * @param string $content          - inserted after opening tag, and appends closing tag, otherwise tag is left open
223
-     * @param string $id               - html id attribute
224
-     * @param string $class            - html class attribute
225
-     * @param string $style            - html style attribute for applying inline styles
226
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
227
-     * @return string
228
-     */
229
-    public static function h3($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
230
-    {
231
-        return EEH_HTML::_open_tag('h3', $content, $id, $class, $style, $other_attributes, true);
232
-    }
233
-
234
-
235
-
236
-    /**
237
-     * Generates HTML <h4></h4> tags, inserts content, and adds any passed attributes
238
-     * usage: echo EEH_HTML::h4( 'This is a Heading' );
239
-     *
240
-     * @param string $content          - inserted after opening tag, and appends closing tag, otherwise tag is left open
241
-     * @param string $id               - html id attribute
242
-     * @param string $class            - html class attribute
243
-     * @param string $style            - html style attribute for applying inline styles
244
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
245
-     * @return string
246
-     */
247
-    public static function h4($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
248
-    {
249
-        return EEH_HTML::_open_tag('h4', $content, $id, $class, $style, $other_attributes, true);
250
-    }
251
-
252
-
253
-
254
-    /**
255
-     * Generates HTML <h5></h5> tags, inserts content, and adds any passed attributes
256
-     * usage: echo EEH_HTML::h5( 'This is a Heading' );
257
-     *
258
-     * @param string $content          - inserted after opening tag, and appends closing tag, otherwise tag is left open
259
-     * @param string $id               - html id attribute
260
-     * @param string $class            - html class attribute
261
-     * @param string $style            - html style attribute for applying inline styles
262
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
263
-     * @return string
264
-     */
265
-    public static function h5($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
266
-    {
267
-        return EEH_HTML::_open_tag('h5', $content, $id, $class, $style, $other_attributes, true);
268
-    }
269
-
270
-
271
-
272
-    /**
273
-     * Generates HTML <h6></h6> tags, inserts content, and adds any passed attributes
274
-     * usage: echo EEH_HTML::h6( 'This is a Heading' );
275
-     *
276
-     * @param string $content          - inserted after opening tag, and appends closing tag, otherwise tag is left open
277
-     * @param string $id               - html id attribute
278
-     * @param string $class            - html class attribute
279
-     * @param string $style            - html style attribute for applying inline styles
280
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
281
-     * @return string
282
-     */
283
-    public static function h6($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
284
-    {
285
-        return EEH_HTML::_open_tag('h6', $content, $id, $class, $style, $other_attributes, true);
286
-    }
287
-
288
-
289
-
290
-    /**
291
-     * Generates HTML <p></p> tags, inserts content, and adds any passed attributes
292
-     * usage: echo EEH_HTML::p( 'this is a paragraph' );
293
-     *
294
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
295
-     * @param string $id - html id attribute
296
-     * @param string $class - html class attribute
297
-     * @param string $style - html style attribute for applying inline styles
298
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
299
-     * @return string
300
-     */
301
-    public static function p($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
302
-    {
303
-        return EEH_HTML::_open_tag('p', $content, $id, $class, $style, $other_attributes, true);
304
-    }
305
-
306
-
307
-
308
-    /**
309
-     *  ul - generates HTML opening <ul> tag and adds any passed attributes
310
-     *  usage:      echo EEH_HTML::ul( 'my-list-id', 'my-list-class' );
311
-     *
312
-     * @param string $id - html id attribute
313
-     * @param string $class - html class attribute
314
-     * @param string $style - html style attribute for applying inline styles
315
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
316
-     * @return string
317
-     */
318
-    public static function ul($id = '', $class = '', $style = '', $other_attributes = '')
319
-    {
320
-        return EEH_HTML::_open_tag('ul', '', $id, $class, $style, $other_attributes);
321
-    }
322
-
323
-
324
-
325
-    /**
326
-     * Generates HTML closing </ul> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
327
-     * usage: echo EEH_HTML::ulx();
328
-     *
329
-     * @param string $id - html id attribute
330
-     * @param string $class - html class attribute
331
-     * @return string
332
-     */
333
-    public static function ulx($id = '', $class = '')
334
-    {
335
-        return EEH_HTML::_close_tag('ul', $id, $class);
336
-    }
337
-
338
-
339
-
340
-    /**
341
-     * Generates HTML <li> tag, inserts content, and adds any passed attributes
342
-     * if passed content, it will also add that, as well as the closing </li> tag
343
-     * usage: echo EEH_HTML::li( 'this is a line item' );
344
-     *
345
-     * @param string $id - html id attribute
346
-     * @param string $class - html class attribute
347
-     * @param string $style - html style attribute for applying inline styles
348
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
349
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
350
-     * @return string
351
-     */
352
-    public static function li($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
353
-    {
354
-        return EEH_HTML::_open_tag('li', $content, $id, $class, $style, $other_attributes);
355
-    }
356
-
357
-
358
-
359
-    /**
360
-     * Generates HTML closing </li> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
361
-     * usage: echo EEH_HTML::lix();
362
-     *
363
-     * @param string $id - html id attribute
364
-     * @param string $class - html class attribute
365
-     * @return string
366
-     */
367
-    public static function lix($id = '', $class = '')
368
-    {
369
-        return EEH_HTML::_close_tag('li', $id, $class);
370
-    }
371
-
372
-
373
-
374
-    /**
375
-     *    table - generates an HTML <table> tag and adds any passed attributes
376
-     *    usage: echo EEH_HTML::table();
377
-     *
378
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
379
-     * @param string $id - html id attribute
380
-     * @param string $class - html class attribute
381
-     * @param string $style - html style attribute for applying inline styles
382
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
383
-     * @return string
384
-     */
385
-    public static function table($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
386
-    {
387
-        return EEH_HTML::_open_tag('table', $content, $id, $class, $style, $other_attributes);
388
-    }
389
-
390
-
391
-
392
-    /**
393
-     * tablex - generates an HTML </table> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
394
-     *
395
-     * @param string $id - html id attribute
396
-     * @param string $class - html class attribute
397
-     * @return string
398
-     */
399
-    public static function tablex($id = '', $class = '')
400
-    {
401
-        return EEH_HTML::_close_tag('table', $id, $class);
402
-    }
403
-
404
-
405
-
406
-    /**
407
-     *    thead - generates an HTML <thead> tag and adds any passed attributes
408
-     *    usage: echo EEH_HTML::thead();
409
-     *
410
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
411
-     * @param string $id - html id attribute
412
-     * @param string $class - html class attribute
413
-     * @param string $style - html style attribute for applying inline styles
414
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
415
-     * @return string
416
-     */
417
-    public static function thead($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
418
-    {
419
-        return EEH_HTML::_open_tag('thead', $content, $id, $class, $style, $other_attributes);
420
-    }
421
-
422
-
423
-
424
-    /**
425
-     * theadx - generates an HTML </thead> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
426
-     *
427
-     * @param string $id - html id attribute
428
-     * @param string $class - html class attribute
429
-     * @return string
430
-     */
431
-    public static function theadx($id = '', $class = '')
432
-    {
433
-        return EEH_HTML::_close_tag('thead', $id, $class);
434
-    }
435
-
436
-
437
-
438
-    /**
439
-     *    tbody - generates an HTML <tbody> tag and adds any passed attributes
440
-     *    usage: echo EEH_HTML::tbody();
441
-     *
442
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
443
-     * @param string $id - html id attribute
444
-     * @param string $class - html class attribute
445
-     * @param string $style - html style attribute for applying inline styles
446
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
447
-     * @return string
448
-     */
449
-    public static function tbody($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
450
-    {
451
-        return EEH_HTML::_open_tag('tbody', $content, $id, $class, $style, $other_attributes);
452
-    }
453
-
454
-
455
-
456
-    /**
457
-     * tbodyx - generates an HTML </tbody> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
458
-     *
459
-     * @param string $id - html id attribute
460
-     * @param string $class - html class attribute
461
-     * @return string
462
-     */
463
-    public static function tbodyx($id = '', $class = '')
464
-    {
465
-        return EEH_HTML::_close_tag('tbody', $id, $class);
466
-    }
467
-
468
-
469
-
470
-    /**
471
-     *    tr - generates an HTML <tr> tag and adds any passed attributes
472
-     *    usage: echo EEH_HTML::tr();
473
-     *
474
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
475
-     * @param string $id - html id attribute
476
-     * @param string $class - html class attribute
477
-     * @param string $style - html style attribute for applying inline styles
478
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
479
-     * @return string
480
-     */
481
-    public static function tr($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
482
-    {
483
-        return EEH_HTML::_open_tag('tr', $content, $id, $class, $style, $other_attributes);
484
-    }
485
-
486
-
487
-
488
-    /**
489
-     * trx - generates an HTML </tr> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
490
-     *
491
-     * @param string $id - html id attribute
492
-     * @param string $class - html class attribute
493
-     * @return string
494
-     */
495
-    public static function trx($id = '', $class = '')
496
-    {
497
-        return EEH_HTML::_close_tag('tr', $id, $class);
498
-    }
499
-
500
-
501
-
502
-    /**
503
-     *    th - generates an HTML <th> tag and adds any passed attributes
504
-     *    usage: echo EEH_HTML::th();
505
-     *
506
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
507
-     * @param string $id - html id attribute
508
-     * @param string $class - html class attribute
509
-     * @param string $style - html style attribute for applying inline styles
510
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
511
-     * @return string
512
-     */
513
-    public static function th($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
514
-    {
515
-        return EEH_HTML::_open_tag('th', $content, $id, $class, $style, $other_attributes);
516
-    }
517
-
518
-
519
-
520
-    /**
521
-     * thx - generates an HTML </th> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
522
-     *
523
-     * @param string $id - html id attribute
524
-     * @param string $class - html class attribute
525
-     * @return string
526
-     */
527
-    public static function thx($id = '', $class = '')
528
-    {
529
-        return EEH_HTML::_close_tag('th', $id, $class);
530
-    }
531
-
532
-
533
-
534
-    /**
535
-     *    td - generates an HTML <td> tag and adds any passed attributes
536
-     *    usage: echo EEH_HTML::td();
537
-     *
538
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
539
-     * @param string $id - html id attribute
540
-     * @param string $class - html class attribute
541
-     * @param string $style - html style attribute for applying inline styles
542
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
543
-     * @return string
544
-     */
545
-    public static function td($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
546
-    {
547
-        return EEH_HTML::_open_tag('td', $content, $id, $class, $style, $other_attributes);
548
-    }
549
-
550
-
551
-
552
-    /**
553
-     * tdx - generates an HTML </td> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
554
-     *
555
-     * @param string $id - html id attribute
556
-     * @param string $class - html class attribute
557
-     * @return string
558
-     */
559
-    public static function tdx($id = '', $class = '')
560
-    {
561
-        return EEH_HTML::_close_tag('td', $id, $class);
562
-    }
563
-
564
-
565
-
566
-    /**
567
-     * no_row - for generating a "hidden" table row, good for embedding tables within tables
568
-     * generates a new table row with one td cell that spans however many columns you set
569
-     * removes all styles from the tr and td
570
-     *
571
-     * @param string $content
572
-     * @param int    $colspan
573
-     * @return string
574
-     */
575
-    public static function no_row($content = '', $colspan = 2)
576
-    {
577
-        return EEH_HTML::tr(
578
-            EEH_HTML::td($content, '', '', 'padding:0; border:none;', 'colspan="' . $colspan . '"'),
579
-            '',
580
-            '',
581
-            'padding:0; border:none;'
582
-        );
583
-    }
584
-
585
-
586
-
587
-    /**
588
-     * Generates HTML <a href="url">text</a> tags, inserts content, and adds any passed attributes
589
-     * usage: echo EEH_HTML::link( 'domain.com', 'this is a link' );
590
-     *
591
-     * @access public
592
-     * @param string $href URL to link to
593
-     * @param string $link_text - the text that will become "hyperlinked"
594
-     * @param string $title - html title attribute
595
-     * @param string $id - html id attribute
596
-     * @param string $class - html class attribute
597
-     * @param string $style - html style attribute for applying inline styles
598
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
599
-     * @return string
600
-     */
601
-    public static function link($href = '', $link_text = '', $title = '', $id = '', $class = '', $style = '', $other_attributes = '')
602
-    {
603
-        $link_text = ! empty($link_text) ? $link_text : $href;
604
-        $attributes = ! empty($href) ? ' href="' . $href . '"' : '';
605
-        $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
606
-        $attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
607
-        $attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
608
-        $attributes .= ! empty($title) ? ' title="' . esc_attr($title) . '"' : '';
609
-        $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
610
-        return "<a{$attributes}>{$link_text}</a>";
611
-    }
612
-
613
-
614
-
615
-    /**
616
-     * Generates HTML <button>text</button> tags, inserts content, and adds any passed attributes
617
-     * usage: echo EEH_HTML::button( 'this is a button' );
618
-     *
619
-     * @param string $btn_text - the text that will become "hyperlinked"
620
-     * @param string $class - html class attribute
621
-     * @param string $aria_label - aria-label attribute
622
-     * @param string $id - html id attribute
623
-     * @param string $style - html style attribute for applying inline styles
624
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
625
-     * @return string
626
-     */
627
-    public static function button(
628
-        $btn_text = '',
629
-        $class = '',
630
-        $aria_label = '',
631
-        $id = '',
632
-        $style = '',
633
-        $other_attributes = ''
634
-    ) {
635
-        $attributes = ! empty($aria_label) ? ' aria-label="' . $aria_label . '"' : '';
636
-        $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
637
-        $attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
638
-        $attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
639
-        $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
640
-        return "<button type='button' {$attributes}>{$btn_text}</button>";
641
-    }
642
-
643
-
644
-
645
-    /**
646
-     *    img - generates an HTML <img> tag and adds any passed attributes
647
-     *    usage: echo EEH_HTML::img();
648
-     *
649
-     * @param string $src - html src attribute ie: the path or URL to the image
650
-     * @param string $alt - html alt attribute
651
-     * @param string $id - html id attribute
652
-     * @param string $class - html class attribute
653
-     * @param string $style - html style attribute for applying inline styles
654
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
655
-     * @return string
656
-     */
657
-    public static function img($src = '', $alt = '', $id = '', $class = '', $style = '', $other_attributes = '')
658
-    {
659
-        $attributes = ! empty($src) ? ' src="' . esc_url_raw($src) . '"' : '';
660
-        $attributes .= ! empty($alt) ? ' alt="' . esc_attr($alt) . '"' : '';
661
-        $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
662
-        $attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
663
-        $attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
664
-        $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
665
-        return '<img' . $attributes  . '/>';
666
-    }
667
-
668
-
669
-
670
-    /**
671
-     * Generates HTML <label></label> tags, inserts content, and adds any passed attributes
672
-     * usage: echo EEH_HTML::span( 'this is some inline text' );
673
-     *
674
-     * @access protected
675
-     * @param string $tag
676
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
677
-     * @param string $id - html id attribute
678
-     * @param string $class - html class attribute
679
-     * @param string $style - html style attribute for applying inline styles
680
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
681
-     * @return string
682
-     */
683
-    protected static function _inline_tag($tag = 'span', $content = '', $id = '', $class = '', $style = '', $other_attributes = '')
684
-    {
685
-        $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
686
-        $attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
687
-        $attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
688
-        $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
689
-        return '<' . $tag . ' ' . $attributes . '>'  . $content  . '</' . $tag . '>';
690
-    }
691
-
692
-
693
-
694
-    /**
695
-     * Generates HTML <label></label> tags, inserts content, and adds any passed attributes
696
-     * usage: echo EEH_HTML::span( 'this is some inline text' );
697
-     *
698
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
699
-     * @param string $id - html id attribute
700
-     * @param string $class - html class attribute
701
-     * @param string $style - html style attribute for applying inline styles
702
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
703
-     * @return string
704
-     */
705
-    public static function label($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
706
-    {
707
-        return EEH_HTML::_inline_tag('label', $content, $id, $class, $style, $other_attributes);
708
-    }
709
-
710
-
711
-
712
-    /**
713
-     * Generates HTML <span></span> tags, inserts content, and adds any passed attributes
714
-     * usage: echo EEH_HTML::span( 'this is some inline text' );
715
-     *
716
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
717
-     * @param string $id - html id attribute
718
-     * @param string $class - html class attribute
719
-     * @param string $style - html style attribute for applying inline styles
720
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
721
-     * @return string
722
-     */
723
-    public static function span($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
724
-    {
725
-        return EEH_HTML::_inline_tag('span', $content, $id, $class, $style, $other_attributes);
726
-    }
727
-
728
-
729
-
730
-    /**
731
-     * Generates HTML <span></span> tags, inserts content, and adds any passed attributes
732
-     * usage: echo EEH_HTML::span( 'this is some inline text' );
733
-     *
734
-     * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
735
-     * @param string $id - html id attribute
736
-     * @param string $class - html class attribute
737
-     * @param string $style - html style attribute for applying inline styles
738
-     * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
739
-     * @return string
740
-     */
741
-    public static function strong($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
742
-    {
743
-        return EEH_HTML::_inline_tag('strong', $content, $id, $class, $style, $other_attributes);
744
-    }
745
-
746
-
747
-
748
-    /**
749
-     * Generates an html <--  comment --> tag
750
-     *  usage: echo comment( 'this is a comment' );
751
-     *
752
-     * @param string $comment
753
-     * @return string
754
-     */
755
-    public static function comment($comment = '')
756
-    {
757
-        return ! empty($comment) ? EEH_HTML::nl() . '<!-- ' . $comment . ' -->' : '';
758
-    }
759
-
760
-
761
-
762
-    /**
763
-     * br - generates a line break
764
-     *
765
-     * @param int $nmbr - the number of line breaks to return
766
-     * @return string
767
-     */
768
-    public static function br($nmbr = 1)
769
-    {
770
-        return str_repeat('<br />', $nmbr);
771
-    }
772
-
773
-
774
-
775
-    /**
776
-     * nbsp - generates non-breaking space entities based on number supplied
777
-     *
778
-     * @param int $nmbr - the number of non-breaking spaces to return
779
-     * @return string
780
-     */
781
-    public static function nbsp($nmbr = 1)
782
-    {
783
-        return str_repeat('&nbsp;', $nmbr);
784
-    }
785
-
786
-
787
-
788
-    /**
789
-     * sanitize_id
790
-     *
791
-     * functionally does the same as the wp_core function sanitize_key except it does NOT use
792
-     * strtolower and allows capitals.
793
-     *
794
-     * @param string $id
795
-     * @return string
796
-     */
797
-    public static function sanitize_id($id = '')
798
-    {
799
-        $key = str_replace(' ', '-', trim($id));
800
-        return preg_replace('/[^a-zA-Z0-9_\-]/', '', $key);
801
-    }
802
-
803
-
804
-
805
-    /**
806
-     * return a newline and tabs ("nl" stands for "new line")
807
-     *
808
-     * @param int    $indent the number of tabs to ADD to the current indent (can be negative or zero)
809
-     * @param string $tag
810
-     * @return string - newline character plus # of indents passed (can be + or -)
811
-     */
812
-    public static function nl($indent = 0, $tag = 'none')
813
-    {
814
-        $html = "\n";
815
-        EEH_HTML::indent($indent, $tag);
816
-        for ($x = 0; $x < EEH_HTML::$_indent[ $tag ]; $x++) {
817
-            $html .= "\t";
818
-        }
819
-        return $html;
820
-    }
821
-
822
-
823
-
824
-    /**
825
-     * Changes the indents used in EEH_HTML::nl. Often its convenient to change
826
-     * the indentation level without actually creating a new line
827
-     *
828
-     * @param int    $indent can be negative to decrease the indentation level
829
-     * @param string $tag
830
-     */
831
-    public static function indent($indent, $tag = 'none')
832
-    {
833
-        static $default_indentation = false;
834
-        if (! $default_indentation) {
835
-            EEH_HTML::_set_default_indentation();
836
-            $default_indentation = true;
837
-        }
838
-        if (! isset(EEH_HTML::$_indent[ $tag ])) {
839
-            EEH_HTML::$_indent[ $tag ] = 0;
840
-        }
841
-        EEH_HTML::$_indent[ $tag ] += (int) $indent;
842
-        EEH_HTML::$_indent[ $tag ] = EEH_HTML::$_indent[ $tag ] >= 0 ? EEH_HTML::$_indent[ $tag ] : 0;
843
-    }
844
-
845
-
846
-    /**
847
-     *  class _set_default_indentation
848
-     *
849
-     * @access    private
850
-     */
851
-    private static function _set_default_indentation()
852
-    {
853
-        // set some initial formatting for table indentation
854
-        EEH_HTML::$_indent = array(
855
-            'none'  => 0,
856
-            'form'  => 0,
857
-            'radio'     => 0,
858
-            'checkbox'  => 0,
859
-            'select'    => 0,
860
-            'option' => 0,
861
-            'optgroup' => 0,
862
-            'table'     => 1,
863
-            'thead' => 2,
864
-            'tbody' => 2,
865
-            'tr'    => 3,
866
-            'th'    => 4,
867
-            'td'    => 4,
868
-            'div'   => 0,
869
-            'h1'    => 0,
870
-            'h2'    => 0,
871
-            'h3'    => 0,
872
-            'h4'    => 0,
873
-            'h5'    => 0,
874
-            'h6'    => 0,
875
-            'p'     => 0,
876
-            'ul'    => 0,
877
-            'li'    => 1
878
-        );
879
-    }
880
-
881
-
882
-
883
-    /**
884
-     * Retrieves the list of tags considered "simple", that are probably safe for
885
-     * use in inputs
886
-     * @global array $allowedtags
887
-     * @return array
888
-     */
889
-    public static function get_simple_tags()
890
-    {
891
-        global $allowedtags;
892
-        $tags_we_allow = array_merge_recursive(
893
-            $allowedtags,
894
-            [
895
-                'ol' => [],
896
-                'ul' => [],
897
-                'li' => [],
898
-                'br' => [],
899
-                'p' => [],
900
-                'a' => ['target']
901
-            ]
902
-        );
903
-        return apply_filters('FHEE__EEH_HTML__get_simple_tags', $tags_we_allow);
904
-    }
126
+	 * @param string $tag
127
+	 * @param string $id - html id attribute
128
+	 * @param string $class - html class attribute
129
+	 * @param bool   $indent
130
+	 * @return string
131
+	 */
132
+	protected static function _close_tag($tag = 'div', $id = '', $class = '', $indent = true)
133
+	{
134
+		$comment = '';
135
+		if ($id) {
136
+			$comment = EEH_HTML::comment('close ' . $id) . EEH_HTML::nl(0, $tag);
137
+		} elseif ($class) {
138
+			$comment = EEH_HTML::comment('close ' . $class) . EEH_HTML::nl(0, $tag);
139
+		}
140
+		$html = $indent ? EEH_HTML::nl(-1, $tag) : '';
141
+		$html .= '</' . $tag . '>' . $comment;
142
+		return $html;
143
+	}
144
+
145
+
146
+
147
+	/**
148
+	 *  div - generates HTML opening <div> tag and adds any passed attributes
149
+	 *  to add an id use:       echo EEH_HTML::div( 'this is some content', 'footer' );
150
+	 *  to add a class use:     echo EEH_HTML::div( 'this is some content', '', 'float_left' );
151
+	 *  to add a both an id and a class use:    echo EEH_HTML::div( 'this is some content', 'footer', 'float_left' );
152
+	 *
153
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
154
+	 * @param string $id - html id attribute
155
+	 * @param string $class - html class attribute
156
+	 * @param string $style - html style attribute for applying inline styles
157
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
158
+	 * @return string
159
+	 */
160
+	public static function div($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
161
+	{
162
+		return EEH_HTML::_open_tag('div', $content, $id, $class, $style, $other_attributes);
163
+	}
164
+
165
+
166
+
167
+	/**
168
+	 * Generates HTML closing </div> tag - if passed the id or class attribute used for the opening div tag, will append a comment
169
+	 * usage: echo EEH_HTML::divx();
170
+	 *
171
+	 * @param string $id - html id attribute
172
+	 * @param string $class - html class attribute
173
+	 * @return string
174
+	 */
175
+	public static function divx($id = '', $class = '')
176
+	{
177
+		return EEH_HTML::_close_tag('div', $id, $class);
178
+	}
179
+
180
+
181
+
182
+	/**
183
+	 * Generates HTML <h1></h1> tags, inserts content, and adds any passed attributes
184
+	 * usage: echo EEH_HTML::h1( 'This is a Heading' );
185
+	 *
186
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
187
+	 * @param string $id - html id attribute
188
+	 * @param string $class - html class attribute
189
+	 * @param string $style - html style attribute for applying inline styles
190
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
191
+	 * @return string
192
+	 */
193
+	public static function h1($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
194
+	{
195
+		return EEH_HTML::_open_tag('h1', $content, $id, $class, $style, $other_attributes, true);
196
+	}
197
+
198
+
199
+
200
+	/**
201
+	 * Generates HTML <h2></h2> tags, inserts content, and adds any passed attributes
202
+	 * usage: echo EEH_HTML::h2( 'This is a Heading' );
203
+	 *
204
+	 * @param string $content          - inserted after opening tag, and appends closing tag, otherwise tag is left open
205
+	 * @param string $id               - html id attribute
206
+	 * @param string $class            - html class attribute
207
+	 * @param string $style            - html style attribute for applying inline styles
208
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
209
+	 * @return string
210
+	 */
211
+	public static function h2($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
212
+	{
213
+		return EEH_HTML::_open_tag('h2', $content, $id, $class, $style, $other_attributes, true);
214
+	}
215
+
216
+
217
+
218
+	/**
219
+	 * Generates HTML <h3></h3> tags, inserts content, and adds any passed attributes
220
+	 * usage: echo EEH_HTML::h3( 'This is a Heading' );
221
+	 *
222
+	 * @param string $content          - inserted after opening tag, and appends closing tag, otherwise tag is left open
223
+	 * @param string $id               - html id attribute
224
+	 * @param string $class            - html class attribute
225
+	 * @param string $style            - html style attribute for applying inline styles
226
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
227
+	 * @return string
228
+	 */
229
+	public static function h3($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
230
+	{
231
+		return EEH_HTML::_open_tag('h3', $content, $id, $class, $style, $other_attributes, true);
232
+	}
233
+
234
+
235
+
236
+	/**
237
+	 * Generates HTML <h4></h4> tags, inserts content, and adds any passed attributes
238
+	 * usage: echo EEH_HTML::h4( 'This is a Heading' );
239
+	 *
240
+	 * @param string $content          - inserted after opening tag, and appends closing tag, otherwise tag is left open
241
+	 * @param string $id               - html id attribute
242
+	 * @param string $class            - html class attribute
243
+	 * @param string $style            - html style attribute for applying inline styles
244
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
245
+	 * @return string
246
+	 */
247
+	public static function h4($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
248
+	{
249
+		return EEH_HTML::_open_tag('h4', $content, $id, $class, $style, $other_attributes, true);
250
+	}
251
+
252
+
253
+
254
+	/**
255
+	 * Generates HTML <h5></h5> tags, inserts content, and adds any passed attributes
256
+	 * usage: echo EEH_HTML::h5( 'This is a Heading' );
257
+	 *
258
+	 * @param string $content          - inserted after opening tag, and appends closing tag, otherwise tag is left open
259
+	 * @param string $id               - html id attribute
260
+	 * @param string $class            - html class attribute
261
+	 * @param string $style            - html style attribute for applying inline styles
262
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
263
+	 * @return string
264
+	 */
265
+	public static function h5($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
266
+	{
267
+		return EEH_HTML::_open_tag('h5', $content, $id, $class, $style, $other_attributes, true);
268
+	}
269
+
270
+
271
+
272
+	/**
273
+	 * Generates HTML <h6></h6> tags, inserts content, and adds any passed attributes
274
+	 * usage: echo EEH_HTML::h6( 'This is a Heading' );
275
+	 *
276
+	 * @param string $content          - inserted after opening tag, and appends closing tag, otherwise tag is left open
277
+	 * @param string $id               - html id attribute
278
+	 * @param string $class            - html class attribute
279
+	 * @param string $style            - html style attribute for applying inline styles
280
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
281
+	 * @return string
282
+	 */
283
+	public static function h6($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
284
+	{
285
+		return EEH_HTML::_open_tag('h6', $content, $id, $class, $style, $other_attributes, true);
286
+	}
287
+
288
+
289
+
290
+	/**
291
+	 * Generates HTML <p></p> tags, inserts content, and adds any passed attributes
292
+	 * usage: echo EEH_HTML::p( 'this is a paragraph' );
293
+	 *
294
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
295
+	 * @param string $id - html id attribute
296
+	 * @param string $class - html class attribute
297
+	 * @param string $style - html style attribute for applying inline styles
298
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
299
+	 * @return string
300
+	 */
301
+	public static function p($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
302
+	{
303
+		return EEH_HTML::_open_tag('p', $content, $id, $class, $style, $other_attributes, true);
304
+	}
305
+
306
+
307
+
308
+	/**
309
+	 *  ul - generates HTML opening <ul> tag and adds any passed attributes
310
+	 *  usage:      echo EEH_HTML::ul( 'my-list-id', 'my-list-class' );
311
+	 *
312
+	 * @param string $id - html id attribute
313
+	 * @param string $class - html class attribute
314
+	 * @param string $style - html style attribute for applying inline styles
315
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
316
+	 * @return string
317
+	 */
318
+	public static function ul($id = '', $class = '', $style = '', $other_attributes = '')
319
+	{
320
+		return EEH_HTML::_open_tag('ul', '', $id, $class, $style, $other_attributes);
321
+	}
322
+
323
+
324
+
325
+	/**
326
+	 * Generates HTML closing </ul> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
327
+	 * usage: echo EEH_HTML::ulx();
328
+	 *
329
+	 * @param string $id - html id attribute
330
+	 * @param string $class - html class attribute
331
+	 * @return string
332
+	 */
333
+	public static function ulx($id = '', $class = '')
334
+	{
335
+		return EEH_HTML::_close_tag('ul', $id, $class);
336
+	}
337
+
338
+
339
+
340
+	/**
341
+	 * Generates HTML <li> tag, inserts content, and adds any passed attributes
342
+	 * if passed content, it will also add that, as well as the closing </li> tag
343
+	 * usage: echo EEH_HTML::li( 'this is a line item' );
344
+	 *
345
+	 * @param string $id - html id attribute
346
+	 * @param string $class - html class attribute
347
+	 * @param string $style - html style attribute for applying inline styles
348
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
349
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
350
+	 * @return string
351
+	 */
352
+	public static function li($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
353
+	{
354
+		return EEH_HTML::_open_tag('li', $content, $id, $class, $style, $other_attributes);
355
+	}
356
+
357
+
358
+
359
+	/**
360
+	 * Generates HTML closing </li> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
361
+	 * usage: echo EEH_HTML::lix();
362
+	 *
363
+	 * @param string $id - html id attribute
364
+	 * @param string $class - html class attribute
365
+	 * @return string
366
+	 */
367
+	public static function lix($id = '', $class = '')
368
+	{
369
+		return EEH_HTML::_close_tag('li', $id, $class);
370
+	}
371
+
372
+
373
+
374
+	/**
375
+	 *    table - generates an HTML <table> tag and adds any passed attributes
376
+	 *    usage: echo EEH_HTML::table();
377
+	 *
378
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
379
+	 * @param string $id - html id attribute
380
+	 * @param string $class - html class attribute
381
+	 * @param string $style - html style attribute for applying inline styles
382
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
383
+	 * @return string
384
+	 */
385
+	public static function table($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
386
+	{
387
+		return EEH_HTML::_open_tag('table', $content, $id, $class, $style, $other_attributes);
388
+	}
389
+
390
+
391
+
392
+	/**
393
+	 * tablex - generates an HTML </table> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
394
+	 *
395
+	 * @param string $id - html id attribute
396
+	 * @param string $class - html class attribute
397
+	 * @return string
398
+	 */
399
+	public static function tablex($id = '', $class = '')
400
+	{
401
+		return EEH_HTML::_close_tag('table', $id, $class);
402
+	}
403
+
404
+
405
+
406
+	/**
407
+	 *    thead - generates an HTML <thead> tag and adds any passed attributes
408
+	 *    usage: echo EEH_HTML::thead();
409
+	 *
410
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
411
+	 * @param string $id - html id attribute
412
+	 * @param string $class - html class attribute
413
+	 * @param string $style - html style attribute for applying inline styles
414
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
415
+	 * @return string
416
+	 */
417
+	public static function thead($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
418
+	{
419
+		return EEH_HTML::_open_tag('thead', $content, $id, $class, $style, $other_attributes);
420
+	}
421
+
422
+
423
+
424
+	/**
425
+	 * theadx - generates an HTML </thead> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
426
+	 *
427
+	 * @param string $id - html id attribute
428
+	 * @param string $class - html class attribute
429
+	 * @return string
430
+	 */
431
+	public static function theadx($id = '', $class = '')
432
+	{
433
+		return EEH_HTML::_close_tag('thead', $id, $class);
434
+	}
435
+
436
+
437
+
438
+	/**
439
+	 *    tbody - generates an HTML <tbody> tag and adds any passed attributes
440
+	 *    usage: echo EEH_HTML::tbody();
441
+	 *
442
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
443
+	 * @param string $id - html id attribute
444
+	 * @param string $class - html class attribute
445
+	 * @param string $style - html style attribute for applying inline styles
446
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
447
+	 * @return string
448
+	 */
449
+	public static function tbody($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
450
+	{
451
+		return EEH_HTML::_open_tag('tbody', $content, $id, $class, $style, $other_attributes);
452
+	}
453
+
454
+
455
+
456
+	/**
457
+	 * tbodyx - generates an HTML </tbody> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
458
+	 *
459
+	 * @param string $id - html id attribute
460
+	 * @param string $class - html class attribute
461
+	 * @return string
462
+	 */
463
+	public static function tbodyx($id = '', $class = '')
464
+	{
465
+		return EEH_HTML::_close_tag('tbody', $id, $class);
466
+	}
467
+
468
+
469
+
470
+	/**
471
+	 *    tr - generates an HTML <tr> tag and adds any passed attributes
472
+	 *    usage: echo EEH_HTML::tr();
473
+	 *
474
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
475
+	 * @param string $id - html id attribute
476
+	 * @param string $class - html class attribute
477
+	 * @param string $style - html style attribute for applying inline styles
478
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
479
+	 * @return string
480
+	 */
481
+	public static function tr($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
482
+	{
483
+		return EEH_HTML::_open_tag('tr', $content, $id, $class, $style, $other_attributes);
484
+	}
485
+
486
+
487
+
488
+	/**
489
+	 * trx - generates an HTML </tr> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
490
+	 *
491
+	 * @param string $id - html id attribute
492
+	 * @param string $class - html class attribute
493
+	 * @return string
494
+	 */
495
+	public static function trx($id = '', $class = '')
496
+	{
497
+		return EEH_HTML::_close_tag('tr', $id, $class);
498
+	}
499
+
500
+
501
+
502
+	/**
503
+	 *    th - generates an HTML <th> tag and adds any passed attributes
504
+	 *    usage: echo EEH_HTML::th();
505
+	 *
506
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
507
+	 * @param string $id - html id attribute
508
+	 * @param string $class - html class attribute
509
+	 * @param string $style - html style attribute for applying inline styles
510
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
511
+	 * @return string
512
+	 */
513
+	public static function th($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
514
+	{
515
+		return EEH_HTML::_open_tag('th', $content, $id, $class, $style, $other_attributes);
516
+	}
517
+
518
+
519
+
520
+	/**
521
+	 * thx - generates an HTML </th> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
522
+	 *
523
+	 * @param string $id - html id attribute
524
+	 * @param string $class - html class attribute
525
+	 * @return string
526
+	 */
527
+	public static function thx($id = '', $class = '')
528
+	{
529
+		return EEH_HTML::_close_tag('th', $id, $class);
530
+	}
531
+
532
+
533
+
534
+	/**
535
+	 *    td - generates an HTML <td> tag and adds any passed attributes
536
+	 *    usage: echo EEH_HTML::td();
537
+	 *
538
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
539
+	 * @param string $id - html id attribute
540
+	 * @param string $class - html class attribute
541
+	 * @param string $style - html style attribute for applying inline styles
542
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
543
+	 * @return string
544
+	 */
545
+	public static function td($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
546
+	{
547
+		return EEH_HTML::_open_tag('td', $content, $id, $class, $style, $other_attributes);
548
+	}
549
+
550
+
551
+
552
+	/**
553
+	 * tdx - generates an HTML </td> tag - if passed the id or class attribute used for the opening ul tag, will append a comment
554
+	 *
555
+	 * @param string $id - html id attribute
556
+	 * @param string $class - html class attribute
557
+	 * @return string
558
+	 */
559
+	public static function tdx($id = '', $class = '')
560
+	{
561
+		return EEH_HTML::_close_tag('td', $id, $class);
562
+	}
563
+
564
+
565
+
566
+	/**
567
+	 * no_row - for generating a "hidden" table row, good for embedding tables within tables
568
+	 * generates a new table row with one td cell that spans however many columns you set
569
+	 * removes all styles from the tr and td
570
+	 *
571
+	 * @param string $content
572
+	 * @param int    $colspan
573
+	 * @return string
574
+	 */
575
+	public static function no_row($content = '', $colspan = 2)
576
+	{
577
+		return EEH_HTML::tr(
578
+			EEH_HTML::td($content, '', '', 'padding:0; border:none;', 'colspan="' . $colspan . '"'),
579
+			'',
580
+			'',
581
+			'padding:0; border:none;'
582
+		);
583
+	}
584
+
585
+
586
+
587
+	/**
588
+	 * Generates HTML <a href="url">text</a> tags, inserts content, and adds any passed attributes
589
+	 * usage: echo EEH_HTML::link( 'domain.com', 'this is a link' );
590
+	 *
591
+	 * @access public
592
+	 * @param string $href URL to link to
593
+	 * @param string $link_text - the text that will become "hyperlinked"
594
+	 * @param string $title - html title attribute
595
+	 * @param string $id - html id attribute
596
+	 * @param string $class - html class attribute
597
+	 * @param string $style - html style attribute for applying inline styles
598
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
599
+	 * @return string
600
+	 */
601
+	public static function link($href = '', $link_text = '', $title = '', $id = '', $class = '', $style = '', $other_attributes = '')
602
+	{
603
+		$link_text = ! empty($link_text) ? $link_text : $href;
604
+		$attributes = ! empty($href) ? ' href="' . $href . '"' : '';
605
+		$attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
606
+		$attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
607
+		$attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
608
+		$attributes .= ! empty($title) ? ' title="' . esc_attr($title) . '"' : '';
609
+		$attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
610
+		return "<a{$attributes}>{$link_text}</a>";
611
+	}
612
+
613
+
614
+
615
+	/**
616
+	 * Generates HTML <button>text</button> tags, inserts content, and adds any passed attributes
617
+	 * usage: echo EEH_HTML::button( 'this is a button' );
618
+	 *
619
+	 * @param string $btn_text - the text that will become "hyperlinked"
620
+	 * @param string $class - html class attribute
621
+	 * @param string $aria_label - aria-label attribute
622
+	 * @param string $id - html id attribute
623
+	 * @param string $style - html style attribute for applying inline styles
624
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
625
+	 * @return string
626
+	 */
627
+	public static function button(
628
+		$btn_text = '',
629
+		$class = '',
630
+		$aria_label = '',
631
+		$id = '',
632
+		$style = '',
633
+		$other_attributes = ''
634
+	) {
635
+		$attributes = ! empty($aria_label) ? ' aria-label="' . $aria_label . '"' : '';
636
+		$attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
637
+		$attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
638
+		$attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
639
+		$attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
640
+		return "<button type='button' {$attributes}>{$btn_text}</button>";
641
+	}
642
+
643
+
644
+
645
+	/**
646
+	 *    img - generates an HTML <img> tag and adds any passed attributes
647
+	 *    usage: echo EEH_HTML::img();
648
+	 *
649
+	 * @param string $src - html src attribute ie: the path or URL to the image
650
+	 * @param string $alt - html alt attribute
651
+	 * @param string $id - html id attribute
652
+	 * @param string $class - html class attribute
653
+	 * @param string $style - html style attribute for applying inline styles
654
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
655
+	 * @return string
656
+	 */
657
+	public static function img($src = '', $alt = '', $id = '', $class = '', $style = '', $other_attributes = '')
658
+	{
659
+		$attributes = ! empty($src) ? ' src="' . esc_url_raw($src) . '"' : '';
660
+		$attributes .= ! empty($alt) ? ' alt="' . esc_attr($alt) . '"' : '';
661
+		$attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
662
+		$attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
663
+		$attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
664
+		$attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
665
+		return '<img' . $attributes  . '/>';
666
+	}
667
+
668
+
669
+
670
+	/**
671
+	 * Generates HTML <label></label> tags, inserts content, and adds any passed attributes
672
+	 * usage: echo EEH_HTML::span( 'this is some inline text' );
673
+	 *
674
+	 * @access protected
675
+	 * @param string $tag
676
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
677
+	 * @param string $id - html id attribute
678
+	 * @param string $class - html class attribute
679
+	 * @param string $style - html style attribute for applying inline styles
680
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
681
+	 * @return string
682
+	 */
683
+	protected static function _inline_tag($tag = 'span', $content = '', $id = '', $class = '', $style = '', $other_attributes = '')
684
+	{
685
+		$attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
686
+		$attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
687
+		$attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
688
+		$attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
689
+		return '<' . $tag . ' ' . $attributes . '>'  . $content  . '</' . $tag . '>';
690
+	}
691
+
692
+
693
+
694
+	/**
695
+	 * Generates HTML <label></label> tags, inserts content, and adds any passed attributes
696
+	 * usage: echo EEH_HTML::span( 'this is some inline text' );
697
+	 *
698
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
699
+	 * @param string $id - html id attribute
700
+	 * @param string $class - html class attribute
701
+	 * @param string $style - html style attribute for applying inline styles
702
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
703
+	 * @return string
704
+	 */
705
+	public static function label($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
706
+	{
707
+		return EEH_HTML::_inline_tag('label', $content, $id, $class, $style, $other_attributes);
708
+	}
709
+
710
+
711
+
712
+	/**
713
+	 * Generates HTML <span></span> tags, inserts content, and adds any passed attributes
714
+	 * usage: echo EEH_HTML::span( 'this is some inline text' );
715
+	 *
716
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
717
+	 * @param string $id - html id attribute
718
+	 * @param string $class - html class attribute
719
+	 * @param string $style - html style attribute for applying inline styles
720
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
721
+	 * @return string
722
+	 */
723
+	public static function span($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
724
+	{
725
+		return EEH_HTML::_inline_tag('span', $content, $id, $class, $style, $other_attributes);
726
+	}
727
+
728
+
729
+
730
+	/**
731
+	 * Generates HTML <span></span> tags, inserts content, and adds any passed attributes
732
+	 * usage: echo EEH_HTML::span( 'this is some inline text' );
733
+	 *
734
+	 * @param string $content - inserted after opening tag, and appends closing tag, otherwise tag is left open
735
+	 * @param string $id - html id attribute
736
+	 * @param string $class - html class attribute
737
+	 * @param string $style - html style attribute for applying inline styles
738
+	 * @param string $other_attributes - additional attributes like "colspan", inline JS, "rel" tags, etc
739
+	 * @return string
740
+	 */
741
+	public static function strong($content = '', $id = '', $class = '', $style = '', $other_attributes = '')
742
+	{
743
+		return EEH_HTML::_inline_tag('strong', $content, $id, $class, $style, $other_attributes);
744
+	}
745
+
746
+
747
+
748
+	/**
749
+	 * Generates an html <--  comment --> tag
750
+	 *  usage: echo comment( 'this is a comment' );
751
+	 *
752
+	 * @param string $comment
753
+	 * @return string
754
+	 */
755
+	public static function comment($comment = '')
756
+	{
757
+		return ! empty($comment) ? EEH_HTML::nl() . '<!-- ' . $comment . ' -->' : '';
758
+	}
759
+
760
+
761
+
762
+	/**
763
+	 * br - generates a line break
764
+	 *
765
+	 * @param int $nmbr - the number of line breaks to return
766
+	 * @return string
767
+	 */
768
+	public static function br($nmbr = 1)
769
+	{
770
+		return str_repeat('<br />', $nmbr);
771
+	}
772
+
773
+
774
+
775
+	/**
776
+	 * nbsp - generates non-breaking space entities based on number supplied
777
+	 *
778
+	 * @param int $nmbr - the number of non-breaking spaces to return
779
+	 * @return string
780
+	 */
781
+	public static function nbsp($nmbr = 1)
782
+	{
783
+		return str_repeat('&nbsp;', $nmbr);
784
+	}
785
+
786
+
787
+
788
+	/**
789
+	 * sanitize_id
790
+	 *
791
+	 * functionally does the same as the wp_core function sanitize_key except it does NOT use
792
+	 * strtolower and allows capitals.
793
+	 *
794
+	 * @param string $id
795
+	 * @return string
796
+	 */
797
+	public static function sanitize_id($id = '')
798
+	{
799
+		$key = str_replace(' ', '-', trim($id));
800
+		return preg_replace('/[^a-zA-Z0-9_\-]/', '', $key);
801
+	}
802
+
803
+
804
+
805
+	/**
806
+	 * return a newline and tabs ("nl" stands for "new line")
807
+	 *
808
+	 * @param int    $indent the number of tabs to ADD to the current indent (can be negative or zero)
809
+	 * @param string $tag
810
+	 * @return string - newline character plus # of indents passed (can be + or -)
811
+	 */
812
+	public static function nl($indent = 0, $tag = 'none')
813
+	{
814
+		$html = "\n";
815
+		EEH_HTML::indent($indent, $tag);
816
+		for ($x = 0; $x < EEH_HTML::$_indent[ $tag ]; $x++) {
817
+			$html .= "\t";
818
+		}
819
+		return $html;
820
+	}
821
+
822
+
823
+
824
+	/**
825
+	 * Changes the indents used in EEH_HTML::nl. Often its convenient to change
826
+	 * the indentation level without actually creating a new line
827
+	 *
828
+	 * @param int    $indent can be negative to decrease the indentation level
829
+	 * @param string $tag
830
+	 */
831
+	public static function indent($indent, $tag = 'none')
832
+	{
833
+		static $default_indentation = false;
834
+		if (! $default_indentation) {
835
+			EEH_HTML::_set_default_indentation();
836
+			$default_indentation = true;
837
+		}
838
+		if (! isset(EEH_HTML::$_indent[ $tag ])) {
839
+			EEH_HTML::$_indent[ $tag ] = 0;
840
+		}
841
+		EEH_HTML::$_indent[ $tag ] += (int) $indent;
842
+		EEH_HTML::$_indent[ $tag ] = EEH_HTML::$_indent[ $tag ] >= 0 ? EEH_HTML::$_indent[ $tag ] : 0;
843
+	}
844
+
845
+
846
+	/**
847
+	 *  class _set_default_indentation
848
+	 *
849
+	 * @access    private
850
+	 */
851
+	private static function _set_default_indentation()
852
+	{
853
+		// set some initial formatting for table indentation
854
+		EEH_HTML::$_indent = array(
855
+			'none'  => 0,
856
+			'form'  => 0,
857
+			'radio'     => 0,
858
+			'checkbox'  => 0,
859
+			'select'    => 0,
860
+			'option' => 0,
861
+			'optgroup' => 0,
862
+			'table'     => 1,
863
+			'thead' => 2,
864
+			'tbody' => 2,
865
+			'tr'    => 3,
866
+			'th'    => 4,
867
+			'td'    => 4,
868
+			'div'   => 0,
869
+			'h1'    => 0,
870
+			'h2'    => 0,
871
+			'h3'    => 0,
872
+			'h4'    => 0,
873
+			'h5'    => 0,
874
+			'h6'    => 0,
875
+			'p'     => 0,
876
+			'ul'    => 0,
877
+			'li'    => 1
878
+		);
879
+	}
880
+
881
+
882
+
883
+	/**
884
+	 * Retrieves the list of tags considered "simple", that are probably safe for
885
+	 * use in inputs
886
+	 * @global array $allowedtags
887
+	 * @return array
888
+	 */
889
+	public static function get_simple_tags()
890
+	{
891
+		global $allowedtags;
892
+		$tags_we_allow = array_merge_recursive(
893
+			$allowedtags,
894
+			[
895
+				'ol' => [],
896
+				'ul' => [],
897
+				'li' => [],
898
+				'br' => [],
899
+				'p' => [],
900
+				'a' => ['target']
901
+			]
902
+		);
903
+		return apply_filters('FHEE__EEH_HTML__get_simple_tags', $tags_we_allow);
904
+	}
905 905
 }
Please login to merge, or discard this patch.
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
     public static function instance()
44 44
     {
45 45
         // check if class object is instantiated, and instantiated properly
46
-        if (! self::$_instance instanceof EEH_HTML) {
46
+        if ( ! self::$_instance instanceof EEH_HTML) {
47 47
             self::$_instance = new EEH_HTML();
48 48
         }
49 49
         return self::$_instance;
@@ -105,12 +105,12 @@  discard block
 block discarded – undo
105 105
         $other_attributes = '',
106 106
         $force_close = false
107 107
     ) {
108
-        $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
109
-        $attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
110
-        $attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
111
-        $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
112
-        $html = EEH_HTML::nl(0, $tag) . '<' . $tag . $attributes . '>';
113
-        $html .= ! empty($content) ? EEH_HTML::nl(1, $tag) . $content : '';
108
+        $attributes = ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : '';
109
+        $attributes .= ! empty($class) ? ' class="'.$class.'"' : '';
110
+        $attributes .= ! empty($style) ? ' style="'.$style.'"' : '';
111
+        $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : '';
112
+        $html = EEH_HTML::nl(0, $tag).'<'.$tag.$attributes.'>';
113
+        $html .= ! empty($content) ? EEH_HTML::nl(1, $tag).$content : '';
114 114
         $indent = ! empty($content) || $force_close ? true : false;
115 115
         $html .= ! empty($content) || $force_close ? EEH_HTML::_close_tag($tag, $id, $class, $indent) : '';
116 116
         return $html;
@@ -133,12 +133,12 @@  discard block
 block discarded – undo
133 133
     {
134 134
         $comment = '';
135 135
         if ($id) {
136
-            $comment = EEH_HTML::comment('close ' . $id) . EEH_HTML::nl(0, $tag);
136
+            $comment = EEH_HTML::comment('close '.$id).EEH_HTML::nl(0, $tag);
137 137
         } elseif ($class) {
138
-            $comment = EEH_HTML::comment('close ' . $class) . EEH_HTML::nl(0, $tag);
138
+            $comment = EEH_HTML::comment('close '.$class).EEH_HTML::nl(0, $tag);
139 139
         }
140 140
         $html = $indent ? EEH_HTML::nl(-1, $tag) : '';
141
-        $html .= '</' . $tag . '>' . $comment;
141
+        $html .= '</'.$tag.'>'.$comment;
142 142
         return $html;
143 143
     }
144 144
 
@@ -575,7 +575,7 @@  discard block
 block discarded – undo
575 575
     public static function no_row($content = '', $colspan = 2)
576 576
     {
577 577
         return EEH_HTML::tr(
578
-            EEH_HTML::td($content, '', '', 'padding:0; border:none;', 'colspan="' . $colspan . '"'),
578
+            EEH_HTML::td($content, '', '', 'padding:0; border:none;', 'colspan="'.$colspan.'"'),
579 579
             '',
580 580
             '',
581 581
             'padding:0; border:none;'
@@ -601,12 +601,12 @@  discard block
 block discarded – undo
601 601
     public static function link($href = '', $link_text = '', $title = '', $id = '', $class = '', $style = '', $other_attributes = '')
602 602
     {
603 603
         $link_text = ! empty($link_text) ? $link_text : $href;
604
-        $attributes = ! empty($href) ? ' href="' . $href . '"' : '';
605
-        $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
606
-        $attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
607
-        $attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
608
-        $attributes .= ! empty($title) ? ' title="' . esc_attr($title) . '"' : '';
609
-        $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
604
+        $attributes = ! empty($href) ? ' href="'.$href.'"' : '';
605
+        $attributes .= ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : '';
606
+        $attributes .= ! empty($class) ? ' class="'.$class.'"' : '';
607
+        $attributes .= ! empty($style) ? ' style="'.$style.'"' : '';
608
+        $attributes .= ! empty($title) ? ' title="'.esc_attr($title).'"' : '';
609
+        $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : '';
610 610
         return "<a{$attributes}>{$link_text}</a>";
611 611
     }
612 612
 
@@ -632,11 +632,11 @@  discard block
 block discarded – undo
632 632
         $style = '',
633 633
         $other_attributes = ''
634 634
     ) {
635
-        $attributes = ! empty($aria_label) ? ' aria-label="' . $aria_label . '"' : '';
636
-        $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
637
-        $attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
638
-        $attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
639
-        $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
635
+        $attributes = ! empty($aria_label) ? ' aria-label="'.$aria_label.'"' : '';
636
+        $attributes .= ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : '';
637
+        $attributes .= ! empty($class) ? ' class="'.$class.'"' : '';
638
+        $attributes .= ! empty($style) ? ' style="'.$style.'"' : '';
639
+        $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : '';
640 640
         return "<button type='button' {$attributes}>{$btn_text}</button>";
641 641
     }
642 642
 
@@ -656,13 +656,13 @@  discard block
 block discarded – undo
656 656
      */
657 657
     public static function img($src = '', $alt = '', $id = '', $class = '', $style = '', $other_attributes = '')
658 658
     {
659
-        $attributes = ! empty($src) ? ' src="' . esc_url_raw($src) . '"' : '';
660
-        $attributes .= ! empty($alt) ? ' alt="' . esc_attr($alt) . '"' : '';
661
-        $attributes .= ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
662
-        $attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
663
-        $attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
664
-        $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
665
-        return '<img' . $attributes  . '/>';
659
+        $attributes = ! empty($src) ? ' src="'.esc_url_raw($src).'"' : '';
660
+        $attributes .= ! empty($alt) ? ' alt="'.esc_attr($alt).'"' : '';
661
+        $attributes .= ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : '';
662
+        $attributes .= ! empty($class) ? ' class="'.$class.'"' : '';
663
+        $attributes .= ! empty($style) ? ' style="'.$style.'"' : '';
664
+        $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : '';
665
+        return '<img'.$attributes.'/>';
666 666
     }
667 667
 
668 668
 
@@ -682,11 +682,11 @@  discard block
 block discarded – undo
682 682
      */
683 683
     protected static function _inline_tag($tag = 'span', $content = '', $id = '', $class = '', $style = '', $other_attributes = '')
684 684
     {
685
-        $attributes = ! empty($id) ? ' id="' . EEH_HTML::sanitize_id($id) . '"' : '';
686
-        $attributes .= ! empty($class) ? ' class="' . $class . '"' : '';
687
-        $attributes .= ! empty($style) ? ' style="' . $style . '"' : '';
688
-        $attributes .= ! empty($other_attributes) ? ' ' . $other_attributes : '';
689
-        return '<' . $tag . ' ' . $attributes . '>'  . $content  . '</' . $tag . '>';
685
+        $attributes = ! empty($id) ? ' id="'.EEH_HTML::sanitize_id($id).'"' : '';
686
+        $attributes .= ! empty($class) ? ' class="'.$class.'"' : '';
687
+        $attributes .= ! empty($style) ? ' style="'.$style.'"' : '';
688
+        $attributes .= ! empty($other_attributes) ? ' '.$other_attributes : '';
689
+        return '<'.$tag.' '.$attributes.'>'.$content.'</'.$tag.'>';
690 690
     }
691 691
 
692 692
 
@@ -754,7 +754,7 @@  discard block
 block discarded – undo
754 754
      */
755 755
     public static function comment($comment = '')
756 756
     {
757
-        return ! empty($comment) ? EEH_HTML::nl() . '<!-- ' . $comment . ' -->' : '';
757
+        return ! empty($comment) ? EEH_HTML::nl().'<!-- '.$comment.' -->' : '';
758 758
     }
759 759
 
760 760
 
@@ -813,7 +813,7 @@  discard block
 block discarded – undo
813 813
     {
814 814
         $html = "\n";
815 815
         EEH_HTML::indent($indent, $tag);
816
-        for ($x = 0; $x < EEH_HTML::$_indent[ $tag ]; $x++) {
816
+        for ($x = 0; $x < EEH_HTML::$_indent[$tag]; $x++) {
817 817
             $html .= "\t";
818 818
         }
819 819
         return $html;
@@ -831,15 +831,15 @@  discard block
 block discarded – undo
831 831
     public static function indent($indent, $tag = 'none')
832 832
     {
833 833
         static $default_indentation = false;
834
-        if (! $default_indentation) {
834
+        if ( ! $default_indentation) {
835 835
             EEH_HTML::_set_default_indentation();
836 836
             $default_indentation = true;
837 837
         }
838
-        if (! isset(EEH_HTML::$_indent[ $tag ])) {
839
-            EEH_HTML::$_indent[ $tag ] = 0;
838
+        if ( ! isset(EEH_HTML::$_indent[$tag])) {
839
+            EEH_HTML::$_indent[$tag] = 0;
840 840
         }
841
-        EEH_HTML::$_indent[ $tag ] += (int) $indent;
842
-        EEH_HTML::$_indent[ $tag ] = EEH_HTML::$_indent[ $tag ] >= 0 ? EEH_HTML::$_indent[ $tag ] : 0;
841
+        EEH_HTML::$_indent[$tag] += (int) $indent;
842
+        EEH_HTML::$_indent[$tag] = EEH_HTML::$_indent[$tag] >= 0 ? EEH_HTML::$_indent[$tag] : 0;
843 843
     }
844 844
 
845 845
 
Please login to merge, or discard this patch.