Completed
Branch master (de4804)
by
unknown
34:50 queued 28:45
created
core/libraries/form_sections/form_handlers/FormHandler.php 2 patches
Indentation   +613 added lines, -613 removed lines patch added patch discarded remove patch
@@ -31,617 +31,617 @@
 block discarded – undo
31 31
  */
32 32
 abstract class FormHandler implements FormHandlerInterface
33 33
 {
34
-    /**
35
-     * will add opening and closing HTML form tags as well as a submit button
36
-     */
37
-    const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit';
38
-
39
-    /**
40
-     * will add opening and closing HTML form tags but NOT a submit button
41
-     */
42
-    const ADD_FORM_TAGS_ONLY = 'add_form_tags_only';
43
-
44
-    /**
45
-     * will NOT add opening and closing HTML form tags but will add a submit button
46
-     */
47
-    const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only';
48
-
49
-    /**
50
-     * will NOT add opening and closing HTML form tags NOR a submit button
51
-     */
52
-    const DO_NOT_SETUP_FORM = 'do_not_setup_form';
53
-
54
-    /**
55
-     * if set to false, then this form has no displayable content,
56
-     * and will only be used for processing data sent passed via GET or POST
57
-     * defaults to true ( ie: form has displayable content )
58
-     */
59
-    private bool $displayable = true;
60
-
61
-    private string $form_name;
62
-
63
-    private string $admin_name;
64
-
65
-    private string $slug;
66
-
67
-    private string $submit_btn_text;
68
-
69
-    private string $form_action;
70
-
71
-    /**
72
-     * form params in key value pairs
73
-     * can be added to form action URL or as hidden inputs
74
-     */
75
-    private array $form_args = [];
76
-
77
-    /**
78
-     * value of one of the string constant above
79
-     */
80
-    private string $form_config;
81
-
82
-    private bool $form_has_errors = false;
83
-
84
-    /**
85
-     * the absolute top level form section being used on the page
86
-     */
87
-    private ?EE_Form_Section_Proper $form = null;
88
-
89
-    protected ?EE_Registry $registry = null;
90
-
91
-    // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd
92
-
93
-
94
-    /**
95
-     * Form constructor.
96
-     *
97
-     * @param string           $form_name
98
-     * @param string           $admin_name
99
-     * @param string           $slug
100
-     * @param string           $form_action
101
-     * @param string           $form_config
102
-     * @param EE_Registry|null $registry
103
-     */
104
-    public function __construct(
105
-        string $form_name,
106
-        string $admin_name,
107
-        string $slug,
108
-        string $form_action = '',
109
-        string $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
110
-        ?EE_Registry $registry = null
111
-    ) {
112
-        $this->setFormName($form_name);
113
-        $this->setAdminName($admin_name);
114
-        $this->setSlug($slug);
115
-        $this->setFormAction($form_action);
116
-        $this->setFormConfig($form_config);
117
-        $this->setSubmitBtnText(esc_html__('Submit', 'event_espresso'));
118
-        $this->registry = $registry;
119
-    }
120
-
121
-
122
-    /**
123
-     * @return array
124
-     */
125
-    public static function getFormConfigConstants(): array
126
-    {
127
-        return [
128
-            FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
129
-            FormHandler::ADD_FORM_TAGS_ONLY,
130
-            FormHandler::ADD_FORM_SUBMIT_ONLY,
131
-            FormHandler::DO_NOT_SETUP_FORM,
132
-        ];
133
-    }
134
-
135
-
136
-    /**
137
-     * @param bool $for_display
138
-     * @return EE_Form_Section_Proper|null
139
-     * @throws EE_Error
140
-     * @throws LogicException
141
-     */
142
-    public function form(bool $for_display = false): ?EE_Form_Section_Proper
143
-    {
144
-        if (! $this->formIsValid()) {
145
-            return null;
146
-        }
147
-        if ($for_display) {
148
-            $form_config = $this->formConfig();
149
-            if (
150
-                $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
151
-                || $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY
152
-            ) {
153
-                $this->appendSubmitButton();
154
-                $this->clearFormButtonFloats();
155
-            }
156
-        }
157
-        return $this->form;
158
-    }
159
-
160
-
161
-    /**
162
-     * @return bool
163
-     * @throws LogicException
164
-     */
165
-    public function formIsValid(): bool
166
-    {
167
-        if ($this->form instanceof EE_Form_Section_Proper) {
168
-            return true;
169
-        }
170
-        $form = apply_filters(
171
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object',
172
-            $this->generate(),
173
-            $this
174
-        );
175
-        if ($this->verifyForm($form)) {
176
-            $this->setForm($form);
177
-        }
178
-        return true;
179
-    }
180
-
181
-
182
-    /**
183
-     * @param EE_Form_Section_Proper|null $form
184
-     * @return bool
185
-     * @throws LogicException
186
-     */
187
-    public function verifyForm(?EE_Form_Section_Proper $form = null): bool
188
-    {
189
-        $form = $form !== null ? $form : $this->form;
190
-        if ($form instanceof EE_Form_Section_Proper) {
191
-            return true;
192
-        }
193
-        throw new LogicException(
194
-            sprintf(
195
-                esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'),
196
-                $this->form_name,
197
-                var_export($form, true)
198
-            )
199
-        );
200
-    }
201
-
202
-
203
-    /**
204
-     * @param EE_Form_Section_Proper $form
205
-     */
206
-    public function setForm(EE_Form_Section_Proper $form)
207
-    {
208
-        $this->form = $form;
209
-    }
210
-
211
-
212
-    /**
213
-     * @return bool
214
-     */
215
-    public function displayable(): bool
216
-    {
217
-        return $this->displayable;
218
-    }
219
-
220
-
221
-    /**
222
-     * @param bool|int|string $displayable
223
-     */
224
-    public function setDisplayable($displayable = false)
225
-    {
226
-        $this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN);
227
-    }
228
-
229
-
230
-    /**
231
-     * a public name for the form that can be displayed on the frontend of a site
232
-     *
233
-     * @return string
234
-     */
235
-    public function formName(): string
236
-    {
237
-        return $this->form_name;
238
-    }
239
-
240
-
241
-    /**
242
-     * @param string $form_name
243
-     * @throws InvalidDataTypeException
244
-     */
245
-    public function setFormName(string $form_name)
246
-    {
247
-        $this->form_name = $form_name;
248
-    }
249
-
250
-
251
-    /**
252
-     * a public name for the form that can be displayed, but only in the admin
253
-     *
254
-     * @return string
255
-     */
256
-    public function adminName(): string
257
-    {
258
-        return $this->admin_name;
259
-    }
260
-
261
-
262
-    /**
263
-     * @param string $admin_name
264
-     * @throws InvalidDataTypeException
265
-     */
266
-    public function setAdminName($admin_name)
267
-    {
268
-        if (! is_string($admin_name)) {
269
-            throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
270
-        }
271
-        $this->admin_name = $admin_name;
272
-    }
273
-
274
-
275
-    /**
276
-     * a URL friendly string that can be used for identifying the form
277
-     *
278
-     * @return string
279
-     */
280
-    public function slug()
281
-    {
282
-        return $this->slug;
283
-    }
284
-
285
-
286
-    /**
287
-     * @param string $slug
288
-     * @throws InvalidDataTypeException
289
-     */
290
-    public function setSlug($slug)
291
-    {
292
-        if (! is_string($slug)) {
293
-            throw new InvalidDataTypeException('$slug', $slug, 'string');
294
-        }
295
-        $this->slug = $slug;
296
-    }
297
-
298
-
299
-    /**
300
-     * @return string
301
-     */
302
-    public function submitBtnText()
303
-    {
304
-        return $this->submit_btn_text;
305
-    }
306
-
307
-
308
-    /**
309
-     * @param string $submit_btn_text
310
-     * @throws InvalidDataTypeException
311
-     * @throws InvalidArgumentException
312
-     */
313
-    public function setSubmitBtnText($submit_btn_text)
314
-    {
315
-        if (! is_string($submit_btn_text)) {
316
-            throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
317
-        }
318
-        if (empty($submit_btn_text)) {
319
-            throw new InvalidArgumentException(
320
-                esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso')
321
-            );
322
-        }
323
-        $this->submit_btn_text = $submit_btn_text;
324
-    }
325
-
326
-
327
-    /**
328
-     * @return string
329
-     */
330
-    public function formAction()
331
-    {
332
-        return ! empty($this->form_args)
333
-            ? add_query_arg($this->form_args, $this->form_action)
334
-            : $this->form_action;
335
-    }
336
-
337
-
338
-    /**
339
-     * @param string $form_action
340
-     * @throws InvalidDataTypeException
341
-     */
342
-    public function setFormAction($form_action)
343
-    {
344
-        if (! is_string($form_action)) {
345
-            throw new InvalidDataTypeException('$form_action', $form_action, 'string');
346
-        }
347
-        if (empty($form_action)) {
348
-            $request = LoaderFactory::getShared(RequestInterface::class);
349
-            $form_action = $request instanceof RequestInterface
350
-                ? $request->requestUri()
351
-                : '';
352
-        }
353
-        $this->form_action = $form_action;
354
-    }
355
-
356
-
357
-    /**
358
-     * @param array $form_args
359
-     * @throws InvalidDataTypeException
360
-     * @throws InvalidArgumentException
361
-     */
362
-    public function addFormActionArgs($form_args = [])
363
-    {
364
-        if (is_object($form_args)) {
365
-            throw new InvalidDataTypeException(
366
-                '$form_args',
367
-                $form_args,
368
-                'anything other than an object was expected.'
369
-            );
370
-        }
371
-        if (empty($form_args)) {
372
-            throw new InvalidArgumentException(
373
-                esc_html__('The redirect arguments can not be an empty array.', 'event_espresso')
374
-            );
375
-        }
376
-        $this->form_args = array_merge($this->form_args, $form_args);
377
-    }
378
-
379
-
380
-    /**
381
-     * @return string
382
-     */
383
-    public function formConfig()
384
-    {
385
-        return $this->form_config;
386
-    }
387
-
388
-
389
-    /**
390
-     * @param string $form_config
391
-     * @throws DomainException
392
-     */
393
-    public function setFormConfig($form_config)
394
-    {
395
-        if (
396
-            ! in_array(
397
-                $form_config,
398
-                [
399
-                    FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
400
-                    FormHandler::ADD_FORM_TAGS_ONLY,
401
-                    FormHandler::ADD_FORM_SUBMIT_ONLY,
402
-                    FormHandler::DO_NOT_SETUP_FORM,
403
-                ],
404
-                true
405
-            )
406
-        ) {
407
-            throw new DomainException(
408
-                sprintf(
409
-                    esc_html__(
410
-                        '"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form',
411
-                        'event_espresso'
412
-                    ),
413
-                    $form_config
414
-                )
415
-            );
416
-        }
417
-        $this->form_config = $form_config;
418
-    }
419
-
420
-
421
-    /**
422
-     * called after the form is instantiated
423
-     * and used for performing any logic that needs to occur early
424
-     * before any of the other methods are called.
425
-     * returns true if everything is ok to proceed,
426
-     * and false if no further form logic should be implemented
427
-     *
428
-     * @return boolean
429
-     */
430
-    public function initialize()
431
-    {
432
-        $this->form_has_errors = EE_Error::has_error(true);
433
-        return true;
434
-    }
435
-
436
-
437
-    /**
438
-     * used for setting up css and js
439
-     *
440
-     * @return void
441
-     * @throws LogicException
442
-     * @throws EE_Error
443
-     */
444
-    public function enqueueStylesAndScripts()
445
-    {
446
-        $this->form()->enqueue_js();
447
-    }
448
-
449
-
450
-    /**
451
-     * creates and returns the actual form
452
-     *
453
-     * @return EE_Form_Section_Proper
454
-     */
455
-    abstract public function generate();
456
-
457
-
458
-    /**
459
-     * creates and returns an EE_Submit_Input labeled "Submit"
460
-     *
461
-     * @param string $text
462
-     * @return EE_Submit_Input
463
-     */
464
-    public function generateSubmitButton($text = '')
465
-    {
466
-        $text = ! empty($text) ? $text : $this->submitBtnText();
467
-        return new EE_Submit_Input(
468
-            [
469
-                'html_name'             => 'ee-form-submit-' . $this->slug(),
470
-                'html_id'               => 'ee-form-submit-' . $this->slug(),
471
-                'html_class'            => 'ee-form-submit',
472
-                'html_label'            => ' ',
473
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
474
-                'default'               => $text,
475
-            ]
476
-        );
477
-    }
478
-
479
-
480
-    /**
481
-     * calls generateSubmitButton() and appends it onto the form along with a float clearing div
482
-     *
483
-     * @param string $text
484
-     * @return void
485
-     * @throws EE_Error
486
-     */
487
-    public function appendSubmitButton($text = '')
488
-    {
489
-        if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
490
-            return;
491
-        }
492
-        $this->form->add_subsections(
493
-            [$this->slug() . '-submit-btn' => $this->generateSubmitButton($text)],
494
-            null,
495
-            false
496
-        );
497
-    }
498
-
499
-
500
-    /**
501
-     * creates and returns an EE_Submit_Input labeled "Cancel"
502
-     *
503
-     * @param string $text
504
-     * @return EE_Submit_Input
505
-     */
506
-    public function generateCancelButton($text = '')
507
-    {
508
-        $cancel_button = new EE_Submit_Input(
509
-            [
510
-                'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
511
-                'html_id'               => 'ee-cancel-form-' . $this->slug(),
512
-                'html_class'            => 'ee-cancel-form',
513
-                'html_label'            => ' ',
514
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
515
-                'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
516
-            ]
517
-        );
518
-        $cancel_button->set_button_css_attributes(false);
519
-        return $cancel_button;
520
-    }
521
-
522
-
523
-    /**
524
-     * appends a float clearing div onto end of form
525
-     *
526
-     * @return void
527
-     * @throws EE_Error
528
-     */
529
-    public function clearFormButtonFloats()
530
-    {
531
-        $this->form->add_subsections(
532
-            [
533
-                'clear-submit-btn-float' => new EE_Form_Section_HTML(
534
-                    EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
535
-                ),
536
-            ],
537
-            null,
538
-            false
539
-        );
540
-    }
541
-
542
-
543
-    /**
544
-     * takes the generated form and displays it along with ony other non-form HTML that may be required
545
-     * returns a string of HTML that can be directly echoed in a template
546
-     *
547
-     * @return string
548
-     * @throws InvalidArgumentException
549
-     * @throws InvalidInterfaceException
550
-     * @throws InvalidDataTypeException
551
-     * @throws LogicException
552
-     * @throws EE_Error
553
-     */
554
-    public function display()
555
-    {
556
-        $form_html   = apply_filters(
557
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form',
558
-            ''
559
-        );
560
-        $form_config = $this->formConfig();
561
-        if (
562
-            $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
563
-            || $form_config === FormHandler::ADD_FORM_TAGS_ONLY
564
-        ) {
565
-            $additional_props = $this->requiresMultipartEnctype()
566
-                ? ' enctype="multipart/form-data"'
567
-                : '';
568
-            $form_html        .= $this->form()->form_open(
569
-                $this->formAction(),
570
-                'POST',
571
-                $additional_props
572
-            );
573
-        }
574
-        $form_html .= $this->form(true)->get_html();
575
-        if (
576
-            $form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
577
-            || $form_config === FormHandler::ADD_FORM_TAGS_ONLY
578
-        ) {
579
-            $form_html .= $this->form()->form_close();
580
-        }
581
-        $form_html .= apply_filters(
582
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form',
583
-            ''
584
-        );
585
-        return $form_html;
586
-    }
587
-
588
-
589
-    /**
590
-     * Determines if this form needs "enctype='multipart/form-data'" or not.
591
-     *
592
-     * @return bool
593
-     * @throws EE_Error
594
-     * @since 4.9.80.p
595
-     */
596
-    public function requiresMultipartEnctype(): bool
597
-    {
598
-        foreach ($this->form()->inputs_in_subsections() as $input) {
599
-            if ($input instanceof EE_File_Input) {
600
-                return true;
601
-            }
602
-        }
603
-        return false;
604
-    }
605
-
606
-
607
-    /**
608
-     * handles processing the form submission
609
-     * returns true or false depending on whether the form was processed successfully or not
610
-     *
611
-     * @param array $submitted_form_data
612
-     * @return array
613
-     * @throws InvalidArgumentException
614
-     * @throws InvalidInterfaceException
615
-     * @throws InvalidDataTypeException
616
-     * @throws EE_Error
617
-     * @throws LogicException
618
-     * @throws InvalidFormSubmissionException
619
-     */
620
-    public function process($submitted_form_data = [])
621
-    {
622
-        $submitted_form = $this->form();
623
-        if (! $submitted_form->was_submitted($submitted_form_data)) {
624
-            throw new InvalidFormSubmissionException($this->form_name);
625
-        }
626
-        $submitted_form->receive_form_submission($submitted_form_data);
627
-        if (! $submitted_form->is_valid()) {
628
-            throw new InvalidFormSubmissionException(
629
-                $this->form_name,
630
-                sprintf(
631
-                    esc_html__(
632
-                        'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s',
633
-                        'event_espresso'
634
-                    ),
635
-                    $this->form_name,
636
-                    '<br />',
637
-                    implode('<br />', $submitted_form->get_validation_errors_accumulated())
638
-                )
639
-            );
640
-        }
641
-        return (array) apply_filters(
642
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data',
643
-            $submitted_form->valid_data(),
644
-            $this
645
-        );
646
-    }
34
+	/**
35
+	 * will add opening and closing HTML form tags as well as a submit button
36
+	 */
37
+	const ADD_FORM_TAGS_AND_SUBMIT = 'add_form_tags_and_submit';
38
+
39
+	/**
40
+	 * will add opening and closing HTML form tags but NOT a submit button
41
+	 */
42
+	const ADD_FORM_TAGS_ONLY = 'add_form_tags_only';
43
+
44
+	/**
45
+	 * will NOT add opening and closing HTML form tags but will add a submit button
46
+	 */
47
+	const ADD_FORM_SUBMIT_ONLY = 'add_form_submit_only';
48
+
49
+	/**
50
+	 * will NOT add opening and closing HTML form tags NOR a submit button
51
+	 */
52
+	const DO_NOT_SETUP_FORM = 'do_not_setup_form';
53
+
54
+	/**
55
+	 * if set to false, then this form has no displayable content,
56
+	 * and will only be used for processing data sent passed via GET or POST
57
+	 * defaults to true ( ie: form has displayable content )
58
+	 */
59
+	private bool $displayable = true;
60
+
61
+	private string $form_name;
62
+
63
+	private string $admin_name;
64
+
65
+	private string $slug;
66
+
67
+	private string $submit_btn_text;
68
+
69
+	private string $form_action;
70
+
71
+	/**
72
+	 * form params in key value pairs
73
+	 * can be added to form action URL or as hidden inputs
74
+	 */
75
+	private array $form_args = [];
76
+
77
+	/**
78
+	 * value of one of the string constant above
79
+	 */
80
+	private string $form_config;
81
+
82
+	private bool $form_has_errors = false;
83
+
84
+	/**
85
+	 * the absolute top level form section being used on the page
86
+	 */
87
+	private ?EE_Form_Section_Proper $form = null;
88
+
89
+	protected ?EE_Registry $registry = null;
90
+
91
+	// phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd
92
+
93
+
94
+	/**
95
+	 * Form constructor.
96
+	 *
97
+	 * @param string           $form_name
98
+	 * @param string           $admin_name
99
+	 * @param string           $slug
100
+	 * @param string           $form_action
101
+	 * @param string           $form_config
102
+	 * @param EE_Registry|null $registry
103
+	 */
104
+	public function __construct(
105
+		string $form_name,
106
+		string $admin_name,
107
+		string $slug,
108
+		string $form_action = '',
109
+		string $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
110
+		?EE_Registry $registry = null
111
+	) {
112
+		$this->setFormName($form_name);
113
+		$this->setAdminName($admin_name);
114
+		$this->setSlug($slug);
115
+		$this->setFormAction($form_action);
116
+		$this->setFormConfig($form_config);
117
+		$this->setSubmitBtnText(esc_html__('Submit', 'event_espresso'));
118
+		$this->registry = $registry;
119
+	}
120
+
121
+
122
+	/**
123
+	 * @return array
124
+	 */
125
+	public static function getFormConfigConstants(): array
126
+	{
127
+		return [
128
+			FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
129
+			FormHandler::ADD_FORM_TAGS_ONLY,
130
+			FormHandler::ADD_FORM_SUBMIT_ONLY,
131
+			FormHandler::DO_NOT_SETUP_FORM,
132
+		];
133
+	}
134
+
135
+
136
+	/**
137
+	 * @param bool $for_display
138
+	 * @return EE_Form_Section_Proper|null
139
+	 * @throws EE_Error
140
+	 * @throws LogicException
141
+	 */
142
+	public function form(bool $for_display = false): ?EE_Form_Section_Proper
143
+	{
144
+		if (! $this->formIsValid()) {
145
+			return null;
146
+		}
147
+		if ($for_display) {
148
+			$form_config = $this->formConfig();
149
+			if (
150
+				$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
151
+				|| $form_config === FormHandler::ADD_FORM_SUBMIT_ONLY
152
+			) {
153
+				$this->appendSubmitButton();
154
+				$this->clearFormButtonFloats();
155
+			}
156
+		}
157
+		return $this->form;
158
+	}
159
+
160
+
161
+	/**
162
+	 * @return bool
163
+	 * @throws LogicException
164
+	 */
165
+	public function formIsValid(): bool
166
+	{
167
+		if ($this->form instanceof EE_Form_Section_Proper) {
168
+			return true;
169
+		}
170
+		$form = apply_filters(
171
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__formIsValid__generated_form_object',
172
+			$this->generate(),
173
+			$this
174
+		);
175
+		if ($this->verifyForm($form)) {
176
+			$this->setForm($form);
177
+		}
178
+		return true;
179
+	}
180
+
181
+
182
+	/**
183
+	 * @param EE_Form_Section_Proper|null $form
184
+	 * @return bool
185
+	 * @throws LogicException
186
+	 */
187
+	public function verifyForm(?EE_Form_Section_Proper $form = null): bool
188
+	{
189
+		$form = $form !== null ? $form : $this->form;
190
+		if ($form instanceof EE_Form_Section_Proper) {
191
+			return true;
192
+		}
193
+		throw new LogicException(
194
+			sprintf(
195
+				esc_html__('The "%1$s" form is invalid or missing. %2$s', 'event_espresso'),
196
+				$this->form_name,
197
+				var_export($form, true)
198
+			)
199
+		);
200
+	}
201
+
202
+
203
+	/**
204
+	 * @param EE_Form_Section_Proper $form
205
+	 */
206
+	public function setForm(EE_Form_Section_Proper $form)
207
+	{
208
+		$this->form = $form;
209
+	}
210
+
211
+
212
+	/**
213
+	 * @return bool
214
+	 */
215
+	public function displayable(): bool
216
+	{
217
+		return $this->displayable;
218
+	}
219
+
220
+
221
+	/**
222
+	 * @param bool|int|string $displayable
223
+	 */
224
+	public function setDisplayable($displayable = false)
225
+	{
226
+		$this->displayable = filter_var($displayable, FILTER_VALIDATE_BOOLEAN);
227
+	}
228
+
229
+
230
+	/**
231
+	 * a public name for the form that can be displayed on the frontend of a site
232
+	 *
233
+	 * @return string
234
+	 */
235
+	public function formName(): string
236
+	{
237
+		return $this->form_name;
238
+	}
239
+
240
+
241
+	/**
242
+	 * @param string $form_name
243
+	 * @throws InvalidDataTypeException
244
+	 */
245
+	public function setFormName(string $form_name)
246
+	{
247
+		$this->form_name = $form_name;
248
+	}
249
+
250
+
251
+	/**
252
+	 * a public name for the form that can be displayed, but only in the admin
253
+	 *
254
+	 * @return string
255
+	 */
256
+	public function adminName(): string
257
+	{
258
+		return $this->admin_name;
259
+	}
260
+
261
+
262
+	/**
263
+	 * @param string $admin_name
264
+	 * @throws InvalidDataTypeException
265
+	 */
266
+	public function setAdminName($admin_name)
267
+	{
268
+		if (! is_string($admin_name)) {
269
+			throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
270
+		}
271
+		$this->admin_name = $admin_name;
272
+	}
273
+
274
+
275
+	/**
276
+	 * a URL friendly string that can be used for identifying the form
277
+	 *
278
+	 * @return string
279
+	 */
280
+	public function slug()
281
+	{
282
+		return $this->slug;
283
+	}
284
+
285
+
286
+	/**
287
+	 * @param string $slug
288
+	 * @throws InvalidDataTypeException
289
+	 */
290
+	public function setSlug($slug)
291
+	{
292
+		if (! is_string($slug)) {
293
+			throw new InvalidDataTypeException('$slug', $slug, 'string');
294
+		}
295
+		$this->slug = $slug;
296
+	}
297
+
298
+
299
+	/**
300
+	 * @return string
301
+	 */
302
+	public function submitBtnText()
303
+	{
304
+		return $this->submit_btn_text;
305
+	}
306
+
307
+
308
+	/**
309
+	 * @param string $submit_btn_text
310
+	 * @throws InvalidDataTypeException
311
+	 * @throws InvalidArgumentException
312
+	 */
313
+	public function setSubmitBtnText($submit_btn_text)
314
+	{
315
+		if (! is_string($submit_btn_text)) {
316
+			throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
317
+		}
318
+		if (empty($submit_btn_text)) {
319
+			throw new InvalidArgumentException(
320
+				esc_html__('Can not set Submit button text because an empty string was provided.', 'event_espresso')
321
+			);
322
+		}
323
+		$this->submit_btn_text = $submit_btn_text;
324
+	}
325
+
326
+
327
+	/**
328
+	 * @return string
329
+	 */
330
+	public function formAction()
331
+	{
332
+		return ! empty($this->form_args)
333
+			? add_query_arg($this->form_args, $this->form_action)
334
+			: $this->form_action;
335
+	}
336
+
337
+
338
+	/**
339
+	 * @param string $form_action
340
+	 * @throws InvalidDataTypeException
341
+	 */
342
+	public function setFormAction($form_action)
343
+	{
344
+		if (! is_string($form_action)) {
345
+			throw new InvalidDataTypeException('$form_action', $form_action, 'string');
346
+		}
347
+		if (empty($form_action)) {
348
+			$request = LoaderFactory::getShared(RequestInterface::class);
349
+			$form_action = $request instanceof RequestInterface
350
+				? $request->requestUri()
351
+				: '';
352
+		}
353
+		$this->form_action = $form_action;
354
+	}
355
+
356
+
357
+	/**
358
+	 * @param array $form_args
359
+	 * @throws InvalidDataTypeException
360
+	 * @throws InvalidArgumentException
361
+	 */
362
+	public function addFormActionArgs($form_args = [])
363
+	{
364
+		if (is_object($form_args)) {
365
+			throw new InvalidDataTypeException(
366
+				'$form_args',
367
+				$form_args,
368
+				'anything other than an object was expected.'
369
+			);
370
+		}
371
+		if (empty($form_args)) {
372
+			throw new InvalidArgumentException(
373
+				esc_html__('The redirect arguments can not be an empty array.', 'event_espresso')
374
+			);
375
+		}
376
+		$this->form_args = array_merge($this->form_args, $form_args);
377
+	}
378
+
379
+
380
+	/**
381
+	 * @return string
382
+	 */
383
+	public function formConfig()
384
+	{
385
+		return $this->form_config;
386
+	}
387
+
388
+
389
+	/**
390
+	 * @param string $form_config
391
+	 * @throws DomainException
392
+	 */
393
+	public function setFormConfig($form_config)
394
+	{
395
+		if (
396
+			! in_array(
397
+				$form_config,
398
+				[
399
+					FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
400
+					FormHandler::ADD_FORM_TAGS_ONLY,
401
+					FormHandler::ADD_FORM_SUBMIT_ONLY,
402
+					FormHandler::DO_NOT_SETUP_FORM,
403
+				],
404
+				true
405
+			)
406
+		) {
407
+			throw new DomainException(
408
+				sprintf(
409
+					esc_html__(
410
+						'"%1$s" is not a valid value for the form config. Please use one of the class constants on \EventEspresso\core\libraries\form_sections\form_handlers\Form',
411
+						'event_espresso'
412
+					),
413
+					$form_config
414
+				)
415
+			);
416
+		}
417
+		$this->form_config = $form_config;
418
+	}
419
+
420
+
421
+	/**
422
+	 * called after the form is instantiated
423
+	 * and used for performing any logic that needs to occur early
424
+	 * before any of the other methods are called.
425
+	 * returns true if everything is ok to proceed,
426
+	 * and false if no further form logic should be implemented
427
+	 *
428
+	 * @return boolean
429
+	 */
430
+	public function initialize()
431
+	{
432
+		$this->form_has_errors = EE_Error::has_error(true);
433
+		return true;
434
+	}
435
+
436
+
437
+	/**
438
+	 * used for setting up css and js
439
+	 *
440
+	 * @return void
441
+	 * @throws LogicException
442
+	 * @throws EE_Error
443
+	 */
444
+	public function enqueueStylesAndScripts()
445
+	{
446
+		$this->form()->enqueue_js();
447
+	}
448
+
449
+
450
+	/**
451
+	 * creates and returns the actual form
452
+	 *
453
+	 * @return EE_Form_Section_Proper
454
+	 */
455
+	abstract public function generate();
456
+
457
+
458
+	/**
459
+	 * creates and returns an EE_Submit_Input labeled "Submit"
460
+	 *
461
+	 * @param string $text
462
+	 * @return EE_Submit_Input
463
+	 */
464
+	public function generateSubmitButton($text = '')
465
+	{
466
+		$text = ! empty($text) ? $text : $this->submitBtnText();
467
+		return new EE_Submit_Input(
468
+			[
469
+				'html_name'             => 'ee-form-submit-' . $this->slug(),
470
+				'html_id'               => 'ee-form-submit-' . $this->slug(),
471
+				'html_class'            => 'ee-form-submit',
472
+				'html_label'            => '&nbsp;',
473
+				'other_html_attributes' => ' rel="' . $this->slug() . '"',
474
+				'default'               => $text,
475
+			]
476
+		);
477
+	}
478
+
479
+
480
+	/**
481
+	 * calls generateSubmitButton() and appends it onto the form along with a float clearing div
482
+	 *
483
+	 * @param string $text
484
+	 * @return void
485
+	 * @throws EE_Error
486
+	 */
487
+	public function appendSubmitButton($text = '')
488
+	{
489
+		if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
490
+			return;
491
+		}
492
+		$this->form->add_subsections(
493
+			[$this->slug() . '-submit-btn' => $this->generateSubmitButton($text)],
494
+			null,
495
+			false
496
+		);
497
+	}
498
+
499
+
500
+	/**
501
+	 * creates and returns an EE_Submit_Input labeled "Cancel"
502
+	 *
503
+	 * @param string $text
504
+	 * @return EE_Submit_Input
505
+	 */
506
+	public function generateCancelButton($text = '')
507
+	{
508
+		$cancel_button = new EE_Submit_Input(
509
+			[
510
+				'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
511
+				'html_id'               => 'ee-cancel-form-' . $this->slug(),
512
+				'html_class'            => 'ee-cancel-form',
513
+				'html_label'            => '&nbsp;',
514
+				'other_html_attributes' => ' rel="' . $this->slug() . '"',
515
+				'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
516
+			]
517
+		);
518
+		$cancel_button->set_button_css_attributes(false);
519
+		return $cancel_button;
520
+	}
521
+
522
+
523
+	/**
524
+	 * appends a float clearing div onto end of form
525
+	 *
526
+	 * @return void
527
+	 * @throws EE_Error
528
+	 */
529
+	public function clearFormButtonFloats()
530
+	{
531
+		$this->form->add_subsections(
532
+			[
533
+				'clear-submit-btn-float' => new EE_Form_Section_HTML(
534
+					EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
535
+				),
536
+			],
537
+			null,
538
+			false
539
+		);
540
+	}
541
+
542
+
543
+	/**
544
+	 * takes the generated form and displays it along with ony other non-form HTML that may be required
545
+	 * returns a string of HTML that can be directly echoed in a template
546
+	 *
547
+	 * @return string
548
+	 * @throws InvalidArgumentException
549
+	 * @throws InvalidInterfaceException
550
+	 * @throws InvalidDataTypeException
551
+	 * @throws LogicException
552
+	 * @throws EE_Error
553
+	 */
554
+	public function display()
555
+	{
556
+		$form_html   = apply_filters(
557
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form',
558
+			''
559
+		);
560
+		$form_config = $this->formConfig();
561
+		if (
562
+			$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
563
+			|| $form_config === FormHandler::ADD_FORM_TAGS_ONLY
564
+		) {
565
+			$additional_props = $this->requiresMultipartEnctype()
566
+				? ' enctype="multipart/form-data"'
567
+				: '';
568
+			$form_html        .= $this->form()->form_open(
569
+				$this->formAction(),
570
+				'POST',
571
+				$additional_props
572
+			);
573
+		}
574
+		$form_html .= $this->form(true)->get_html();
575
+		if (
576
+			$form_config === FormHandler::ADD_FORM_TAGS_AND_SUBMIT
577
+			|| $form_config === FormHandler::ADD_FORM_TAGS_ONLY
578
+		) {
579
+			$form_html .= $this->form()->form_close();
580
+		}
581
+		$form_html .= apply_filters(
582
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__after_form',
583
+			''
584
+		);
585
+		return $form_html;
586
+	}
587
+
588
+
589
+	/**
590
+	 * Determines if this form needs "enctype='multipart/form-data'" or not.
591
+	 *
592
+	 * @return bool
593
+	 * @throws EE_Error
594
+	 * @since 4.9.80.p
595
+	 */
596
+	public function requiresMultipartEnctype(): bool
597
+	{
598
+		foreach ($this->form()->inputs_in_subsections() as $input) {
599
+			if ($input instanceof EE_File_Input) {
600
+				return true;
601
+			}
602
+		}
603
+		return false;
604
+	}
605
+
606
+
607
+	/**
608
+	 * handles processing the form submission
609
+	 * returns true or false depending on whether the form was processed successfully or not
610
+	 *
611
+	 * @param array $submitted_form_data
612
+	 * @return array
613
+	 * @throws InvalidArgumentException
614
+	 * @throws InvalidInterfaceException
615
+	 * @throws InvalidDataTypeException
616
+	 * @throws EE_Error
617
+	 * @throws LogicException
618
+	 * @throws InvalidFormSubmissionException
619
+	 */
620
+	public function process($submitted_form_data = [])
621
+	{
622
+		$submitted_form = $this->form();
623
+		if (! $submitted_form->was_submitted($submitted_form_data)) {
624
+			throw new InvalidFormSubmissionException($this->form_name);
625
+		}
626
+		$submitted_form->receive_form_submission($submitted_form_data);
627
+		if (! $submitted_form->is_valid()) {
628
+			throw new InvalidFormSubmissionException(
629
+				$this->form_name,
630
+				sprintf(
631
+					esc_html__(
632
+						'The "%1$s" form is invalid. Please correct the following errors and resubmit: %2$s %3$s',
633
+						'event_espresso'
634
+					),
635
+					$this->form_name,
636
+					'<br />',
637
+					implode('<br />', $submitted_form->get_validation_errors_accumulated())
638
+				)
639
+			);
640
+		}
641
+		return (array) apply_filters(
642
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__process__valid_data',
643
+			$submitted_form->valid_data(),
644
+			$this
645
+		);
646
+	}
647 647
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
      */
142 142
     public function form(bool $for_display = false): ?EE_Form_Section_Proper
143 143
     {
144
-        if (! $this->formIsValid()) {
144
+        if ( ! $this->formIsValid()) {
145 145
             return null;
146 146
         }
147 147
         if ($for_display) {
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
      */
266 266
     public function setAdminName($admin_name)
267 267
     {
268
-        if (! is_string($admin_name)) {
268
+        if ( ! is_string($admin_name)) {
269 269
             throw new InvalidDataTypeException('$admin_name', $admin_name, 'string');
270 270
         }
271 271
         $this->admin_name = $admin_name;
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
      */
290 290
     public function setSlug($slug)
291 291
     {
292
-        if (! is_string($slug)) {
292
+        if ( ! is_string($slug)) {
293 293
             throw new InvalidDataTypeException('$slug', $slug, 'string');
294 294
         }
295 295
         $this->slug = $slug;
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
      */
313 313
     public function setSubmitBtnText($submit_btn_text)
314 314
     {
315
-        if (! is_string($submit_btn_text)) {
315
+        if ( ! is_string($submit_btn_text)) {
316 316
             throw new InvalidDataTypeException('$submit_btn_text', $submit_btn_text, 'string');
317 317
         }
318 318
         if (empty($submit_btn_text)) {
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
      */
342 342
     public function setFormAction($form_action)
343 343
     {
344
-        if (! is_string($form_action)) {
344
+        if ( ! is_string($form_action)) {
345 345
             throw new InvalidDataTypeException('$form_action', $form_action, 'string');
346 346
         }
347 347
         if (empty($form_action)) {
@@ -466,11 +466,11 @@  discard block
 block discarded – undo
466 466
         $text = ! empty($text) ? $text : $this->submitBtnText();
467 467
         return new EE_Submit_Input(
468 468
             [
469
-                'html_name'             => 'ee-form-submit-' . $this->slug(),
470
-                'html_id'               => 'ee-form-submit-' . $this->slug(),
469
+                'html_name'             => 'ee-form-submit-'.$this->slug(),
470
+                'html_id'               => 'ee-form-submit-'.$this->slug(),
471 471
                 'html_class'            => 'ee-form-submit',
472 472
                 'html_label'            => '&nbsp;',
473
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
473
+                'other_html_attributes' => ' rel="'.$this->slug().'"',
474 474
                 'default'               => $text,
475 475
             ]
476 476
         );
@@ -486,11 +486,11 @@  discard block
 block discarded – undo
486 486
      */
487 487
     public function appendSubmitButton($text = '')
488 488
     {
489
-        if ($this->form->subsection_exists($this->slug() . '-submit-btn')) {
489
+        if ($this->form->subsection_exists($this->slug().'-submit-btn')) {
490 490
             return;
491 491
         }
492 492
         $this->form->add_subsections(
493
-            [$this->slug() . '-submit-btn' => $this->generateSubmitButton($text)],
493
+            [$this->slug().'-submit-btn' => $this->generateSubmitButton($text)],
494 494
             null,
495 495
             false
496 496
         );
@@ -507,11 +507,11 @@  discard block
 block discarded – undo
507 507
     {
508 508
         $cancel_button = new EE_Submit_Input(
509 509
             [
510
-                'html_name'             => 'ee-form-submit-' . $this->slug(), // YES! Same name as submit !!!
511
-                'html_id'               => 'ee-cancel-form-' . $this->slug(),
510
+                'html_name'             => 'ee-form-submit-'.$this->slug(), // YES! Same name as submit !!!
511
+                'html_id'               => 'ee-cancel-form-'.$this->slug(),
512 512
                 'html_class'            => 'ee-cancel-form',
513 513
                 'html_label'            => '&nbsp;',
514
-                'other_html_attributes' => ' rel="' . $this->slug() . '"',
514
+                'other_html_attributes' => ' rel="'.$this->slug().'"',
515 515
                 'default'               => ! empty($text) ? $text : esc_html__('Cancel', 'event_espresso'),
516 516
             ]
517 517
         );
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
         $this->form->add_subsections(
532 532
             [
533 533
                 'clear-submit-btn-float' => new EE_Form_Section_HTML(
534
-                    EEH_HTML::div('', '', 'clear-float') . EEH_HTML::divx()
534
+                    EEH_HTML::div('', '', 'clear-float').EEH_HTML::divx()
535 535
                 ),
536 536
             ],
537 537
             null,
@@ -553,7 +553,7 @@  discard block
 block discarded – undo
553 553
      */
554 554
     public function display()
555 555
     {
556
-        $form_html   = apply_filters(
556
+        $form_html = apply_filters(
557 557
             'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form',
558 558
             ''
559 559
         );
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
             $additional_props = $this->requiresMultipartEnctype()
566 566
                 ? ' enctype="multipart/form-data"'
567 567
                 : '';
568
-            $form_html        .= $this->form()->form_open(
568
+            $form_html .= $this->form()->form_open(
569 569
                 $this->formAction(),
570 570
                 'POST',
571 571
                 $additional_props
@@ -620,11 +620,11 @@  discard block
 block discarded – undo
620 620
     public function process($submitted_form_data = [])
621 621
     {
622 622
         $submitted_form = $this->form();
623
-        if (! $submitted_form->was_submitted($submitted_form_data)) {
623
+        if ( ! $submitted_form->was_submitted($submitted_form_data)) {
624 624
             throw new InvalidFormSubmissionException($this->form_name);
625 625
         }
626 626
         $submitted_form->receive_form_submission($submitted_form_data);
627
-        if (! $submitted_form->is_valid()) {
627
+        if ( ! $submitted_form->is_valid()) {
628 628
             throw new InvalidFormSubmissionException(
629 629
                 $this->form_name,
630 630
                 sprintf(
Please login to merge, or discard this patch.
libraries/form_sections/payment_methods/EE_Payment_Method_Form.form.php 2 patches
Indentation   +202 added lines, -202 removed lines patch added patch discarded remove patch
@@ -6,206 +6,206 @@
 block discarded – undo
6 6
  */
7 7
 class EE_Payment_Method_Form extends EE_Model_Form_Section
8 8
 {
9
-    /**
10
-     * All the subsection inputs that correspond ot extra meta rows
11
-     * for this payment method
12
-     *
13
-     * @var EE_Form_Input_Base[]
14
-     */
15
-    protected $_extra_meta_inputs = [];
16
-
17
-    /**
18
-     * Because payment method form might DELAY part of construction, we want to remember
19
-     * what options were passed in
20
-     *
21
-     * @var array
22
-     */
23
-    protected $_options_array = [];
24
-
25
-    /**
26
-     * The payment method type for this form
27
-     *
28
-     * @var EE_PMT_Base
29
-     */
30
-    protected $_payment_method_type;
31
-
32
-
33
-    /**
34
-     * @param array $options_array
35
-     * {
36
-     *      @type string $extra_meta_inputs         should be EE_Form_Section_Validatable[] which will be _subsections
37
-     *                                              and will be saved as extra meta on the payment method object;
38
-     *      @type EE_PMT_Base $payment_method_type  the payment method type this form is for
39
-     *      @see EE_Model_Form_Section::__construct()   for more
40
-     * }
41
-     * @throws EE_Error
42
-     * @throws ReflectionException
43
-     */
44
-    public function __construct($options_array = [])
45
-    {
46
-        $this->_model         = EEM_Payment_Method::instance();
47
-        $this->_options_array = (array) apply_filters(
48
-            'FHEE__EE_Payment_Method_Form___construct__options_array',
49
-            $options_array,
50
-            $this
51
-        );
52
-        if (isset($this->_options_array['payment_method_type'])) {
53
-            $this->_payment_method_type = $this->_options_array['payment_method_type'];
54
-        }
55
-        if (isset($this->_options_array['extra_meta_inputs'])) {
56
-            $this->_extra_meta_inputs = array_merge($this->_extra_meta_inputs, $this->_options_array['extra_meta_inputs']);
57
-        }
58
-        if ($this->_extra_meta_inputs) {
59
-            $this->_subsections = array_merge($this->_subsections, $this->_extra_meta_inputs);
60
-        }
61
-        $this->_subsections['PMD_button_url'] = new EE_Admin_File_Uploader_Input(
62
-            ['html_label_text' => esc_html__('Button URL', 'event_espresso')]
63
-        );
64
-        $this->_subsections['PMD_scope']      = new EE_Checkbox_Multi_Input(
65
-            EEM_Payment_Method::instance()->scopes(),
66
-            [
67
-                'html_label_text' => $this->_model->field_settings_for('PMD_scope')->get_nicename()
68
-                                     . EEH_Template::get_help_tab_link('payment_methods_overview'),
69
-            ]
70
-        );
71
-        // set up the currency options
72
-        $this->_subsections['Currency']  = new EE_Select_Multi_Model_Input(
73
-            EEM_Currency::instance()->get_all_currencies_usable_by($this->_payment_method_type),
74
-            [
75
-                'html_label_text' => esc_html__('Currencies Supported', 'event_espresso'),
76
-                'required'        => true,
77
-            ]
78
-        );
79
-        $this->_subsections['PMD_order'] = new EE_Text_Input(
80
-            [
81
-                'html_label_text'        => esc_html__('Order', 'event_espresso'),
82
-                'html_help_text'         => esc_html__('Lowest numbers will be shown first', 'event_espresso'),
83
-                'normalization_strategy' => new EE_Int_Normalization(),
84
-                'validation_strategies'  => [
85
-                    new EE_Int_Validation_Strategy(),
86
-                ],
87
-                'default'                => 0,
88
-            ]
89
-        );
90
-        $this->_layout_strategy          = new EE_Admin_Two_Column_Layout();
91
-
92
-        parent::__construct($this->_options_array);
93
-        $debug_mode = $this->_subsections['PMD_debug_mode'] ?? null;
94
-        if ($debug_mode instanceof EE_Form_Input_Base) {
95
-            $debug_mode->set_html_help_text(
96
-                esc_html__(
97
-                    'This payment method has a Sandbox Server (also known as Testing Server, Development Server, Quality Assurance Server, etc). While in sandbox mode and using this sandbox server, real payments will not be processed.',
98
-                    'event_espresso'
99
-                )
100
-            );
101
-        }
102
-    }
103
-
104
-
105
-    /**
106
-     * Finishes construction given the parent form section and this form section's name
107
-     *
108
-     * @param EE_Form_Section_Proper $parent_form_section
109
-     * @param string                 $name
110
-     * @throws EE_Error
111
-     */
112
-    public function _construct_finalize($parent_form_section, $name)
113
-    {
114
-        if (! $this->_payment_method_type instanceof EE_PMT_Base) {
115
-            throw new EE_Error(
116
-                esc_html__(
117
-                    'Payment Method forms must have set their payment method type BEFORE calling _construct_finalize',
118
-                    'event_espresso'
119
-                )
120
-            );
121
-        }
122
-        // set the name of this form based on the payment method type
123
-        if (! $this->_name && ! $name) {
124
-            $name = str_replace(" ", "_", ucwords(str_replace("_", " ", ($this->_payment_method_type->system_name()))))
125
-                    . "_Settings_Form";
126
-        }
127
-        parent::_construct_finalize($parent_form_section, $name);
128
-    }
129
-
130
-
131
-    /**
132
-     * @param $payment_method_type
133
-     * @throws EE_Error
134
-     */
135
-    public function set_payment_method_type($payment_method_type)
136
-    {
137
-        if (! $payment_method_type instanceof EE_PMT_Base) {
138
-            throw new EE_Error(
139
-                esc_html__(
140
-                    "Payment Method forms MUST set a payment method type by using _set_payment_method_type",
141
-                    "event_espresso"
142
-                )
143
-            );
144
-        }
145
-        $this->_payment_method_type = $payment_method_type;
146
-    }
147
-
148
-
149
-    /**
150
-     * extends the model form section's save() method to also save the extra meta field values
151
-     *
152
-     * @return int ID of the payment method inserted, or true on update
153
-     * @throws EE_Error
154
-     * @throws ReflectionException
155
-     */
156
-    public function save(): int
157
-    {
158
-        $parent_save_val = parent::save();
159
-        if ($this->_model_object && $this->_model_object->ID()) {
160
-            foreach ($this->_extra_meta_inputs as $input_name => $input) {
161
-                $this->_model_object->update_extra_meta($input_name, $input->normalized_value());
162
-            }
163
-        }
164
-        return $parent_save_val;
165
-    }
166
-
167
-
168
-    /**
169
-     * Overrides parent's populate_model_obj to also populate the extra meta fields
170
-     *
171
-     * @param EE_Base_Class $model_obj
172
-     * @throws EE_Error
173
-     * @throws ReflectionException
174
-     */
175
-    public function populate_model_obj($model_obj)
176
-    {
177
-        $model_obj = $this->_model->ensure_is_obj($model_obj);
178
-        parent::populate_model_obj($model_obj);
179
-        $extra_meta = $model_obj->all_extra_meta_array();
180
-        foreach ($this->_extra_meta_inputs as $input_name => $extra_meta_input) {
181
-            if (isset($extra_meta[ $input_name ])) {
182
-                $extra_meta_input->set_default($extra_meta[ $input_name ]);
183
-            }
184
-        }
185
-    }
186
-
187
-
188
-    /**
189
-     * gets the default name of this form section if none is specified
190
-     *
191
-     * @return void
192
-     */
193
-    protected function _set_default_name_if_empty()
194
-    {
195
-        if (! $this->_name) {
196
-            $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form";
197
-            $this->_name  = $default_name;
198
-        }
199
-    }
200
-
201
-
202
-    /**
203
-     * Gets all the extra meta inputs in this form
204
-     *
205
-     * @return EE_Form_Input_Base[]
206
-     */
207
-    public function extra_meta_inputs(): array
208
-    {
209
-        return $this->_extra_meta_inputs;
210
-    }
9
+	/**
10
+	 * All the subsection inputs that correspond ot extra meta rows
11
+	 * for this payment method
12
+	 *
13
+	 * @var EE_Form_Input_Base[]
14
+	 */
15
+	protected $_extra_meta_inputs = [];
16
+
17
+	/**
18
+	 * Because payment method form might DELAY part of construction, we want to remember
19
+	 * what options were passed in
20
+	 *
21
+	 * @var array
22
+	 */
23
+	protected $_options_array = [];
24
+
25
+	/**
26
+	 * The payment method type for this form
27
+	 *
28
+	 * @var EE_PMT_Base
29
+	 */
30
+	protected $_payment_method_type;
31
+
32
+
33
+	/**
34
+	 * @param array $options_array
35
+	 * {
36
+	 *      @type string $extra_meta_inputs         should be EE_Form_Section_Validatable[] which will be _subsections
37
+	 *                                              and will be saved as extra meta on the payment method object;
38
+	 *      @type EE_PMT_Base $payment_method_type  the payment method type this form is for
39
+	 *      @see EE_Model_Form_Section::__construct()   for more
40
+	 * }
41
+	 * @throws EE_Error
42
+	 * @throws ReflectionException
43
+	 */
44
+	public function __construct($options_array = [])
45
+	{
46
+		$this->_model         = EEM_Payment_Method::instance();
47
+		$this->_options_array = (array) apply_filters(
48
+			'FHEE__EE_Payment_Method_Form___construct__options_array',
49
+			$options_array,
50
+			$this
51
+		);
52
+		if (isset($this->_options_array['payment_method_type'])) {
53
+			$this->_payment_method_type = $this->_options_array['payment_method_type'];
54
+		}
55
+		if (isset($this->_options_array['extra_meta_inputs'])) {
56
+			$this->_extra_meta_inputs = array_merge($this->_extra_meta_inputs, $this->_options_array['extra_meta_inputs']);
57
+		}
58
+		if ($this->_extra_meta_inputs) {
59
+			$this->_subsections = array_merge($this->_subsections, $this->_extra_meta_inputs);
60
+		}
61
+		$this->_subsections['PMD_button_url'] = new EE_Admin_File_Uploader_Input(
62
+			['html_label_text' => esc_html__('Button URL', 'event_espresso')]
63
+		);
64
+		$this->_subsections['PMD_scope']      = new EE_Checkbox_Multi_Input(
65
+			EEM_Payment_Method::instance()->scopes(),
66
+			[
67
+				'html_label_text' => $this->_model->field_settings_for('PMD_scope')->get_nicename()
68
+									 . EEH_Template::get_help_tab_link('payment_methods_overview'),
69
+			]
70
+		);
71
+		// set up the currency options
72
+		$this->_subsections['Currency']  = new EE_Select_Multi_Model_Input(
73
+			EEM_Currency::instance()->get_all_currencies_usable_by($this->_payment_method_type),
74
+			[
75
+				'html_label_text' => esc_html__('Currencies Supported', 'event_espresso'),
76
+				'required'        => true,
77
+			]
78
+		);
79
+		$this->_subsections['PMD_order'] = new EE_Text_Input(
80
+			[
81
+				'html_label_text'        => esc_html__('Order', 'event_espresso'),
82
+				'html_help_text'         => esc_html__('Lowest numbers will be shown first', 'event_espresso'),
83
+				'normalization_strategy' => new EE_Int_Normalization(),
84
+				'validation_strategies'  => [
85
+					new EE_Int_Validation_Strategy(),
86
+				],
87
+				'default'                => 0,
88
+			]
89
+		);
90
+		$this->_layout_strategy          = new EE_Admin_Two_Column_Layout();
91
+
92
+		parent::__construct($this->_options_array);
93
+		$debug_mode = $this->_subsections['PMD_debug_mode'] ?? null;
94
+		if ($debug_mode instanceof EE_Form_Input_Base) {
95
+			$debug_mode->set_html_help_text(
96
+				esc_html__(
97
+					'This payment method has a Sandbox Server (also known as Testing Server, Development Server, Quality Assurance Server, etc). While in sandbox mode and using this sandbox server, real payments will not be processed.',
98
+					'event_espresso'
99
+				)
100
+			);
101
+		}
102
+	}
103
+
104
+
105
+	/**
106
+	 * Finishes construction given the parent form section and this form section's name
107
+	 *
108
+	 * @param EE_Form_Section_Proper $parent_form_section
109
+	 * @param string                 $name
110
+	 * @throws EE_Error
111
+	 */
112
+	public function _construct_finalize($parent_form_section, $name)
113
+	{
114
+		if (! $this->_payment_method_type instanceof EE_PMT_Base) {
115
+			throw new EE_Error(
116
+				esc_html__(
117
+					'Payment Method forms must have set their payment method type BEFORE calling _construct_finalize',
118
+					'event_espresso'
119
+				)
120
+			);
121
+		}
122
+		// set the name of this form based on the payment method type
123
+		if (! $this->_name && ! $name) {
124
+			$name = str_replace(" ", "_", ucwords(str_replace("_", " ", ($this->_payment_method_type->system_name()))))
125
+					. "_Settings_Form";
126
+		}
127
+		parent::_construct_finalize($parent_form_section, $name);
128
+	}
129
+
130
+
131
+	/**
132
+	 * @param $payment_method_type
133
+	 * @throws EE_Error
134
+	 */
135
+	public function set_payment_method_type($payment_method_type)
136
+	{
137
+		if (! $payment_method_type instanceof EE_PMT_Base) {
138
+			throw new EE_Error(
139
+				esc_html__(
140
+					"Payment Method forms MUST set a payment method type by using _set_payment_method_type",
141
+					"event_espresso"
142
+				)
143
+			);
144
+		}
145
+		$this->_payment_method_type = $payment_method_type;
146
+	}
147
+
148
+
149
+	/**
150
+	 * extends the model form section's save() method to also save the extra meta field values
151
+	 *
152
+	 * @return int ID of the payment method inserted, or true on update
153
+	 * @throws EE_Error
154
+	 * @throws ReflectionException
155
+	 */
156
+	public function save(): int
157
+	{
158
+		$parent_save_val = parent::save();
159
+		if ($this->_model_object && $this->_model_object->ID()) {
160
+			foreach ($this->_extra_meta_inputs as $input_name => $input) {
161
+				$this->_model_object->update_extra_meta($input_name, $input->normalized_value());
162
+			}
163
+		}
164
+		return $parent_save_val;
165
+	}
166
+
167
+
168
+	/**
169
+	 * Overrides parent's populate_model_obj to also populate the extra meta fields
170
+	 *
171
+	 * @param EE_Base_Class $model_obj
172
+	 * @throws EE_Error
173
+	 * @throws ReflectionException
174
+	 */
175
+	public function populate_model_obj($model_obj)
176
+	{
177
+		$model_obj = $this->_model->ensure_is_obj($model_obj);
178
+		parent::populate_model_obj($model_obj);
179
+		$extra_meta = $model_obj->all_extra_meta_array();
180
+		foreach ($this->_extra_meta_inputs as $input_name => $extra_meta_input) {
181
+			if (isset($extra_meta[ $input_name ])) {
182
+				$extra_meta_input->set_default($extra_meta[ $input_name ]);
183
+			}
184
+		}
185
+	}
186
+
187
+
188
+	/**
189
+	 * gets the default name of this form section if none is specified
190
+	 *
191
+	 * @return void
192
+	 */
193
+	protected function _set_default_name_if_empty()
194
+	{
195
+		if (! $this->_name) {
196
+			$default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form";
197
+			$this->_name  = $default_name;
198
+		}
199
+	}
200
+
201
+
202
+	/**
203
+	 * Gets all the extra meta inputs in this form
204
+	 *
205
+	 * @return EE_Form_Input_Base[]
206
+	 */
207
+	public function extra_meta_inputs(): array
208
+	{
209
+		return $this->_extra_meta_inputs;
210
+	}
211 211
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
             ]
70 70
         );
71 71
         // set up the currency options
72
-        $this->_subsections['Currency']  = new EE_Select_Multi_Model_Input(
72
+        $this->_subsections['Currency'] = new EE_Select_Multi_Model_Input(
73 73
             EEM_Currency::instance()->get_all_currencies_usable_by($this->_payment_method_type),
74 74
             [
75 75
                 'html_label_text' => esc_html__('Currencies Supported', 'event_espresso'),
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
                 'default'                => 0,
88 88
             ]
89 89
         );
90
-        $this->_layout_strategy          = new EE_Admin_Two_Column_Layout();
90
+        $this->_layout_strategy = new EE_Admin_Two_Column_Layout();
91 91
 
92 92
         parent::__construct($this->_options_array);
93 93
         $debug_mode = $this->_subsections['PMD_debug_mode'] ?? null;
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
      */
112 112
     public function _construct_finalize($parent_form_section, $name)
113 113
     {
114
-        if (! $this->_payment_method_type instanceof EE_PMT_Base) {
114
+        if ( ! $this->_payment_method_type instanceof EE_PMT_Base) {
115 115
             throw new EE_Error(
116 116
                 esc_html__(
117 117
                     'Payment Method forms must have set their payment method type BEFORE calling _construct_finalize',
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
             );
121 121
         }
122 122
         // set the name of this form based on the payment method type
123
-        if (! $this->_name && ! $name) {
123
+        if ( ! $this->_name && ! $name) {
124 124
             $name = str_replace(" ", "_", ucwords(str_replace("_", " ", ($this->_payment_method_type->system_name()))))
125 125
                     . "_Settings_Form";
126 126
         }
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
      */
135 135
     public function set_payment_method_type($payment_method_type)
136 136
     {
137
-        if (! $payment_method_type instanceof EE_PMT_Base) {
137
+        if ( ! $payment_method_type instanceof EE_PMT_Base) {
138 138
             throw new EE_Error(
139 139
                 esc_html__(
140 140
                     "Payment Method forms MUST set a payment method type by using _set_payment_method_type",
@@ -178,8 +178,8 @@  discard block
 block discarded – undo
178 178
         parent::populate_model_obj($model_obj);
179 179
         $extra_meta = $model_obj->all_extra_meta_array();
180 180
         foreach ($this->_extra_meta_inputs as $input_name => $extra_meta_input) {
181
-            if (isset($extra_meta[ $input_name ])) {
182
-                $extra_meta_input->set_default($extra_meta[ $input_name ]);
181
+            if (isset($extra_meta[$input_name])) {
182
+                $extra_meta_input->set_default($extra_meta[$input_name]);
183 183
             }
184 184
         }
185 185
     }
@@ -192,8 +192,8 @@  discard block
 block discarded – undo
192 192
      */
193 193
     protected function _set_default_name_if_empty()
194 194
     {
195
-        if (! $this->_name) {
196
-            $default_name = str_replace("EEM_", "", get_class($this->_model)) . "_Model_Form";
195
+        if ( ! $this->_name) {
196
+            $default_name = str_replace("EEM_", "", get_class($this->_model))."_Model_Form";
197 197
             $this->_name  = $default_name;
198 198
         }
199 199
     }
Please login to merge, or discard this patch.
core/libraries/form_sections/inputs/EE_Form_Input_Base.input.php 2 patches
Indentation   +1282 added lines, -1282 removed lines patch added patch discarded remove patch
@@ -14,1286 +14,1286 @@
 block discarded – undo
14 14
  */
15 15
 abstract class EE_Form_Input_Base extends EE_Form_Section_Validatable
16 16
 {
17
-    /**
18
-     * the input's name attribute
19
-     *
20
-     * @var string|null
21
-     */
22
-    protected ?string $_html_name = null;
23
-
24
-    /**
25
-     * id for the HTML label tag
26
-     *
27
-     * @var string
28
-     */
29
-    protected $_html_label_id;
30
-
31
-    /**
32
-     * class for the HTML label tag
33
-     *
34
-     * @var string
35
-     */
36
-    protected $_html_label_class;
37
-
38
-    /**
39
-     * style for the HTML label tag
40
-     *
41
-     * @var string
42
-     */
43
-    protected $_html_label_style;
44
-
45
-    /**
46
-     * text to be placed in the HTML label
47
-     *
48
-     * @var string
49
-     */
50
-    protected $_html_label_text;
51
-
52
-    /**
53
-     * the full HTML label. If used, all other html_label_* properties are invalid
54
-     *
55
-     * @var string
56
-     */
57
-    protected $_html_label;
58
-
59
-    /**
60
-     * HTML to use for help text (normally placed below form input), in a span which normally
61
-     * has a class of 'description'
62
-     *
63
-     * @var string
64
-     */
65
-    protected $_html_help_text;
66
-
67
-    /**
68
-     * CSS classes for displaying the help span
69
-     *
70
-     * @var string
71
-     */
72
-    protected $_html_help_class = 'description';
73
-
74
-    /**
75
-     * CSS to put in the style attribute on the help span
76
-     *
77
-     * @var string
78
-     */
79
-    protected $_html_help_style;
80
-
81
-    /**
82
-     * Stores whether this input's response is required.
83
-     * Because certain styling elements may also want to know that this
84
-     * input is required etc.
85
-     *
86
-     * @var boolean
87
-     */
88
-    protected $_required;
89
-
90
-    /**
91
-     * css class added to required inputs
92
-     *
93
-     * @var string
94
-     */
95
-    protected $_required_css_class = 'ee-required';
96
-
97
-    /**
98
-     * css styles applied to button type inputs
99
-     *
100
-     * @var string
101
-     */
102
-    protected $_button_css_attributes;
103
-
104
-    /**
105
-     * The raw post data submitted for this
106
-     * Generally unsafe for usage in client code
107
-     *
108
-     * @var mixed string or array
109
-     */
110
-    protected $_raw_value;
111
-
112
-    /**
113
-     * Value normalized according to the input's normalization strategy.
114
-     * The normalization strategy dictates whether this is a string, int, float,
115
-     * boolean, or array of any of those.
116
-     *
117
-     * @var mixed
118
-     */
119
-    protected $_normalized_value;
120
-
121
-
122
-    /**
123
-     * Normalized default value either initially set on the input, or provided by calling
124
-     * set_default().
125
-     *
126
-     * @var mixed
127
-     */
128
-    protected $_default;
129
-
130
-    /**
131
-     * Strategy used for displaying this field.
132
-     * Child classes must use _get_display_strategy to access it.
133
-     *
134
-     * @var EE_Display_Strategy_Base
135
-     */
136
-    private $_display_strategy;
137
-
138
-    /**
139
-     * Gets all the validation strategies used on this field
140
-     *
141
-     * @var EE_Validation_Strategy_Base[]
142
-     */
143
-    private $_validation_strategies = [];
144
-
145
-    /**
146
-     * The normalization strategy for this field
147
-     *
148
-     * @var EE_Normalization_Strategy_Base
149
-     */
150
-    private $_normalization_strategy;
151
-
152
-    /**
153
-     * Strategy for removing sensitive data after we're done with the form input
154
-     *
155
-     * @var EE_Sensitive_Data_Removal_Base
156
-     */
157
-    protected $_sensitive_data_removal_strategy;
158
-
159
-    /**
160
-     * Whether this input has been disabled or not.
161
-     * If it's disabled while rendering, an extra hidden input is added that indicates it has been knowingly disabled.
162
-     * (Client-side code that wants to dynamically disable it must also add this hidden input).
163
-     * When the form is submitted, if the input is disabled in the PHP form section, then input is ignored.
164
-     * If the input is missing from the request data but the hidden input indicating the input is disabled, then the
165
-     * input is again ignored.
166
-     *
167
-     * @var boolean
168
-     */
169
-    protected $disabled = false;
170
-
171
-    protected array $_data_attributes = [];
172
-
173
-    protected bool $_no_label = false; // if true, then no HTML label will be displayed for this input
174
-
175
-    /**
176
-     * adds a class to the input's container
177
-     *
178
-     * @var string
179
-     */
180
-    protected string $_layout_container_class = '';
181
-
182
-    /**
183
-     * additional HTML to inject into the input's container
184
-     *
185
-     * @var string
186
-     */
187
-    protected string $_extra_container_html = '';
188
-
189
-
190
-    /**
191
-     * @param array                         $input_args       {
192
-     * @type string                         $html_name        the HTML name for the input
193
-     * @type string                         $html_label_id    the id attribute to give to the HTML label tag
194
-     * @type string                         $html_label_class the class attribute to give to the HTML label tag
195
-     * @type string                         $html_label_style the style attribute to give ot the label tag
196
-     * @type string                         $html_label_text  the text to put in the label tag
197
-     * @type string                         $html_label       the full HTML label. If used,
198
-     *                                                        all other html_label_* args are invalid
199
-     * @type string                         $html_help_text   text to put in help element
200
-     * @type string                         $html_help_style  style attribute to give to the help element
201
-     * @type string                         $html_help_class  class attribute to give to the help element
202
-     * @type string                         $default          default value NORMALIZED (eg, if providing the default
203
-     *                                                        for a Yes_No_Input, you should provide TRUE or FALSE, not
204
-     *                                                        '1' or '0')
205
-     * @type EE_Display_Strategy_Base       $display          strategy
206
-     * @type EE_Normalization_Strategy_Base $normalization_strategy
207
-     * @type EE_Validation_Strategy_Base[]  $validation_strategies
208
-     * @type boolean                        $ignore_input     special argument which can be used to avoid adding any
209
-     *                                                        validation strategies, and sets the normalization
210
-     *                                                        strategy to the Null normalization. This is good when you
211
-     *                                                        want the input to be totally ignored server-side (like
212
-     *                                                        when using React.js form inputs)
213
-     *                                                        }
214
-     */
215
-    public function __construct($input_args = [])
216
-    {
217
-        $input_args = (array) apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this);
218
-        // the following properties must be cast as arrays
219
-        if (isset($input_args['validation_strategies'])) {
220
-            foreach ((array) $input_args['validation_strategies'] as $validation_strategy) {
221
-                if ($validation_strategy instanceof EE_Validation_Strategy_Base && empty($input_args['ignore_input'])) {
222
-                    $this->_validation_strategies[ get_class($validation_strategy) ] = $validation_strategy;
223
-                }
224
-            }
225
-            unset($input_args['validation_strategies']);
226
-        }
227
-        if (isset($input_args['ignore_input'])) {
228
-            $this->_validation_strategies = [];
229
-        }
230
-        // loop thru incoming options
231
-        foreach ($input_args as $key => $value) {
232
-            if ($key === 'disabled') {
233
-                $this->disable($value);
234
-                continue;
235
-            }
236
-            $setter = 'set_' . $key;
237
-            if (method_exists($this, $setter)) {
238
-                $this->$setter($value);
239
-                unset($input_args[ $key ]);
240
-                continue;
241
-            }
242
-            // add underscore to $key to match property names
243
-            $_key = "_$key";
244
-            if (property_exists($this, $_key)) {
245
-                $this->{$_key} = $value;
246
-                unset($input_args[ $key ]);
247
-            }
248
-        }
249
-        // ensure that "required" is set correctly
250
-        $this->set_required(
251
-            $this->_required,
252
-            $input_args['required_validation_error_message'] ?? null
253
-        );
254
-        // $this->_html_name_specified = isset( $input_args['html_name'] ) ? TRUE : FALSE;
255
-        $this->_display_strategy->_construct_finalize($this);
256
-        foreach ($this->_validation_strategies as $validation_strategy) {
257
-            $validation_strategy->_construct_finalize($this);
258
-        }
259
-        if (isset($input_args['ignore_input'])) {
260
-            $this->_normalization_strategy = new EE_Null_Normalization();
261
-        }
262
-        if (! $this->_normalization_strategy) {
263
-            $this->_normalization_strategy = new EE_Text_Normalization();
264
-        }
265
-        $this->_normalization_strategy->_construct_finalize($this);
266
-        // at least we can use the normalization strategy to populate the default
267
-        if (isset($input_args['default'])) {
268
-            $this->set_default($input_args['default']);
269
-            unset($input_args['default']);
270
-        }
271
-        if (! $this->_sensitive_data_removal_strategy) {
272
-            $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal();
273
-        }
274
-        $this->_sensitive_data_removal_strategy->_construct_finalize($this);
275
-        parent::__construct($input_args);
276
-    }
277
-
278
-
279
-    /**
280
-     * Sets the html_name to its default value, if none was specified in the constructor.
281
-     * Calculation involves using the name and the parent's html_name
282
-     *
283
-     * @throws EE_Error
284
-     */
285
-    protected function _set_default_html_name_if_empty()
286
-    {
287
-        if (! $this->_html_name) {
288
-            $this->_html_name = $this->name();
289
-            if ($this->_parent_section instanceof EE_Form_Section_Proper) {
290
-                $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]";
291
-            }
292
-        }
293
-    }
294
-
295
-
296
-    /**
297
-     * @param $parent_form_section
298
-     * @param $name
299
-     * @throws EE_Error
300
-     */
301
-    public function _construct_finalize($parent_form_section, $name)
302
-    {
303
-        parent::_construct_finalize($parent_form_section, $name);
304
-        if ($this->_html_label === null && $this->_html_label_text === null && ! $this->_no_label) {
305
-            $this->_html_label_text = ucwords(str_replace("_", " ", $name));
306
-        }
307
-        do_action('AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name);
308
-    }
309
-
310
-
311
-    /**
312
-     * Returns the strategy for displaying this form input. If none is set, throws an exception.
313
-     *
314
-     * @return EE_Display_Strategy_Base
315
-     * @throws EE_Error
316
-     */
317
-    protected function _get_display_strategy()
318
-    {
319
-        $this->ensure_construct_finalized_called();
320
-        if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) {
321
-            throw new EE_Error(
322
-                sprintf(
323
-                    esc_html__(
324
-                        "Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor",
325
-                        "event_espresso"
326
-                    ),
327
-                    $this->html_name(),
328
-                    $this->html_id()
329
-                )
330
-            );
331
-        } else {
332
-            return $this->_display_strategy;
333
-        }
334
-    }
335
-
336
-
337
-    /**
338
-     * Sets the display strategy.
339
-     *
340
-     * @param EE_Display_Strategy_Base $strategy
341
-     */
342
-    protected function _set_display_strategy(EE_Display_Strategy_Base $strategy)
343
-    {
344
-        $this->_display_strategy = $strategy;
345
-    }
346
-
347
-
348
-    /**
349
-     * Sets the sanitization strategy
350
-     *
351
-     * @param EE_Normalization_Strategy_Base $strategy
352
-     */
353
-    protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy)
354
-    {
355
-        $this->_normalization_strategy = $strategy;
356
-    }
357
-
358
-
359
-    /**
360
-     * Gets sensitive_data_removal_strategy
361
-     *
362
-     * @return EE_Sensitive_Data_Removal_Base
363
-     */
364
-    public function get_sensitive_data_removal_strategy()
365
-    {
366
-        return $this->_sensitive_data_removal_strategy;
367
-    }
368
-
369
-
370
-    /**
371
-     * Sets sensitive_data_removal_strategy
372
-     *
373
-     * @param EE_Sensitive_Data_Removal_Base $sensitive_data_removal_strategy
374
-     * @return void
375
-     */
376
-    public function set_sensitive_data_removal_strategy($sensitive_data_removal_strategy)
377
-    {
378
-        $this->_sensitive_data_removal_strategy = $sensitive_data_removal_strategy;
379
-    }
380
-
381
-
382
-    /**
383
-     * Gets the display strategy for this input
384
-     *
385
-     * @return EE_Display_Strategy_Base
386
-     */
387
-    public function get_display_strategy()
388
-    {
389
-        return $this->_display_strategy;
390
-    }
391
-
392
-
393
-    /**
394
-     * Overwrites the display strategy
395
-     *
396
-     * @param EE_Display_Strategy_Base $display_strategy
397
-     */
398
-    public function set_display_strategy($display_strategy)
399
-    {
400
-        $this->_display_strategy = $display_strategy;
401
-        $this->_display_strategy->_construct_finalize($this);
402
-    }
403
-
404
-
405
-    /**
406
-     * Gets the normalization strategy set on this input
407
-     *
408
-     * @return EE_Normalization_Strategy_Base
409
-     */
410
-    public function get_normalization_strategy()
411
-    {
412
-        return $this->_normalization_strategy;
413
-    }
414
-
415
-
416
-    /**
417
-     * Overwrites the normalization strategy
418
-     *
419
-     * @param EE_Normalization_Strategy_Base $normalization_strategy
420
-     */
421
-    public function set_normalization_strategy($normalization_strategy)
422
-    {
423
-        $this->_normalization_strategy = $normalization_strategy;
424
-        $this->_normalization_strategy->_construct_finalize($this);
425
-    }
426
-
427
-
428
-    /**
429
-     * Returns all the validation strategies which apply to this field, numerically indexed
430
-     *
431
-     * @return EE_Validation_Strategy_Base[]
432
-     */
433
-    public function get_validation_strategies()
434
-    {
435
-        return $this->_validation_strategies;
436
-    }
437
-
438
-
439
-    /**
440
-     * Adds this strategy to the field so it will be used in both JS validation and server-side validation
441
-     *
442
-     * @param EE_Validation_Strategy_Base $validation_strategy
443
-     * @return void
444
-     */
445
-    protected function _add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy)
446
-    {
447
-        $validation_strategy->_construct_finalize($this);
448
-        $this->_validation_strategies[] = $validation_strategy;
449
-    }
450
-
451
-
452
-    /**
453
-     * Adds a new validation strategy onto the form input
454
-     *
455
-     * @param EE_Validation_Strategy_Base $validation_strategy
456
-     * @return void
457
-     */
458
-    public function add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy)
459
-    {
460
-        $this->_add_validation_strategy($validation_strategy);
461
-    }
462
-
463
-
464
-    /**
465
-     * The classname of the validation strategy to remove
466
-     *
467
-     * @param string $validation_strategy_classname
468
-     */
469
-    public function remove_validation_strategy($validation_strategy_classname)
470
-    {
471
-        foreach ($this->_validation_strategies as $key => $validation_strategy) {
472
-            if (
473
-                $validation_strategy instanceof $validation_strategy_classname
474
-                || is_subclass_of($validation_strategy, $validation_strategy_classname)
475
-            ) {
476
-                unset($this->_validation_strategies[ $key ]);
477
-            }
478
-        }
479
-    }
480
-
481
-
482
-    public function removeAllValidationStrategies()
483
-    {
484
-        $this->_validation_strategies = [];
485
-    }
486
-
487
-
488
-    /**
489
-     * returns true if input employs any of the validation strategy defined by the supplied array of classnames
490
-     *
491
-     * @param array $validation_strategy_classnames
492
-     * @return bool
493
-     */
494
-    public function has_validation_strategy($validation_strategy_classnames)
495
-    {
496
-        $validation_strategy_classnames = is_array($validation_strategy_classnames)
497
-            ? $validation_strategy_classnames
498
-            : [$validation_strategy_classnames];
499
-        foreach ($this->_validation_strategies as $key => $validation_strategy) {
500
-            if (in_array($key, $validation_strategy_classnames)) {
501
-                return true;
502
-            }
503
-        }
504
-        return false;
505
-    }
506
-
507
-
508
-    /**
509
-     * Gets the HTML
510
-     *
511
-     * @return string
512
-     */
513
-    public function get_html()
514
-    {
515
-        return $this->_parent_section->get_html_for_input($this);
516
-    }
517
-
518
-
519
-    /**
520
-     * Gets the HTML for the input itself (no label or errors) according to the
521
-     * input's display strategy
522
-     * Makes sure the JS and CSS are enqueued for it
523
-     *
524
-     * @return string
525
-     * @throws EE_Error
526
-     */
527
-    public function get_html_for_input()
528
-    {
529
-        return $this->_form_html_filter
530
-            ? $this->_form_html_filter->filterHtml(
531
-                $this->_get_display_strategy()->display(),
532
-                $this
533
-            )
534
-            : $this->_get_display_strategy()->display();
535
-    }
536
-
537
-
538
-    /**
539
-     * @return string
540
-     */
541
-    public function html_other_attributes()
542
-    {
543
-        EE_Error::doing_it_wrong(
544
-            __METHOD__,
545
-            sprintf(
546
-                esc_html__(
547
-                    'This method is no longer in use. You should replace it by %s',
548
-                    'event_espresso'
549
-                ),
550
-                'EE_Form_Section_Base::other_html_attributes()'
551
-            ),
552
-            '4.10.2.p'
553
-        );
554
-
555
-        return $this->other_html_attributes();
556
-    }
557
-
558
-
559
-    /**
560
-     * @param string $html_other_attributes
561
-     */
562
-    public function set_html_other_attributes($html_other_attributes)
563
-    {
564
-        EE_Error::doing_it_wrong(
565
-            __METHOD__,
566
-            sprintf(
567
-                esc_html__(
568
-                    'This method is no longer in use. You should replace it by %s',
569
-                    'event_espresso'
570
-                ),
571
-                'EE_Form_Section_Base::set_other_html_attributes()'
572
-            ),
573
-            '4.10.2.p'
574
-        );
575
-
576
-        $this->set_other_html_attributes($html_other_attributes);
577
-    }
578
-
579
-
580
-    /**
581
-     * Gets the HTML for displaying the label for this form input
582
-     * according to the form section's layout strategy
583
-     *
584
-     * @return string
585
-     * @throws EE_Error
586
-     */
587
-    public function get_html_for_label()
588
-    {
589
-        return $this->_parent_section->get_layout_strategy()->display_label($this);
590
-    }
591
-
592
-
593
-    /**
594
-     * Gets the HTML for displaying the errors section for this form input
595
-     * according to the form section's layout strategy
596
-     *
597
-     * @return string
598
-     * @throws EE_Error
599
-     */
600
-    public function get_html_for_errors()
601
-    {
602
-        return $this->_parent_section->get_layout_strategy()->display_errors($this);
603
-    }
604
-
605
-
606
-    /**
607
-     * Gets the HTML for displaying the help text for this form input
608
-     * according to the form section's layout strategy
609
-     *
610
-     * @return string
611
-     * @throws EE_Error
612
-     */
613
-    public function get_html_for_help()
614
-    {
615
-        return $this->_parent_section->get_layout_strategy()->display_help_text($this);
616
-    }
617
-
618
-
619
-    /**
620
-     * Validates the input's sanitized value (assumes _sanitize() has already been called)
621
-     * and returns whether the form input's submitted value is value
622
-     *
623
-     * @return boolean
624
-     */
625
-    protected function _validate()
626
-    {
627
-        if ($this->isDisabled()) {
628
-            return true;
629
-        }
630
-        foreach ($this->_validation_strategies as $validation_strategy) {
631
-            if ($validation_strategy instanceof EE_Validation_Strategy_Base) {
632
-                try {
633
-                    $validation_strategy->validate($this->normalized_value());
634
-                } catch (EE_Validation_Error $e) {
635
-                    $this->add_validation_error($e);
636
-                }
637
-            }
638
-        }
639
-        if ($this->get_validation_errors()) {
640
-            return false;
641
-        } else {
642
-            return true;
643
-        }
644
-    }
645
-
646
-
647
-    /**
648
-     * Performs basic sanitization on this value. But what sanitization can be performed anyways?
649
-     * This value MIGHT be allowed to have tags, so we can't really remove them.
650
-     *
651
-     * @param string $value
652
-     * @return null|string
653
-     */
654
-    protected function _sanitize($value)
655
-    {
656
-        return $value !== null
657
-            ? stripslashes(html_entity_decode(trim((string) $value)))
658
-            : null;
659
-    }
660
-
661
-
662
-    /**
663
-     * Picks out the form value that relates to this form input,
664
-     * and stores it as the sanitized value on the form input, and sets the normalized value.
665
-     * Returns whether any validation errors occurred
666
-     *
667
-     * @param array $req_data
668
-     * @return boolean whether there was an error
669
-     * @throws EE_Error
670
-     */
671
-    protected function _normalize($req_data)
672
-    {
673
-        // any existing validation errors don't apply so clear them
674
-        $this->_validation_errors = [];
675
-        // if the input is disabled, ignore whatever input was sent in
676
-        if ($this->isDisabled()) {
677
-            $this->_set_raw_value(null);
678
-            $this->_set_normalized_value($this->get_default());
679
-            return false;
680
-        }
681
-        try {
682
-            $raw_input = $this->find_form_data_for_this_section($req_data);
683
-            // super simple sanitization for now
684
-            if (is_array($raw_input)) {
685
-                $raw_value = [];
686
-                foreach ($raw_input as $key => $value) {
687
-                    $raw_value[ $key ] = $this->_sanitize($value);
688
-                }
689
-                $this->_set_raw_value($raw_value);
690
-            } else {
691
-                $this->_set_raw_value($this->_sanitize($raw_input));
692
-            }
693
-            // we want to mostly leave the input alone in case we need to re-display it to the user
694
-            $this->_set_normalized_value($this->_normalization_strategy->normalize($this->raw_value()));
695
-            return false;
696
-        } catch (EE_Validation_Error $e) {
697
-            $this->add_validation_error($e);
698
-            return true;
699
-        }
700
-    }
701
-
702
-
703
-    /**
704
-     * @return string
705
-     * @throws EE_Error
706
-     */
707
-    public function html_name()
708
-    {
709
-        $this->_set_default_html_name_if_empty();
710
-        return $this->_html_name ?? '';
711
-    }
712
-
713
-
714
-    /**
715
-     * @param string $html_label_id
716
-     */
717
-    public function set_html_label_id(string $html_label_id)
718
-    {
719
-        // if the html_label_id doesn't end in -lbl, then add it
720
-        if (strpos($html_label_id, '-lbl') !== (strlen($html_label_id) - 4)) {
721
-            $html_label_id .= '-lbl';
722
-        }
723
-        $this->_html_label_id = $html_label_id;
724
-    }
725
-
726
-
727
-    /**
728
-     * @return string
729
-     * @throws EE_Error
730
-     */
731
-    public function html_label_id()
732
-    {
733
-        if (empty($this->_html_label_id)) {
734
-            $this->set_html_label_id($this->html_id());
735
-        }
736
-        return $this->_html_label_id;
737
-    }
738
-
739
-
740
-    /**
741
-     * @return string
742
-     */
743
-    public function html_label_class()
744
-    {
745
-        return $this->_html_label_class ?? '';
746
-    }
747
-
748
-
749
-    /**
750
-     * @param string $html_class
751
-     */
752
-    public function add_html_label_class(string $html_class)
753
-    {
754
-        $this->_html_label_class .= ' ' . trim($html_class);
755
-    }
756
-
757
-
758
-    /**
759
-     * @return string
760
-     */
761
-    public function html_label_style()
762
-    {
763
-        return $this->_html_label_style ?? '';
764
-    }
765
-
766
-
767
-    /**
768
-     * @return string
769
-     */
770
-    public function html_label_text()
771
-    {
772
-        return $this->_html_label_text ?? '';
773
-    }
774
-
775
-
776
-    /**
777
-     * @return string
778
-     */
779
-    public function html_help_text()
780
-    {
781
-        return $this->_html_help_text ?? '';
782
-    }
783
-
784
-
785
-    /**
786
-     * @return string
787
-     */
788
-    public function html_help_class()
789
-    {
790
-        return $this->_html_help_class ?? '';
791
-    }
792
-
793
-
794
-    /**
795
-     * @return string
796
-     */
797
-    public function html_help_style()
798
-    {
799
-        return $this->_html_style ?? '';
800
-    }
801
-
802
-
803
-    /**
804
-     * returns the raw, UNSAFE, input, almost exactly as the user submitted it.
805
-     * Please note that almost all client code should instead use the normalized_value;
806
-     * or possibly raw_value_in_form (which prepares the string for displaying in an HTML attribute on a tag,
807
-     * mostly by escaping quotes)
808
-     * Note, we do not store the exact original value sent in the user's request because
809
-     * it may have malicious content, and we MIGHT want to store the form input in a transient or something...
810
-     * in which case, we would have stored the malicious content to our database.
811
-     *
812
-     * @return mixed
813
-     */
814
-    public function raw_value()
815
-    {
816
-        return $this->_raw_value;
817
-    }
818
-
819
-
820
-    /**
821
-     * Returns a string safe to usage in form inputs when displaying, because
822
-     * it escapes all HTML entities
823
-     *
824
-     * @return string
825
-     */
826
-    public function raw_value_in_form(): string
827
-    {
828
-        return htmlentities((string) $this->raw_value(), ENT_QUOTES, 'UTF-8');
829
-    }
830
-
831
-
832
-    /**
833
-     * returns the value after it's been sanitized, and then converted into it's proper type
834
-     * in PHP. Eg, a string, an int, an array,
835
-     *
836
-     * @return mixed
837
-     */
838
-    public function normalized_value()
839
-    {
840
-        return $this->_normalized_value;
841
-    }
842
-
843
-
844
-    /**
845
-     * Returns the normalized value is a presentable way. By default this is just
846
-     * the normalized value by itself, but it can be overridden for when that's not
847
-     * the best thing to display
848
-     *
849
-     * @return mixed
850
-     */
851
-    public function pretty_value()
852
-    {
853
-        return $this->_normalized_value;
854
-    }
855
-
856
-
857
-    /**
858
-     * When generating the JS for the jquery validation rules like<br>
859
-     * <code>$( "#myform" ).validate({
860
-     * rules: {
861
-     * password: "required",
862
-     * password_again: {
863
-     * equalTo: "#password"
864
-     * }
865
-     * }
866
-     * });</code>
867
-     * if this field had the name 'password_again', it should return
868
-     * <br><code>password_again: {
869
-     * equalTo: "#password"
870
-     * }</code>
871
-     *
872
-     * @return array
873
-     * @throws EE_Error
874
-     */
875
-    public function get_jquery_validation_rules(): array
876
-    {
877
-        $jquery_validation_js    = [];
878
-        $jquery_validation_rules = [];
879
-        foreach ($this->get_validation_strategies() as $validation_strategy) {
880
-            $jquery_validation_rules = array_replace_recursive(
881
-                $jquery_validation_rules,
882
-                $validation_strategy->get_jquery_validation_rule_array()
883
-            );
884
-        }
885
-        if (! empty($jquery_validation_rules)) {
886
-            foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) {
887
-                $jquery_validation_js[ $html_id_with_pound_sign ] = $jquery_validation_rules;
888
-            }
889
-        }
890
-        return $jquery_validation_js;
891
-    }
892
-
893
-
894
-    /**
895
-     * Sets the input's default value for use in displaying in the form. Note: value should be
896
-     * normalized (Eg, if providing a default of ra Yes_NO_Input you would provide TRUE or FALSE, not '1' or '0')
897
-     *
898
-     * @param mixed $value
899
-     * @return void
900
-     */
901
-    public function set_default($value)
902
-    {
903
-        $this->_default = $value;
904
-        $this->_set_normalized_value($value);
905
-        $this->_set_raw_value($value);
906
-    }
907
-
908
-
909
-    /**
910
-     * Sets the normalized value on this input
911
-     *
912
-     * @param mixed $value
913
-     */
914
-    protected function _set_normalized_value($value)
915
-    {
916
-        $this->_normalized_value = $value;
917
-    }
918
-
919
-
920
-    /**
921
-     * Sets the raw value on this input (ie, exactly as the user submitted it)
922
-     *
923
-     * @param mixed $value
924
-     */
925
-    protected function _set_raw_value($value)
926
-    {
927
-        $this->_raw_value = $this->_normalization_strategy->unnormalize($value);
928
-    }
929
-
930
-
931
-    /**
932
-     * Sets the HTML label text after it has already been defined
933
-     *
934
-     * @param string $label
935
-     * @return void
936
-     */
937
-    public function set_html_label_text($label)
938
-    {
939
-        $this->_html_label_text = $label;
940
-    }
941
-
942
-
943
-    /**
944
-     * Sets whether this field is required, and adjusts the validation strategy.
945
-     * If you want to use the EE_Conditionally_Required_Validation_Strategy,
946
-     * please add it as a validation strategy using add_validation_strategy as normal
947
-     *
948
-     * @param boolean $required boolean
949
-     * @param null    $required_text
950
-     */
951
-    public function set_required($required = true, $required_text = null)
952
-    {
953
-        $required = filter_var($required, FILTER_VALIDATE_BOOLEAN);
954
-        // whether $required is a string or a boolean, we want to add a required validation strategy
955
-        if ($required) {
956
-            $this->_add_validation_strategy(new EE_Required_Validation_Strategy($required_text));
957
-        } else {
958
-            $this->remove_validation_strategy('EE_Required_Validation_Strategy');
959
-        }
960
-        $this->_required = $required;
961
-    }
962
-
963
-
964
-    /**
965
-     * Returns whether this field is required
966
-     *
967
-     * @return boolean
968
-     */
969
-    public function required()
970
-    {
971
-        return $this->_required;
972
-    }
973
-
974
-
975
-    /**
976
-     * @param string $required_css_class
977
-     */
978
-    public function set_required_css_class($required_css_class)
979
-    {
980
-        $this->_required_css_class = $required_css_class;
981
-    }
982
-
983
-
984
-    /**
985
-     * @return string
986
-     */
987
-    public function required_css_class()
988
-    {
989
-        return $this->_required_css_class;
990
-    }
991
-
992
-
993
-    /**
994
-     * @param bool $add_required
995
-     * @return string
996
-     */
997
-    public function html_class($add_required = false)
998
-    {
999
-        return $add_required && $this->required()
1000
-            ? $this->required_css_class() . ' ' . $this->_html_class
1001
-            : $this->_html_class;
1002
-    }
1003
-
1004
-
1005
-    /**
1006
-     * Sets the help text, in case
1007
-     *
1008
-     * @param string $text
1009
-     */
1010
-    public function set_html_help_text($text)
1011
-    {
1012
-        $this->_html_help_text = $text;
1013
-    }
1014
-
1015
-
1016
-    /**
1017
-     * Uses the sensitive data removal strategy to remove the sensitive data from this
1018
-     * input. If there is any kind of sensitive data removal on this input, we clear
1019
-     * out the raw value completely
1020
-     *
1021
-     * @return void
1022
-     */
1023
-    public function clean_sensitive_data()
1024
-    {
1025
-        // if we do ANY kind of sensitive data removal on this, then just clear out the raw value
1026
-        // if we need more logic than this we'll make a strategy for it
1027
-        if (
1028
-            $this->_sensitive_data_removal_strategy
1029
-            && ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal
1030
-        ) {
1031
-            $this->_set_raw_value(null);
1032
-        }
1033
-        // and clean the normalized value according to the appropriate strategy
1034
-        $this->_set_normalized_value(
1035
-            $this->get_sensitive_data_removal_strategy()->remove_sensitive_data(
1036
-                $this->_normalized_value
1037
-            )
1038
-        );
1039
-    }
1040
-
1041
-
1042
-    /**
1043
-     * @param bool   $primary
1044
-     * @param string $button_size
1045
-     * @param string $other_attributes
1046
-     */
1047
-    public function set_button_css_attributes($primary = true, $button_size = '', $other_attributes = '')
1048
-    {
1049
-        $button_css_attributes = 'button';
1050
-        $button_css_attributes .= $primary === true
1051
-            ? ' button--primary'
1052
-            : ' button--secondary';
1053
-        switch ($button_size) {
1054
-            case 'xs':
1055
-            case 'extra-small':
1056
-                $button_css_attributes .= ' button-xs';
1057
-                break;
1058
-            case 'sm':
1059
-            case 'small':
1060
-                $button_css_attributes .= ' button-sm';
1061
-                break;
1062
-            case 'lg':
1063
-            case 'large':
1064
-                $button_css_attributes .= ' button-lg';
1065
-                break;
1066
-            case 'block':
1067
-                $button_css_attributes .= ' button-block';
1068
-                break;
1069
-            case 'md':
1070
-            case 'medium':
1071
-            default:
1072
-                $button_css_attributes .= '';
1073
-        }
1074
-        $this->_button_css_attributes .= ! empty($other_attributes)
1075
-            ? $button_css_attributes . ' ' . $other_attributes
1076
-            : $button_css_attributes;
1077
-    }
1078
-
1079
-
1080
-    /**
1081
-     * @return string
1082
-     */
1083
-    public function button_css_attributes()
1084
-    {
1085
-        if (empty($this->_button_css_attributes)) {
1086
-            $this->set_button_css_attributes();
1087
-        }
1088
-        return $this->_button_css_attributes;
1089
-    }
1090
-
1091
-
1092
-    /**
1093
-     * find_form_data_for_this_section
1094
-     * using this section's name and its parents, finds the value of the form data that corresponds to it.
1095
-     * For example, if this form section's HTML name is my_form[subform][form_input_1],
1096
-     * then it's value should be in request at request['my_form']['subform']['form_input_1'].
1097
-     * (If that doesn't exist, we also check for this subsection's name
1098
-     * at the TOP LEVEL of the request data. Eg request['form_input_1'].)
1099
-     * This function finds its value in the form.
1100
-     *
1101
-     * @param array $req_data
1102
-     * @return mixed whatever the raw value of this form section is in the request data
1103
-     * @throws EE_Error
1104
-     */
1105
-    public function find_form_data_for_this_section($req_data)
1106
-    {
1107
-        $name_parts = $this->getInputNameParts();
1108
-        // now get the value for the input
1109
-        $value = $this->findRequestForSectionUsingNameParts($name_parts, $req_data);
1110
-        // check if this thing's name is at the TOP level of the request data
1111
-        if ($value === null && isset($req_data[ $this->name() ])) {
1112
-            $value = $req_data[ $this->name() ];
1113
-        }
1114
-        return $value;
1115
-    }
1116
-
1117
-
1118
-    /**
1119
-     * If this input's name is something like "foo[bar][baz]"
1120
-     * returns an array like `array('foo','bar',baz')`
1121
-     *
1122
-     * @return array
1123
-     * @throws EE_Error
1124
-     */
1125
-    protected function getInputNameParts(): array
1126
-    {
1127
-        // strip out ] brackets, then replace [ with . so we can explode
1128
-        $html_name = str_replace(
1129
-            [']', '['], // replace 1: ]  2: [
1130
-            ['', '.'],  // with    1: '' 2: .
1131
-            $this->html_name()
1132
-        );
1133
-        return explode('.', $html_name);
1134
-    }
1135
-
1136
-
1137
-    /**
1138
-     * @param array $html_name_parts
1139
-     * @param array $req_data
1140
-     * @return array | NULL
1141
-     */
1142
-    public function findRequestForSectionUsingNameParts($html_name_parts, $req_data)
1143
-    {
1144
-        $first_part_to_consider = array_shift($html_name_parts);
1145
-        if (isset($req_data[ $first_part_to_consider ])) {
1146
-            if (empty($html_name_parts)) {
1147
-                return $req_data[ $first_part_to_consider ];
1148
-            } else {
1149
-                return $this->findRequestForSectionUsingNameParts(
1150
-                    $html_name_parts,
1151
-                    $req_data[ $first_part_to_consider ]
1152
-                );
1153
-            }
1154
-        }
1155
-        return null;
1156
-    }
1157
-
1158
-
1159
-    /**
1160
-     * Checks if this form input's data is in the request data
1161
-     *
1162
-     * @param array $req_data
1163
-     * @return boolean
1164
-     * @throws EE_Error
1165
-     */
1166
-    public function form_data_present_in($req_data = null)
1167
-    {
1168
-        if ($req_data === null) {
1169
-            /** @var RequestInterface $request */
1170
-            $request  = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1171
-            $req_data = $request->postParams();
1172
-        }
1173
-
1174
-        return $this->find_form_data_for_this_section($req_data) !== null;
1175
-    }
1176
-
1177
-
1178
-    /**
1179
-     * Overrides parent to add js data from validation and display strategies
1180
-     *
1181
-     * @param array $form_other_js_data
1182
-     * @return array
1183
-     */
1184
-    public function get_other_js_data($form_other_js_data = [])
1185
-    {
1186
-        return $this->get_other_js_data_from_strategies($form_other_js_data);
1187
-    }
1188
-
1189
-
1190
-    /**
1191
-     * Gets other JS data for localization from this input's strategies, like
1192
-     * the validation strategies and the display strategy
1193
-     *
1194
-     * @param array $form_other_js_data
1195
-     * @return array
1196
-     */
1197
-    public function get_other_js_data_from_strategies($form_other_js_data = [])
1198
-    {
1199
-        $form_other_js_data = $this->get_display_strategy()->get_other_js_data($form_other_js_data);
1200
-        foreach ($this->get_validation_strategies() as $validation_strategy) {
1201
-            $form_other_js_data = $validation_strategy->get_other_js_data($form_other_js_data);
1202
-        }
1203
-        return $form_other_js_data;
1204
-    }
1205
-
1206
-
1207
-    /**
1208
-     * Override parent because we want to give our strategies an opportunity to enqueue some js and css
1209
-     *
1210
-     * @return void
1211
-     */
1212
-    public function enqueue_js()
1213
-    {
1214
-        // ask our display strategy and validation strategies if they have js to enqueue
1215
-        $this->enqueue_js_from_strategies();
1216
-    }
1217
-
1218
-
1219
-    /**
1220
-     * Tells strategies when its ok to enqueue their js and css
1221
-     *
1222
-     * @return void
1223
-     */
1224
-    public function enqueue_js_from_strategies()
1225
-    {
1226
-        $this->get_display_strategy()->enqueue_js();
1227
-        foreach ($this->get_validation_strategies() as $validation_strategy) {
1228
-            $validation_strategy->enqueue_js();
1229
-        }
1230
-    }
1231
-
1232
-
1233
-    /**
1234
-     * Gets the default value set on the input (not the current value, which may have been
1235
-     * changed because of a form submission). If no default was set, this us null.
1236
-     *
1237
-     * @return mixed
1238
-     */
1239
-    public function get_default()
1240
-    {
1241
-        return $this->_default;
1242
-    }
1243
-
1244
-
1245
-    /**
1246
-     * Makes this input disabled. That means it will have the HTML attribute 'disabled="disabled"',
1247
-     * and server-side if any input was received it will be ignored
1248
-     */
1249
-    public function disable($disable = true)
1250
-    {
1251
-        $disabled_attribute = ' disabled="disabled"';
1252
-        $this->disabled     = filter_var($disable, FILTER_VALIDATE_BOOLEAN);
1253
-        if ($this->disabled) {
1254
-            if (strpos($this->_other_html_attributes, $disabled_attribute) === false) {
1255
-                $this->_other_html_attributes .= $disabled_attribute;
1256
-            }
1257
-            $this->_set_normalized_value($this->get_default());
1258
-        } else {
1259
-            $this->_other_html_attributes = str_replace($disabled_attribute, '', $this->_other_html_attributes);
1260
-        }
1261
-    }
1262
-
1263
-
1264
-    /**
1265
-     * Returns whether this input is currently disabled.
1266
-     *
1267
-     * @return bool
1268
-     */
1269
-    public function isDisabled(): bool
1270
-    {
1271
-        return $this->disabled;
1272
-    }
1273
-
1274
-
1275
-    public function dataAttributes(): array
1276
-    {
1277
-        return $this->_data_attributes;
1278
-    }
1279
-
1280
-
1281
-    public function layoutContainerClass(): string
1282
-    {
1283
-        return $this->_layout_container_class;
1284
-    }
1285
-
1286
-
1287
-    public function extraContainerHtml(): string
1288
-    {
1289
-        return $this->_extra_container_html;
1290
-    }
1291
-
1292
-
1293
-    public function hasLabel(): bool
1294
-    {
1295
-        return ! $this->_no_label
1296
-            && $this->html_label_text()
1297
-            && ! $this->get_display_strategy() instanceof EE_Hidden_Display_Strategy;
1298
-    }
17
+	/**
18
+	 * the input's name attribute
19
+	 *
20
+	 * @var string|null
21
+	 */
22
+	protected ?string $_html_name = null;
23
+
24
+	/**
25
+	 * id for the HTML label tag
26
+	 *
27
+	 * @var string
28
+	 */
29
+	protected $_html_label_id;
30
+
31
+	/**
32
+	 * class for the HTML label tag
33
+	 *
34
+	 * @var string
35
+	 */
36
+	protected $_html_label_class;
37
+
38
+	/**
39
+	 * style for the HTML label tag
40
+	 *
41
+	 * @var string
42
+	 */
43
+	protected $_html_label_style;
44
+
45
+	/**
46
+	 * text to be placed in the HTML label
47
+	 *
48
+	 * @var string
49
+	 */
50
+	protected $_html_label_text;
51
+
52
+	/**
53
+	 * the full HTML label. If used, all other html_label_* properties are invalid
54
+	 *
55
+	 * @var string
56
+	 */
57
+	protected $_html_label;
58
+
59
+	/**
60
+	 * HTML to use for help text (normally placed below form input), in a span which normally
61
+	 * has a class of 'description'
62
+	 *
63
+	 * @var string
64
+	 */
65
+	protected $_html_help_text;
66
+
67
+	/**
68
+	 * CSS classes for displaying the help span
69
+	 *
70
+	 * @var string
71
+	 */
72
+	protected $_html_help_class = 'description';
73
+
74
+	/**
75
+	 * CSS to put in the style attribute on the help span
76
+	 *
77
+	 * @var string
78
+	 */
79
+	protected $_html_help_style;
80
+
81
+	/**
82
+	 * Stores whether this input's response is required.
83
+	 * Because certain styling elements may also want to know that this
84
+	 * input is required etc.
85
+	 *
86
+	 * @var boolean
87
+	 */
88
+	protected $_required;
89
+
90
+	/**
91
+	 * css class added to required inputs
92
+	 *
93
+	 * @var string
94
+	 */
95
+	protected $_required_css_class = 'ee-required';
96
+
97
+	/**
98
+	 * css styles applied to button type inputs
99
+	 *
100
+	 * @var string
101
+	 */
102
+	protected $_button_css_attributes;
103
+
104
+	/**
105
+	 * The raw post data submitted for this
106
+	 * Generally unsafe for usage in client code
107
+	 *
108
+	 * @var mixed string or array
109
+	 */
110
+	protected $_raw_value;
111
+
112
+	/**
113
+	 * Value normalized according to the input's normalization strategy.
114
+	 * The normalization strategy dictates whether this is a string, int, float,
115
+	 * boolean, or array of any of those.
116
+	 *
117
+	 * @var mixed
118
+	 */
119
+	protected $_normalized_value;
120
+
121
+
122
+	/**
123
+	 * Normalized default value either initially set on the input, or provided by calling
124
+	 * set_default().
125
+	 *
126
+	 * @var mixed
127
+	 */
128
+	protected $_default;
129
+
130
+	/**
131
+	 * Strategy used for displaying this field.
132
+	 * Child classes must use _get_display_strategy to access it.
133
+	 *
134
+	 * @var EE_Display_Strategy_Base
135
+	 */
136
+	private $_display_strategy;
137
+
138
+	/**
139
+	 * Gets all the validation strategies used on this field
140
+	 *
141
+	 * @var EE_Validation_Strategy_Base[]
142
+	 */
143
+	private $_validation_strategies = [];
144
+
145
+	/**
146
+	 * The normalization strategy for this field
147
+	 *
148
+	 * @var EE_Normalization_Strategy_Base
149
+	 */
150
+	private $_normalization_strategy;
151
+
152
+	/**
153
+	 * Strategy for removing sensitive data after we're done with the form input
154
+	 *
155
+	 * @var EE_Sensitive_Data_Removal_Base
156
+	 */
157
+	protected $_sensitive_data_removal_strategy;
158
+
159
+	/**
160
+	 * Whether this input has been disabled or not.
161
+	 * If it's disabled while rendering, an extra hidden input is added that indicates it has been knowingly disabled.
162
+	 * (Client-side code that wants to dynamically disable it must also add this hidden input).
163
+	 * When the form is submitted, if the input is disabled in the PHP form section, then input is ignored.
164
+	 * If the input is missing from the request data but the hidden input indicating the input is disabled, then the
165
+	 * input is again ignored.
166
+	 *
167
+	 * @var boolean
168
+	 */
169
+	protected $disabled = false;
170
+
171
+	protected array $_data_attributes = [];
172
+
173
+	protected bool $_no_label = false; // if true, then no HTML label will be displayed for this input
174
+
175
+	/**
176
+	 * adds a class to the input's container
177
+	 *
178
+	 * @var string
179
+	 */
180
+	protected string $_layout_container_class = '';
181
+
182
+	/**
183
+	 * additional HTML to inject into the input's container
184
+	 *
185
+	 * @var string
186
+	 */
187
+	protected string $_extra_container_html = '';
188
+
189
+
190
+	/**
191
+	 * @param array                         $input_args       {
192
+	 * @type string                         $html_name        the HTML name for the input
193
+	 * @type string                         $html_label_id    the id attribute to give to the HTML label tag
194
+	 * @type string                         $html_label_class the class attribute to give to the HTML label tag
195
+	 * @type string                         $html_label_style the style attribute to give ot the label tag
196
+	 * @type string                         $html_label_text  the text to put in the label tag
197
+	 * @type string                         $html_label       the full HTML label. If used,
198
+	 *                                                        all other html_label_* args are invalid
199
+	 * @type string                         $html_help_text   text to put in help element
200
+	 * @type string                         $html_help_style  style attribute to give to the help element
201
+	 * @type string                         $html_help_class  class attribute to give to the help element
202
+	 * @type string                         $default          default value NORMALIZED (eg, if providing the default
203
+	 *                                                        for a Yes_No_Input, you should provide TRUE or FALSE, not
204
+	 *                                                        '1' or '0')
205
+	 * @type EE_Display_Strategy_Base       $display          strategy
206
+	 * @type EE_Normalization_Strategy_Base $normalization_strategy
207
+	 * @type EE_Validation_Strategy_Base[]  $validation_strategies
208
+	 * @type boolean                        $ignore_input     special argument which can be used to avoid adding any
209
+	 *                                                        validation strategies, and sets the normalization
210
+	 *                                                        strategy to the Null normalization. This is good when you
211
+	 *                                                        want the input to be totally ignored server-side (like
212
+	 *                                                        when using React.js form inputs)
213
+	 *                                                        }
214
+	 */
215
+	public function __construct($input_args = [])
216
+	{
217
+		$input_args = (array) apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this);
218
+		// the following properties must be cast as arrays
219
+		if (isset($input_args['validation_strategies'])) {
220
+			foreach ((array) $input_args['validation_strategies'] as $validation_strategy) {
221
+				if ($validation_strategy instanceof EE_Validation_Strategy_Base && empty($input_args['ignore_input'])) {
222
+					$this->_validation_strategies[ get_class($validation_strategy) ] = $validation_strategy;
223
+				}
224
+			}
225
+			unset($input_args['validation_strategies']);
226
+		}
227
+		if (isset($input_args['ignore_input'])) {
228
+			$this->_validation_strategies = [];
229
+		}
230
+		// loop thru incoming options
231
+		foreach ($input_args as $key => $value) {
232
+			if ($key === 'disabled') {
233
+				$this->disable($value);
234
+				continue;
235
+			}
236
+			$setter = 'set_' . $key;
237
+			if (method_exists($this, $setter)) {
238
+				$this->$setter($value);
239
+				unset($input_args[ $key ]);
240
+				continue;
241
+			}
242
+			// add underscore to $key to match property names
243
+			$_key = "_$key";
244
+			if (property_exists($this, $_key)) {
245
+				$this->{$_key} = $value;
246
+				unset($input_args[ $key ]);
247
+			}
248
+		}
249
+		// ensure that "required" is set correctly
250
+		$this->set_required(
251
+			$this->_required,
252
+			$input_args['required_validation_error_message'] ?? null
253
+		);
254
+		// $this->_html_name_specified = isset( $input_args['html_name'] ) ? TRUE : FALSE;
255
+		$this->_display_strategy->_construct_finalize($this);
256
+		foreach ($this->_validation_strategies as $validation_strategy) {
257
+			$validation_strategy->_construct_finalize($this);
258
+		}
259
+		if (isset($input_args['ignore_input'])) {
260
+			$this->_normalization_strategy = new EE_Null_Normalization();
261
+		}
262
+		if (! $this->_normalization_strategy) {
263
+			$this->_normalization_strategy = new EE_Text_Normalization();
264
+		}
265
+		$this->_normalization_strategy->_construct_finalize($this);
266
+		// at least we can use the normalization strategy to populate the default
267
+		if (isset($input_args['default'])) {
268
+			$this->set_default($input_args['default']);
269
+			unset($input_args['default']);
270
+		}
271
+		if (! $this->_sensitive_data_removal_strategy) {
272
+			$this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal();
273
+		}
274
+		$this->_sensitive_data_removal_strategy->_construct_finalize($this);
275
+		parent::__construct($input_args);
276
+	}
277
+
278
+
279
+	/**
280
+	 * Sets the html_name to its default value, if none was specified in the constructor.
281
+	 * Calculation involves using the name and the parent's html_name
282
+	 *
283
+	 * @throws EE_Error
284
+	 */
285
+	protected function _set_default_html_name_if_empty()
286
+	{
287
+		if (! $this->_html_name) {
288
+			$this->_html_name = $this->name();
289
+			if ($this->_parent_section instanceof EE_Form_Section_Proper) {
290
+				$this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]";
291
+			}
292
+		}
293
+	}
294
+
295
+
296
+	/**
297
+	 * @param $parent_form_section
298
+	 * @param $name
299
+	 * @throws EE_Error
300
+	 */
301
+	public function _construct_finalize($parent_form_section, $name)
302
+	{
303
+		parent::_construct_finalize($parent_form_section, $name);
304
+		if ($this->_html_label === null && $this->_html_label_text === null && ! $this->_no_label) {
305
+			$this->_html_label_text = ucwords(str_replace("_", " ", $name));
306
+		}
307
+		do_action('AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name);
308
+	}
309
+
310
+
311
+	/**
312
+	 * Returns the strategy for displaying this form input. If none is set, throws an exception.
313
+	 *
314
+	 * @return EE_Display_Strategy_Base
315
+	 * @throws EE_Error
316
+	 */
317
+	protected function _get_display_strategy()
318
+	{
319
+		$this->ensure_construct_finalized_called();
320
+		if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) {
321
+			throw new EE_Error(
322
+				sprintf(
323
+					esc_html__(
324
+						"Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor",
325
+						"event_espresso"
326
+					),
327
+					$this->html_name(),
328
+					$this->html_id()
329
+				)
330
+			);
331
+		} else {
332
+			return $this->_display_strategy;
333
+		}
334
+	}
335
+
336
+
337
+	/**
338
+	 * Sets the display strategy.
339
+	 *
340
+	 * @param EE_Display_Strategy_Base $strategy
341
+	 */
342
+	protected function _set_display_strategy(EE_Display_Strategy_Base $strategy)
343
+	{
344
+		$this->_display_strategy = $strategy;
345
+	}
346
+
347
+
348
+	/**
349
+	 * Sets the sanitization strategy
350
+	 *
351
+	 * @param EE_Normalization_Strategy_Base $strategy
352
+	 */
353
+	protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy)
354
+	{
355
+		$this->_normalization_strategy = $strategy;
356
+	}
357
+
358
+
359
+	/**
360
+	 * Gets sensitive_data_removal_strategy
361
+	 *
362
+	 * @return EE_Sensitive_Data_Removal_Base
363
+	 */
364
+	public function get_sensitive_data_removal_strategy()
365
+	{
366
+		return $this->_sensitive_data_removal_strategy;
367
+	}
368
+
369
+
370
+	/**
371
+	 * Sets sensitive_data_removal_strategy
372
+	 *
373
+	 * @param EE_Sensitive_Data_Removal_Base $sensitive_data_removal_strategy
374
+	 * @return void
375
+	 */
376
+	public function set_sensitive_data_removal_strategy($sensitive_data_removal_strategy)
377
+	{
378
+		$this->_sensitive_data_removal_strategy = $sensitive_data_removal_strategy;
379
+	}
380
+
381
+
382
+	/**
383
+	 * Gets the display strategy for this input
384
+	 *
385
+	 * @return EE_Display_Strategy_Base
386
+	 */
387
+	public function get_display_strategy()
388
+	{
389
+		return $this->_display_strategy;
390
+	}
391
+
392
+
393
+	/**
394
+	 * Overwrites the display strategy
395
+	 *
396
+	 * @param EE_Display_Strategy_Base $display_strategy
397
+	 */
398
+	public function set_display_strategy($display_strategy)
399
+	{
400
+		$this->_display_strategy = $display_strategy;
401
+		$this->_display_strategy->_construct_finalize($this);
402
+	}
403
+
404
+
405
+	/**
406
+	 * Gets the normalization strategy set on this input
407
+	 *
408
+	 * @return EE_Normalization_Strategy_Base
409
+	 */
410
+	public function get_normalization_strategy()
411
+	{
412
+		return $this->_normalization_strategy;
413
+	}
414
+
415
+
416
+	/**
417
+	 * Overwrites the normalization strategy
418
+	 *
419
+	 * @param EE_Normalization_Strategy_Base $normalization_strategy
420
+	 */
421
+	public function set_normalization_strategy($normalization_strategy)
422
+	{
423
+		$this->_normalization_strategy = $normalization_strategy;
424
+		$this->_normalization_strategy->_construct_finalize($this);
425
+	}
426
+
427
+
428
+	/**
429
+	 * Returns all the validation strategies which apply to this field, numerically indexed
430
+	 *
431
+	 * @return EE_Validation_Strategy_Base[]
432
+	 */
433
+	public function get_validation_strategies()
434
+	{
435
+		return $this->_validation_strategies;
436
+	}
437
+
438
+
439
+	/**
440
+	 * Adds this strategy to the field so it will be used in both JS validation and server-side validation
441
+	 *
442
+	 * @param EE_Validation_Strategy_Base $validation_strategy
443
+	 * @return void
444
+	 */
445
+	protected function _add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy)
446
+	{
447
+		$validation_strategy->_construct_finalize($this);
448
+		$this->_validation_strategies[] = $validation_strategy;
449
+	}
450
+
451
+
452
+	/**
453
+	 * Adds a new validation strategy onto the form input
454
+	 *
455
+	 * @param EE_Validation_Strategy_Base $validation_strategy
456
+	 * @return void
457
+	 */
458
+	public function add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy)
459
+	{
460
+		$this->_add_validation_strategy($validation_strategy);
461
+	}
462
+
463
+
464
+	/**
465
+	 * The classname of the validation strategy to remove
466
+	 *
467
+	 * @param string $validation_strategy_classname
468
+	 */
469
+	public function remove_validation_strategy($validation_strategy_classname)
470
+	{
471
+		foreach ($this->_validation_strategies as $key => $validation_strategy) {
472
+			if (
473
+				$validation_strategy instanceof $validation_strategy_classname
474
+				|| is_subclass_of($validation_strategy, $validation_strategy_classname)
475
+			) {
476
+				unset($this->_validation_strategies[ $key ]);
477
+			}
478
+		}
479
+	}
480
+
481
+
482
+	public function removeAllValidationStrategies()
483
+	{
484
+		$this->_validation_strategies = [];
485
+	}
486
+
487
+
488
+	/**
489
+	 * returns true if input employs any of the validation strategy defined by the supplied array of classnames
490
+	 *
491
+	 * @param array $validation_strategy_classnames
492
+	 * @return bool
493
+	 */
494
+	public function has_validation_strategy($validation_strategy_classnames)
495
+	{
496
+		$validation_strategy_classnames = is_array($validation_strategy_classnames)
497
+			? $validation_strategy_classnames
498
+			: [$validation_strategy_classnames];
499
+		foreach ($this->_validation_strategies as $key => $validation_strategy) {
500
+			if (in_array($key, $validation_strategy_classnames)) {
501
+				return true;
502
+			}
503
+		}
504
+		return false;
505
+	}
506
+
507
+
508
+	/**
509
+	 * Gets the HTML
510
+	 *
511
+	 * @return string
512
+	 */
513
+	public function get_html()
514
+	{
515
+		return $this->_parent_section->get_html_for_input($this);
516
+	}
517
+
518
+
519
+	/**
520
+	 * Gets the HTML for the input itself (no label or errors) according to the
521
+	 * input's display strategy
522
+	 * Makes sure the JS and CSS are enqueued for it
523
+	 *
524
+	 * @return string
525
+	 * @throws EE_Error
526
+	 */
527
+	public function get_html_for_input()
528
+	{
529
+		return $this->_form_html_filter
530
+			? $this->_form_html_filter->filterHtml(
531
+				$this->_get_display_strategy()->display(),
532
+				$this
533
+			)
534
+			: $this->_get_display_strategy()->display();
535
+	}
536
+
537
+
538
+	/**
539
+	 * @return string
540
+	 */
541
+	public function html_other_attributes()
542
+	{
543
+		EE_Error::doing_it_wrong(
544
+			__METHOD__,
545
+			sprintf(
546
+				esc_html__(
547
+					'This method is no longer in use. You should replace it by %s',
548
+					'event_espresso'
549
+				),
550
+				'EE_Form_Section_Base::other_html_attributes()'
551
+			),
552
+			'4.10.2.p'
553
+		);
554
+
555
+		return $this->other_html_attributes();
556
+	}
557
+
558
+
559
+	/**
560
+	 * @param string $html_other_attributes
561
+	 */
562
+	public function set_html_other_attributes($html_other_attributes)
563
+	{
564
+		EE_Error::doing_it_wrong(
565
+			__METHOD__,
566
+			sprintf(
567
+				esc_html__(
568
+					'This method is no longer in use. You should replace it by %s',
569
+					'event_espresso'
570
+				),
571
+				'EE_Form_Section_Base::set_other_html_attributes()'
572
+			),
573
+			'4.10.2.p'
574
+		);
575
+
576
+		$this->set_other_html_attributes($html_other_attributes);
577
+	}
578
+
579
+
580
+	/**
581
+	 * Gets the HTML for displaying the label for this form input
582
+	 * according to the form section's layout strategy
583
+	 *
584
+	 * @return string
585
+	 * @throws EE_Error
586
+	 */
587
+	public function get_html_for_label()
588
+	{
589
+		return $this->_parent_section->get_layout_strategy()->display_label($this);
590
+	}
591
+
592
+
593
+	/**
594
+	 * Gets the HTML for displaying the errors section for this form input
595
+	 * according to the form section's layout strategy
596
+	 *
597
+	 * @return string
598
+	 * @throws EE_Error
599
+	 */
600
+	public function get_html_for_errors()
601
+	{
602
+		return $this->_parent_section->get_layout_strategy()->display_errors($this);
603
+	}
604
+
605
+
606
+	/**
607
+	 * Gets the HTML for displaying the help text for this form input
608
+	 * according to the form section's layout strategy
609
+	 *
610
+	 * @return string
611
+	 * @throws EE_Error
612
+	 */
613
+	public function get_html_for_help()
614
+	{
615
+		return $this->_parent_section->get_layout_strategy()->display_help_text($this);
616
+	}
617
+
618
+
619
+	/**
620
+	 * Validates the input's sanitized value (assumes _sanitize() has already been called)
621
+	 * and returns whether the form input's submitted value is value
622
+	 *
623
+	 * @return boolean
624
+	 */
625
+	protected function _validate()
626
+	{
627
+		if ($this->isDisabled()) {
628
+			return true;
629
+		}
630
+		foreach ($this->_validation_strategies as $validation_strategy) {
631
+			if ($validation_strategy instanceof EE_Validation_Strategy_Base) {
632
+				try {
633
+					$validation_strategy->validate($this->normalized_value());
634
+				} catch (EE_Validation_Error $e) {
635
+					$this->add_validation_error($e);
636
+				}
637
+			}
638
+		}
639
+		if ($this->get_validation_errors()) {
640
+			return false;
641
+		} else {
642
+			return true;
643
+		}
644
+	}
645
+
646
+
647
+	/**
648
+	 * Performs basic sanitization on this value. But what sanitization can be performed anyways?
649
+	 * This value MIGHT be allowed to have tags, so we can't really remove them.
650
+	 *
651
+	 * @param string $value
652
+	 * @return null|string
653
+	 */
654
+	protected function _sanitize($value)
655
+	{
656
+		return $value !== null
657
+			? stripslashes(html_entity_decode(trim((string) $value)))
658
+			: null;
659
+	}
660
+
661
+
662
+	/**
663
+	 * Picks out the form value that relates to this form input,
664
+	 * and stores it as the sanitized value on the form input, and sets the normalized value.
665
+	 * Returns whether any validation errors occurred
666
+	 *
667
+	 * @param array $req_data
668
+	 * @return boolean whether there was an error
669
+	 * @throws EE_Error
670
+	 */
671
+	protected function _normalize($req_data)
672
+	{
673
+		// any existing validation errors don't apply so clear them
674
+		$this->_validation_errors = [];
675
+		// if the input is disabled, ignore whatever input was sent in
676
+		if ($this->isDisabled()) {
677
+			$this->_set_raw_value(null);
678
+			$this->_set_normalized_value($this->get_default());
679
+			return false;
680
+		}
681
+		try {
682
+			$raw_input = $this->find_form_data_for_this_section($req_data);
683
+			// super simple sanitization for now
684
+			if (is_array($raw_input)) {
685
+				$raw_value = [];
686
+				foreach ($raw_input as $key => $value) {
687
+					$raw_value[ $key ] = $this->_sanitize($value);
688
+				}
689
+				$this->_set_raw_value($raw_value);
690
+			} else {
691
+				$this->_set_raw_value($this->_sanitize($raw_input));
692
+			}
693
+			// we want to mostly leave the input alone in case we need to re-display it to the user
694
+			$this->_set_normalized_value($this->_normalization_strategy->normalize($this->raw_value()));
695
+			return false;
696
+		} catch (EE_Validation_Error $e) {
697
+			$this->add_validation_error($e);
698
+			return true;
699
+		}
700
+	}
701
+
702
+
703
+	/**
704
+	 * @return string
705
+	 * @throws EE_Error
706
+	 */
707
+	public function html_name()
708
+	{
709
+		$this->_set_default_html_name_if_empty();
710
+		return $this->_html_name ?? '';
711
+	}
712
+
713
+
714
+	/**
715
+	 * @param string $html_label_id
716
+	 */
717
+	public function set_html_label_id(string $html_label_id)
718
+	{
719
+		// if the html_label_id doesn't end in -lbl, then add it
720
+		if (strpos($html_label_id, '-lbl') !== (strlen($html_label_id) - 4)) {
721
+			$html_label_id .= '-lbl';
722
+		}
723
+		$this->_html_label_id = $html_label_id;
724
+	}
725
+
726
+
727
+	/**
728
+	 * @return string
729
+	 * @throws EE_Error
730
+	 */
731
+	public function html_label_id()
732
+	{
733
+		if (empty($this->_html_label_id)) {
734
+			$this->set_html_label_id($this->html_id());
735
+		}
736
+		return $this->_html_label_id;
737
+	}
738
+
739
+
740
+	/**
741
+	 * @return string
742
+	 */
743
+	public function html_label_class()
744
+	{
745
+		return $this->_html_label_class ?? '';
746
+	}
747
+
748
+
749
+	/**
750
+	 * @param string $html_class
751
+	 */
752
+	public function add_html_label_class(string $html_class)
753
+	{
754
+		$this->_html_label_class .= ' ' . trim($html_class);
755
+	}
756
+
757
+
758
+	/**
759
+	 * @return string
760
+	 */
761
+	public function html_label_style()
762
+	{
763
+		return $this->_html_label_style ?? '';
764
+	}
765
+
766
+
767
+	/**
768
+	 * @return string
769
+	 */
770
+	public function html_label_text()
771
+	{
772
+		return $this->_html_label_text ?? '';
773
+	}
774
+
775
+
776
+	/**
777
+	 * @return string
778
+	 */
779
+	public function html_help_text()
780
+	{
781
+		return $this->_html_help_text ?? '';
782
+	}
783
+
784
+
785
+	/**
786
+	 * @return string
787
+	 */
788
+	public function html_help_class()
789
+	{
790
+		return $this->_html_help_class ?? '';
791
+	}
792
+
793
+
794
+	/**
795
+	 * @return string
796
+	 */
797
+	public function html_help_style()
798
+	{
799
+		return $this->_html_style ?? '';
800
+	}
801
+
802
+
803
+	/**
804
+	 * returns the raw, UNSAFE, input, almost exactly as the user submitted it.
805
+	 * Please note that almost all client code should instead use the normalized_value;
806
+	 * or possibly raw_value_in_form (which prepares the string for displaying in an HTML attribute on a tag,
807
+	 * mostly by escaping quotes)
808
+	 * Note, we do not store the exact original value sent in the user's request because
809
+	 * it may have malicious content, and we MIGHT want to store the form input in a transient or something...
810
+	 * in which case, we would have stored the malicious content to our database.
811
+	 *
812
+	 * @return mixed
813
+	 */
814
+	public function raw_value()
815
+	{
816
+		return $this->_raw_value;
817
+	}
818
+
819
+
820
+	/**
821
+	 * Returns a string safe to usage in form inputs when displaying, because
822
+	 * it escapes all HTML entities
823
+	 *
824
+	 * @return string
825
+	 */
826
+	public function raw_value_in_form(): string
827
+	{
828
+		return htmlentities((string) $this->raw_value(), ENT_QUOTES, 'UTF-8');
829
+	}
830
+
831
+
832
+	/**
833
+	 * returns the value after it's been sanitized, and then converted into it's proper type
834
+	 * in PHP. Eg, a string, an int, an array,
835
+	 *
836
+	 * @return mixed
837
+	 */
838
+	public function normalized_value()
839
+	{
840
+		return $this->_normalized_value;
841
+	}
842
+
843
+
844
+	/**
845
+	 * Returns the normalized value is a presentable way. By default this is just
846
+	 * the normalized value by itself, but it can be overridden for when that's not
847
+	 * the best thing to display
848
+	 *
849
+	 * @return mixed
850
+	 */
851
+	public function pretty_value()
852
+	{
853
+		return $this->_normalized_value;
854
+	}
855
+
856
+
857
+	/**
858
+	 * When generating the JS for the jquery validation rules like<br>
859
+	 * <code>$( "#myform" ).validate({
860
+	 * rules: {
861
+	 * password: "required",
862
+	 * password_again: {
863
+	 * equalTo: "#password"
864
+	 * }
865
+	 * }
866
+	 * });</code>
867
+	 * if this field had the name 'password_again', it should return
868
+	 * <br><code>password_again: {
869
+	 * equalTo: "#password"
870
+	 * }</code>
871
+	 *
872
+	 * @return array
873
+	 * @throws EE_Error
874
+	 */
875
+	public function get_jquery_validation_rules(): array
876
+	{
877
+		$jquery_validation_js    = [];
878
+		$jquery_validation_rules = [];
879
+		foreach ($this->get_validation_strategies() as $validation_strategy) {
880
+			$jquery_validation_rules = array_replace_recursive(
881
+				$jquery_validation_rules,
882
+				$validation_strategy->get_jquery_validation_rule_array()
883
+			);
884
+		}
885
+		if (! empty($jquery_validation_rules)) {
886
+			foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) {
887
+				$jquery_validation_js[ $html_id_with_pound_sign ] = $jquery_validation_rules;
888
+			}
889
+		}
890
+		return $jquery_validation_js;
891
+	}
892
+
893
+
894
+	/**
895
+	 * Sets the input's default value for use in displaying in the form. Note: value should be
896
+	 * normalized (Eg, if providing a default of ra Yes_NO_Input you would provide TRUE or FALSE, not '1' or '0')
897
+	 *
898
+	 * @param mixed $value
899
+	 * @return void
900
+	 */
901
+	public function set_default($value)
902
+	{
903
+		$this->_default = $value;
904
+		$this->_set_normalized_value($value);
905
+		$this->_set_raw_value($value);
906
+	}
907
+
908
+
909
+	/**
910
+	 * Sets the normalized value on this input
911
+	 *
912
+	 * @param mixed $value
913
+	 */
914
+	protected function _set_normalized_value($value)
915
+	{
916
+		$this->_normalized_value = $value;
917
+	}
918
+
919
+
920
+	/**
921
+	 * Sets the raw value on this input (ie, exactly as the user submitted it)
922
+	 *
923
+	 * @param mixed $value
924
+	 */
925
+	protected function _set_raw_value($value)
926
+	{
927
+		$this->_raw_value = $this->_normalization_strategy->unnormalize($value);
928
+	}
929
+
930
+
931
+	/**
932
+	 * Sets the HTML label text after it has already been defined
933
+	 *
934
+	 * @param string $label
935
+	 * @return void
936
+	 */
937
+	public function set_html_label_text($label)
938
+	{
939
+		$this->_html_label_text = $label;
940
+	}
941
+
942
+
943
+	/**
944
+	 * Sets whether this field is required, and adjusts the validation strategy.
945
+	 * If you want to use the EE_Conditionally_Required_Validation_Strategy,
946
+	 * please add it as a validation strategy using add_validation_strategy as normal
947
+	 *
948
+	 * @param boolean $required boolean
949
+	 * @param null    $required_text
950
+	 */
951
+	public function set_required($required = true, $required_text = null)
952
+	{
953
+		$required = filter_var($required, FILTER_VALIDATE_BOOLEAN);
954
+		// whether $required is a string or a boolean, we want to add a required validation strategy
955
+		if ($required) {
956
+			$this->_add_validation_strategy(new EE_Required_Validation_Strategy($required_text));
957
+		} else {
958
+			$this->remove_validation_strategy('EE_Required_Validation_Strategy');
959
+		}
960
+		$this->_required = $required;
961
+	}
962
+
963
+
964
+	/**
965
+	 * Returns whether this field is required
966
+	 *
967
+	 * @return boolean
968
+	 */
969
+	public function required()
970
+	{
971
+		return $this->_required;
972
+	}
973
+
974
+
975
+	/**
976
+	 * @param string $required_css_class
977
+	 */
978
+	public function set_required_css_class($required_css_class)
979
+	{
980
+		$this->_required_css_class = $required_css_class;
981
+	}
982
+
983
+
984
+	/**
985
+	 * @return string
986
+	 */
987
+	public function required_css_class()
988
+	{
989
+		return $this->_required_css_class;
990
+	}
991
+
992
+
993
+	/**
994
+	 * @param bool $add_required
995
+	 * @return string
996
+	 */
997
+	public function html_class($add_required = false)
998
+	{
999
+		return $add_required && $this->required()
1000
+			? $this->required_css_class() . ' ' . $this->_html_class
1001
+			: $this->_html_class;
1002
+	}
1003
+
1004
+
1005
+	/**
1006
+	 * Sets the help text, in case
1007
+	 *
1008
+	 * @param string $text
1009
+	 */
1010
+	public function set_html_help_text($text)
1011
+	{
1012
+		$this->_html_help_text = $text;
1013
+	}
1014
+
1015
+
1016
+	/**
1017
+	 * Uses the sensitive data removal strategy to remove the sensitive data from this
1018
+	 * input. If there is any kind of sensitive data removal on this input, we clear
1019
+	 * out the raw value completely
1020
+	 *
1021
+	 * @return void
1022
+	 */
1023
+	public function clean_sensitive_data()
1024
+	{
1025
+		// if we do ANY kind of sensitive data removal on this, then just clear out the raw value
1026
+		// if we need more logic than this we'll make a strategy for it
1027
+		if (
1028
+			$this->_sensitive_data_removal_strategy
1029
+			&& ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal
1030
+		) {
1031
+			$this->_set_raw_value(null);
1032
+		}
1033
+		// and clean the normalized value according to the appropriate strategy
1034
+		$this->_set_normalized_value(
1035
+			$this->get_sensitive_data_removal_strategy()->remove_sensitive_data(
1036
+				$this->_normalized_value
1037
+			)
1038
+		);
1039
+	}
1040
+
1041
+
1042
+	/**
1043
+	 * @param bool   $primary
1044
+	 * @param string $button_size
1045
+	 * @param string $other_attributes
1046
+	 */
1047
+	public function set_button_css_attributes($primary = true, $button_size = '', $other_attributes = '')
1048
+	{
1049
+		$button_css_attributes = 'button';
1050
+		$button_css_attributes .= $primary === true
1051
+			? ' button--primary'
1052
+			: ' button--secondary';
1053
+		switch ($button_size) {
1054
+			case 'xs':
1055
+			case 'extra-small':
1056
+				$button_css_attributes .= ' button-xs';
1057
+				break;
1058
+			case 'sm':
1059
+			case 'small':
1060
+				$button_css_attributes .= ' button-sm';
1061
+				break;
1062
+			case 'lg':
1063
+			case 'large':
1064
+				$button_css_attributes .= ' button-lg';
1065
+				break;
1066
+			case 'block':
1067
+				$button_css_attributes .= ' button-block';
1068
+				break;
1069
+			case 'md':
1070
+			case 'medium':
1071
+			default:
1072
+				$button_css_attributes .= '';
1073
+		}
1074
+		$this->_button_css_attributes .= ! empty($other_attributes)
1075
+			? $button_css_attributes . ' ' . $other_attributes
1076
+			: $button_css_attributes;
1077
+	}
1078
+
1079
+
1080
+	/**
1081
+	 * @return string
1082
+	 */
1083
+	public function button_css_attributes()
1084
+	{
1085
+		if (empty($this->_button_css_attributes)) {
1086
+			$this->set_button_css_attributes();
1087
+		}
1088
+		return $this->_button_css_attributes;
1089
+	}
1090
+
1091
+
1092
+	/**
1093
+	 * find_form_data_for_this_section
1094
+	 * using this section's name and its parents, finds the value of the form data that corresponds to it.
1095
+	 * For example, if this form section's HTML name is my_form[subform][form_input_1],
1096
+	 * then it's value should be in request at request['my_form']['subform']['form_input_1'].
1097
+	 * (If that doesn't exist, we also check for this subsection's name
1098
+	 * at the TOP LEVEL of the request data. Eg request['form_input_1'].)
1099
+	 * This function finds its value in the form.
1100
+	 *
1101
+	 * @param array $req_data
1102
+	 * @return mixed whatever the raw value of this form section is in the request data
1103
+	 * @throws EE_Error
1104
+	 */
1105
+	public function find_form_data_for_this_section($req_data)
1106
+	{
1107
+		$name_parts = $this->getInputNameParts();
1108
+		// now get the value for the input
1109
+		$value = $this->findRequestForSectionUsingNameParts($name_parts, $req_data);
1110
+		// check if this thing's name is at the TOP level of the request data
1111
+		if ($value === null && isset($req_data[ $this->name() ])) {
1112
+			$value = $req_data[ $this->name() ];
1113
+		}
1114
+		return $value;
1115
+	}
1116
+
1117
+
1118
+	/**
1119
+	 * If this input's name is something like "foo[bar][baz]"
1120
+	 * returns an array like `array('foo','bar',baz')`
1121
+	 *
1122
+	 * @return array
1123
+	 * @throws EE_Error
1124
+	 */
1125
+	protected function getInputNameParts(): array
1126
+	{
1127
+		// strip out ] brackets, then replace [ with . so we can explode
1128
+		$html_name = str_replace(
1129
+			[']', '['], // replace 1: ]  2: [
1130
+			['', '.'],  // with    1: '' 2: .
1131
+			$this->html_name()
1132
+		);
1133
+		return explode('.', $html_name);
1134
+	}
1135
+
1136
+
1137
+	/**
1138
+	 * @param array $html_name_parts
1139
+	 * @param array $req_data
1140
+	 * @return array | NULL
1141
+	 */
1142
+	public function findRequestForSectionUsingNameParts($html_name_parts, $req_data)
1143
+	{
1144
+		$first_part_to_consider = array_shift($html_name_parts);
1145
+		if (isset($req_data[ $first_part_to_consider ])) {
1146
+			if (empty($html_name_parts)) {
1147
+				return $req_data[ $first_part_to_consider ];
1148
+			} else {
1149
+				return $this->findRequestForSectionUsingNameParts(
1150
+					$html_name_parts,
1151
+					$req_data[ $first_part_to_consider ]
1152
+				);
1153
+			}
1154
+		}
1155
+		return null;
1156
+	}
1157
+
1158
+
1159
+	/**
1160
+	 * Checks if this form input's data is in the request data
1161
+	 *
1162
+	 * @param array $req_data
1163
+	 * @return boolean
1164
+	 * @throws EE_Error
1165
+	 */
1166
+	public function form_data_present_in($req_data = null)
1167
+	{
1168
+		if ($req_data === null) {
1169
+			/** @var RequestInterface $request */
1170
+			$request  = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1171
+			$req_data = $request->postParams();
1172
+		}
1173
+
1174
+		return $this->find_form_data_for_this_section($req_data) !== null;
1175
+	}
1176
+
1177
+
1178
+	/**
1179
+	 * Overrides parent to add js data from validation and display strategies
1180
+	 *
1181
+	 * @param array $form_other_js_data
1182
+	 * @return array
1183
+	 */
1184
+	public function get_other_js_data($form_other_js_data = [])
1185
+	{
1186
+		return $this->get_other_js_data_from_strategies($form_other_js_data);
1187
+	}
1188
+
1189
+
1190
+	/**
1191
+	 * Gets other JS data for localization from this input's strategies, like
1192
+	 * the validation strategies and the display strategy
1193
+	 *
1194
+	 * @param array $form_other_js_data
1195
+	 * @return array
1196
+	 */
1197
+	public function get_other_js_data_from_strategies($form_other_js_data = [])
1198
+	{
1199
+		$form_other_js_data = $this->get_display_strategy()->get_other_js_data($form_other_js_data);
1200
+		foreach ($this->get_validation_strategies() as $validation_strategy) {
1201
+			$form_other_js_data = $validation_strategy->get_other_js_data($form_other_js_data);
1202
+		}
1203
+		return $form_other_js_data;
1204
+	}
1205
+
1206
+
1207
+	/**
1208
+	 * Override parent because we want to give our strategies an opportunity to enqueue some js and css
1209
+	 *
1210
+	 * @return void
1211
+	 */
1212
+	public function enqueue_js()
1213
+	{
1214
+		// ask our display strategy and validation strategies if they have js to enqueue
1215
+		$this->enqueue_js_from_strategies();
1216
+	}
1217
+
1218
+
1219
+	/**
1220
+	 * Tells strategies when its ok to enqueue their js and css
1221
+	 *
1222
+	 * @return void
1223
+	 */
1224
+	public function enqueue_js_from_strategies()
1225
+	{
1226
+		$this->get_display_strategy()->enqueue_js();
1227
+		foreach ($this->get_validation_strategies() as $validation_strategy) {
1228
+			$validation_strategy->enqueue_js();
1229
+		}
1230
+	}
1231
+
1232
+
1233
+	/**
1234
+	 * Gets the default value set on the input (not the current value, which may have been
1235
+	 * changed because of a form submission). If no default was set, this us null.
1236
+	 *
1237
+	 * @return mixed
1238
+	 */
1239
+	public function get_default()
1240
+	{
1241
+		return $this->_default;
1242
+	}
1243
+
1244
+
1245
+	/**
1246
+	 * Makes this input disabled. That means it will have the HTML attribute 'disabled="disabled"',
1247
+	 * and server-side if any input was received it will be ignored
1248
+	 */
1249
+	public function disable($disable = true)
1250
+	{
1251
+		$disabled_attribute = ' disabled="disabled"';
1252
+		$this->disabled     = filter_var($disable, FILTER_VALIDATE_BOOLEAN);
1253
+		if ($this->disabled) {
1254
+			if (strpos($this->_other_html_attributes, $disabled_attribute) === false) {
1255
+				$this->_other_html_attributes .= $disabled_attribute;
1256
+			}
1257
+			$this->_set_normalized_value($this->get_default());
1258
+		} else {
1259
+			$this->_other_html_attributes = str_replace($disabled_attribute, '', $this->_other_html_attributes);
1260
+		}
1261
+	}
1262
+
1263
+
1264
+	/**
1265
+	 * Returns whether this input is currently disabled.
1266
+	 *
1267
+	 * @return bool
1268
+	 */
1269
+	public function isDisabled(): bool
1270
+	{
1271
+		return $this->disabled;
1272
+	}
1273
+
1274
+
1275
+	public function dataAttributes(): array
1276
+	{
1277
+		return $this->_data_attributes;
1278
+	}
1279
+
1280
+
1281
+	public function layoutContainerClass(): string
1282
+	{
1283
+		return $this->_layout_container_class;
1284
+	}
1285
+
1286
+
1287
+	public function extraContainerHtml(): string
1288
+	{
1289
+		return $this->_extra_container_html;
1290
+	}
1291
+
1292
+
1293
+	public function hasLabel(): bool
1294
+	{
1295
+		return ! $this->_no_label
1296
+			&& $this->html_label_text()
1297
+			&& ! $this->get_display_strategy() instanceof EE_Hidden_Display_Strategy;
1298
+	}
1299 1299
 }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
         if (isset($input_args['validation_strategies'])) {
220 220
             foreach ((array) $input_args['validation_strategies'] as $validation_strategy) {
221 221
                 if ($validation_strategy instanceof EE_Validation_Strategy_Base && empty($input_args['ignore_input'])) {
222
-                    $this->_validation_strategies[ get_class($validation_strategy) ] = $validation_strategy;
222
+                    $this->_validation_strategies[get_class($validation_strategy)] = $validation_strategy;
223 223
                 }
224 224
             }
225 225
             unset($input_args['validation_strategies']);
@@ -233,17 +233,17 @@  discard block
 block discarded – undo
233 233
                 $this->disable($value);
234 234
                 continue;
235 235
             }
236
-            $setter = 'set_' . $key;
236
+            $setter = 'set_'.$key;
237 237
             if (method_exists($this, $setter)) {
238 238
                 $this->$setter($value);
239
-                unset($input_args[ $key ]);
239
+                unset($input_args[$key]);
240 240
                 continue;
241 241
             }
242 242
             // add underscore to $key to match property names
243 243
             $_key = "_$key";
244 244
             if (property_exists($this, $_key)) {
245 245
                 $this->{$_key} = $value;
246
-                unset($input_args[ $key ]);
246
+                unset($input_args[$key]);
247 247
             }
248 248
         }
249 249
         // ensure that "required" is set correctly
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
         if (isset($input_args['ignore_input'])) {
260 260
             $this->_normalization_strategy = new EE_Null_Normalization();
261 261
         }
262
-        if (! $this->_normalization_strategy) {
262
+        if ( ! $this->_normalization_strategy) {
263 263
             $this->_normalization_strategy = new EE_Text_Normalization();
264 264
         }
265 265
         $this->_normalization_strategy->_construct_finalize($this);
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
             $this->set_default($input_args['default']);
269 269
             unset($input_args['default']);
270 270
         }
271
-        if (! $this->_sensitive_data_removal_strategy) {
271
+        if ( ! $this->_sensitive_data_removal_strategy) {
272 272
             $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal();
273 273
         }
274 274
         $this->_sensitive_data_removal_strategy->_construct_finalize($this);
@@ -284,10 +284,10 @@  discard block
 block discarded – undo
284 284
      */
285 285
     protected function _set_default_html_name_if_empty()
286 286
     {
287
-        if (! $this->_html_name) {
287
+        if ( ! $this->_html_name) {
288 288
             $this->_html_name = $this->name();
289 289
             if ($this->_parent_section instanceof EE_Form_Section_Proper) {
290
-                $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]";
290
+                $this->_html_name = $this->_parent_section->html_name_prefix()."[{$this->name()}]";
291 291
             }
292 292
         }
293 293
     }
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
     protected function _get_display_strategy()
318 318
     {
319 319
         $this->ensure_construct_finalized_called();
320
-        if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) {
320
+        if ( ! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) {
321 321
             throw new EE_Error(
322 322
                 sprintf(
323 323
                     esc_html__(
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
                 $validation_strategy instanceof $validation_strategy_classname
474 474
                 || is_subclass_of($validation_strategy, $validation_strategy_classname)
475 475
             ) {
476
-                unset($this->_validation_strategies[ $key ]);
476
+                unset($this->_validation_strategies[$key]);
477 477
             }
478 478
         }
479 479
     }
@@ -684,7 +684,7 @@  discard block
 block discarded – undo
684 684
             if (is_array($raw_input)) {
685 685
                 $raw_value = [];
686 686
                 foreach ($raw_input as $key => $value) {
687
-                    $raw_value[ $key ] = $this->_sanitize($value);
687
+                    $raw_value[$key] = $this->_sanitize($value);
688 688
                 }
689 689
                 $this->_set_raw_value($raw_value);
690 690
             } else {
@@ -751,7 +751,7 @@  discard block
 block discarded – undo
751 751
      */
752 752
     public function add_html_label_class(string $html_class)
753 753
     {
754
-        $this->_html_label_class .= ' ' . trim($html_class);
754
+        $this->_html_label_class .= ' '.trim($html_class);
755 755
     }
756 756
 
757 757
 
@@ -882,9 +882,9 @@  discard block
 block discarded – undo
882 882
                 $validation_strategy->get_jquery_validation_rule_array()
883 883
             );
884 884
         }
885
-        if (! empty($jquery_validation_rules)) {
885
+        if ( ! empty($jquery_validation_rules)) {
886 886
             foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) {
887
-                $jquery_validation_js[ $html_id_with_pound_sign ] = $jquery_validation_rules;
887
+                $jquery_validation_js[$html_id_with_pound_sign] = $jquery_validation_rules;
888 888
             }
889 889
         }
890 890
         return $jquery_validation_js;
@@ -997,7 +997,7 @@  discard block
 block discarded – undo
997 997
     public function html_class($add_required = false)
998 998
     {
999 999
         return $add_required && $this->required()
1000
-            ? $this->required_css_class() . ' ' . $this->_html_class
1000
+            ? $this->required_css_class().' '.$this->_html_class
1001 1001
             : $this->_html_class;
1002 1002
     }
1003 1003
 
@@ -1072,7 +1072,7 @@  discard block
 block discarded – undo
1072 1072
                 $button_css_attributes .= '';
1073 1073
         }
1074 1074
         $this->_button_css_attributes .= ! empty($other_attributes)
1075
-            ? $button_css_attributes . ' ' . $other_attributes
1075
+            ? $button_css_attributes.' '.$other_attributes
1076 1076
             : $button_css_attributes;
1077 1077
     }
1078 1078
 
@@ -1108,8 +1108,8 @@  discard block
 block discarded – undo
1108 1108
         // now get the value for the input
1109 1109
         $value = $this->findRequestForSectionUsingNameParts($name_parts, $req_data);
1110 1110
         // check if this thing's name is at the TOP level of the request data
1111
-        if ($value === null && isset($req_data[ $this->name() ])) {
1112
-            $value = $req_data[ $this->name() ];
1111
+        if ($value === null && isset($req_data[$this->name()])) {
1112
+            $value = $req_data[$this->name()];
1113 1113
         }
1114 1114
         return $value;
1115 1115
     }
@@ -1127,7 +1127,7 @@  discard block
 block discarded – undo
1127 1127
         // strip out ] brackets, then replace [ with . so we can explode
1128 1128
         $html_name = str_replace(
1129 1129
             [']', '['], // replace 1: ]  2: [
1130
-            ['', '.'],  // with    1: '' 2: .
1130
+            ['', '.'], // with    1: '' 2: .
1131 1131
             $this->html_name()
1132 1132
         );
1133 1133
         return explode('.', $html_name);
@@ -1142,13 +1142,13 @@  discard block
 block discarded – undo
1142 1142
     public function findRequestForSectionUsingNameParts($html_name_parts, $req_data)
1143 1143
     {
1144 1144
         $first_part_to_consider = array_shift($html_name_parts);
1145
-        if (isset($req_data[ $first_part_to_consider ])) {
1145
+        if (isset($req_data[$first_part_to_consider])) {
1146 1146
             if (empty($html_name_parts)) {
1147
-                return $req_data[ $first_part_to_consider ];
1147
+                return $req_data[$first_part_to_consider];
1148 1148
             } else {
1149 1149
                 return $this->findRequestForSectionUsingNameParts(
1150 1150
                     $html_name_parts,
1151
-                    $req_data[ $first_part_to_consider ]
1151
+                    $req_data[$first_part_to_consider]
1152 1152
                 );
1153 1153
             }
1154 1154
         }
Please login to merge, or discard this patch.
core/libraries/plugin_api/EE_Register_Addon.lib.php 2 patches
Indentation   +1264 added lines, -1264 removed lines patch added patch discarded remove patch
@@ -24,1268 +24,1268 @@
 block discarded – undo
24 24
  */
25 25
 class EE_Register_Addon implements EEI_Plugin_API
26 26
 {
27
-    /**
28
-     * possibly truncated version of the EE core version string
29
-     *
30
-     * @var string
31
-     */
32
-    protected static $_core_version = '';
33
-
34
-    /**
35
-     * Holds values for registered addons
36
-     *
37
-     * @var array
38
-     */
39
-    protected static $_settings = [];
40
-
41
-    /**
42
-     * @var  array $_incompatible_addons keys are addon SLUGS
43
-     *                                   (first argument passed to EE_Register_Addon::register()), keys are
44
-     *                                   their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004).
45
-     *                                   Generally this should be used sparingly, as we don't want to muddle up
46
-     *                                   EE core with knowledge of ALL the addons out there.
47
-     *                                   If you want NO versions of an addon to run with a certain version of core,
48
-     *                                   it's usually best to define the addon's "min_core_version" as part of its call
49
-     *                                   to EE_Register_Addon::register(), rather than using this array with a super
50
-     *                                   high value for its minimum plugin version.
51
-     */
52
-    protected static $_incompatible_addons = [
53
-        'Multi_Event_Registration' => '2.0.11.rc.002',
54
-        'Promotions'               => '1.0.0.rc.084',
55
-        'EE_WPUsers'               => '2.1.3.p',
56
-    ];
57
-
58
-    /**
59
-     * @var LoaderInterface
60
-     */
61
-    protected static $loader;
62
-
63
-
64
-    /**
65
-     * We should always be comparing core to a version like '4.3.0.rc.000',
66
-     * not just '4.3.0'.
67
-     * So if the addon developer doesn't provide that full version string,
68
-     * fill in the blanks for them
69
-     *
70
-     * @param string $min_core_version
71
-     * @return string always like '4.3.0.rc.000'
72
-     */
73
-    protected static function _effective_version(string $min_core_version): string
74
-    {
75
-        // versions: 4 . 3 . 1 . p . 123
76
-        // offsets:    0 . 1 . 2 . 3 . 4
77
-        $version_parts = explode('.', $min_core_version);
78
-        // check they specified the micro version (after 2nd period)
79
-        if (! isset($version_parts[2])) {
80
-            $version_parts[2] = '0';
81
-        }
82
-        // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible
83
-        // soon we can assume that's 'rc', but this current version is 'alpha'
84
-        if (! isset($version_parts[3])) {
85
-            $version_parts[3] = 'dev';
86
-        }
87
-        if (! isset($version_parts[4])) {
88
-            $version_parts[4] = '000';
89
-        }
90
-        return implode('.', $version_parts);
91
-    }
92
-
93
-
94
-    /**
95
-     * Returns whether or not the min core version requirement of the addon is met
96
-     *
97
-     * @param string $min_core_version    the minimum core version required by the addon
98
-     * @param string $actual_core_version the actual core version, optional
99
-     * @return bool
100
-     */
101
-    public static function _meets_min_core_version_requirement(
102
-        string $min_core_version,
103
-        string $actual_core_version = EVENT_ESPRESSO_VERSION
104
-    ): bool {
105
-        return version_compare(
106
-            self::_effective_version($actual_core_version),
107
-            self::_effective_version($min_core_version),
108
-            '>='
109
-        );
110
-    }
111
-
112
-
113
-    /**
114
-     * Method for registering new EE_Addons.
115
-     * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE
116
-     * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it
117
-     * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon
118
-     * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after
119
-     * 'activate_plugin', it registers the addon still, but its components are not registered
120
-     * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do
121
-     * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns
122
-     * (so that we can detect that the addon has activated on the subsequent request)
123
-     *
124
-     * @param string                  $addon_name                       [Required] the EE_Addon's name.
125
-     * @param array                   $setup_args                       {
126
-     *                                                                  An array of arguments provided for registering
127
-     *                                                                  the message type.
128
-     * @type  string                  $class_name                       the addon's main file name.
129
-     *                                                                  If left blank, generated from the addon name,
130
-     *                                                                  changes something like "calendar" to
131
-     *                                                                  "EE_Calendar"
132
-     * @type string                   $min_core_version                 the minimum version of EE Core that the
133
-     *                                                                  addon will work with. eg "4.8.1.rc.084"
134
-     * @type string                   $version                          the "software" version for the addon. eg
135
-     *                                                                  "1.0.0.p" for a first stable release, or
136
-     *                                                                  "1.0.0.rc.043" for a version in progress
137
-     * @type string                   $main_file_path                   the full server path to the main file
138
-     *                                                                  loaded directly by WP
139
-     * @type DomainInterface          $domain                           child class of
140
-     *                                                                  EventEspresso\core\domain\DomainBase
141
-     * @type string                   $domain_fqcn                      Fully Qualified Class Name
142
-     *                                                                  for the addon's Domain class
143
-     *                                                                  (see EventEspresso\core\domain\Domain)
144
-     * @type string                   $admin_path                       full server path to the folder where the
145
-     *                                                                  addon\'s admin files reside
146
-     * @type string                   $admin_callback                   a method to be called when the EE Admin is
147
-     *                                                                  first invoked, can be used for hooking into
148
-     *                                                                  any admin page
149
-     * @type string                   $config_section                   the section name for this addon's
150
-     *                                                                  configuration settings section
151
-     *                                                                  (defaults to "addons")
152
-     * @type string                   $config_class                     the class name for this addon's
153
-     *                                                                  configuration settings object
154
-     * @type string                   $config_name                      the class name for this addon's
155
-     *                                                                  configuration settings object
156
-     * @type string                   $autoloader_paths                 [Required] an array of class names and the full
157
-     *                                                                  server paths to those files.
158
-     * @type string                   $autoloader_folders               an array of  "full server paths" for any
159
-     *                                                                  folders containing classes that might be
160
-     *                                                                  invoked by the addon
161
-     * @type string                   $dms_paths                        [Required] an array of full server paths to
162
-     *                                                                  folders that contain data migration scripts.
163
-     *                                                                  The key should be the EE_Addon class name that
164
-     *                                                                  this set of data migration scripts belongs to.
165
-     *                                                                  If the EE_Addon class is namespaced, then this
166
-     *                                                                  needs to be the Fully Qualified Class Name
167
-     * @type string                   $module_paths                     an array of full server paths to any
168
-     *                                                                  EED_Modules used by the addon
169
-     * @type string                   $shortcode_paths                  an array of full server paths to folders
170
-     *                                                                  that contain EES_Shortcodes
171
-     * @type string                   $widget_paths                     an array of full server paths to folders
172
-     *                                                                  that contain WP_Widgets
173
-     * @type array                    $capabilities                     an array indexed by role name
174
-     *                                                                  (i.e administrator,author ) and the values
175
-     *                                                                  are an array of caps to add to the role.
176
-     *                                                                  'administrator' => array(
177
-     *                                                                  'read_addon',
178
-     *                                                                  'edit_addon',
179
-     *                                                                  etc.
180
-     *                                                                  ).
181
-     * @type EE_Meta_Capability_Map[] $capability_maps                  an array of EE_Meta_Capability_Map object
182
-     *                                                                  for any addons that need to register any
183
-     *                                                                  special meta mapped capabilities.  Should
184
-     *                                                                  be indexed where the key is the
185
-     *                                                                  EE_Meta_Capability_Map class name and the
186
-     *                                                                  values are the arguments sent to the class.
187
-     * @type array                    $model_paths                      array of folders containing DB models
188
-     * @return bool
189
-     * @throws DomainException
190
-     * @throws EE_Error
191
-     * @throws InvalidArgumentException
192
-     * @throws InvalidDataTypeException
193
-     * @throws InvalidInterfaceException
194
-     * @since                                                           4.3.0
195
-     * @see                                                             EE_Register_Model
196
-     * @type array                    $class_paths                      array of folders containing DB classes
197
-     * @see                                                             EE_Register_Model
198
-     * @type array                    $model_extension_paths            array of folders containing DB model
199
-     *                                                                  extensions
200
-     * @see                                                             EE_Register_Model_Extension
201
-     * @type array                    $class_extension_paths            array of folders containing DB class
202
-     *                                                                  extensions
203
-     * @see                                                             EE_Register_Model_Extension
204
-     * @type array message_types {
205
-     *                                                                  An array of message types with the key as
206
-     *                                                                  the message type name and the values as
207
-     *                                                                  below:
208
-     * @type string                   $mtfilename                       [Required] The filename of the message type
209
-     *                                                                  being registered. This will be the main
210
-     *                                                                  EE_{Message Type Name}_message_type class.
211
-     *                                                                  for example:
212
-     *                                                                  EE_Declined_Registration_message_type.class.php
213
-     * @type array                    $autoloadpaths                    [Required] An array of paths to add to the
214
-     *                                                                  messages autoloader for the new message type.
215
-     * @type array                    $messengers_to_activate_with      An array of messengers that this message
216
-     *                                                                  type should activate with. Each value in
217
-     *                                                                  the
218
-     *                                                                  array
219
-     *                                                                  should match the name property of a
220
-     *                                                                  EE_messenger. Optional.
221
-     * @type array                    $messengers_to_validate_with      An array of messengers that this message
222
-     *                                                                  type should validate with. Each value in
223
-     *                                                                  the
224
-     *                                                                  array
225
-     *                                                                  should match the name property of an
226
-     *                                                                  EE_messenger.
227
-     *                                                                  Optional.
228
-     *                                                                  }
229
-     * @type array                    $custom_post_types
230
-     * @type array                    $custom_taxonomies
231
-     * @type array                    $payment_method_paths             each element is the folder containing the
232
-     *                                                                  EE_PMT_Base child class
233
-     *                                                                  (eg,
234
-     *                                                                  '/wp-content/plugins/my_plugin/Payomatic/'
235
-     *                                                                  which contains the files
236
-     *                                                                  EE_PMT_Payomatic.pm.php)
237
-     * @type array                    $default_terms
238
-     * @type array                    $namespace                        {
239
-     *                                                                  An array with two items for registering the
240
-     *                                                                  addon's namespace. (If, for some reason, you
241
-     *                                                                  require additional namespaces,
242
-     *                                                                  use
243
-     *                                                                  EventEspresso\core\Psr4Autoloader::addNamespace()
244
-     *                                                                  directly)
245
-     * @see                                                             EventEspresso\core\Psr4Autoloader::addNamespace()
246
-     * @type string                   $FQNS                             the namespace prefix
247
-     * @type string                   $DIR                              a base directory for class files in the
248
-     *                                                                  namespace.
249
-     *                                                                  }
250
-     *                                                                  }
251
-     * @type string                   $privacy_policies                 FQNSs (namespaces, each of which contains only
252
-     *                                                                  privacy policy classes) or FQCNs (specific
253
-     *                                                                  classnames of privacy policy classes)
254
-     * @type string                   $personal_data_exporters          FQNSs (namespaces, each of which contains only
255
-     *                                                                  privacy policy classes) or FQCNs (specific
256
-     *                                                                  classnames of privacy policy classes)
257
-     * @type string                   $personal_data_erasers            FQNSs (namespaces, each of which contains only
258
-     *                                                                  privacy policy classes) or FQCNs (specific
259
-     *                                                                  classnames of privacy policy classes)
260
-     */
261
-    public static function register(string $addon_name = '', array $setup_args = []): bool
262
-    {
263
-        // $addon_name = basename($addon_name);
264
-        if (! self::$loader instanceof LoaderInterface) {
265
-            self::$loader = LoaderFactory::getLoader();
266
-        }
267
-        // make sure this was called in the right place!
268
-        if (
269
-            ! did_action('activate_plugin')
270
-            && (
271
-                ! did_action('AHEE__EE_System__load_espresso_addons')
272
-                || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
273
-            )
274
-        ) {
275
-            EE_Error::doing_it_wrong(
276
-                __METHOD__,
277
-                sprintf(
278
-                    esc_html__(
279
-                        'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.',
280
-                        'event_espresso'
281
-                    ),
282
-                    $addon_name
283
-                ),
284
-                '4.3.0'
285
-            );
286
-            return false;
287
-        }
288
-        // required fields MUST be present, so let's make sure they are.
289
-        EE_Register_Addon::_verify_parameters($addon_name, $setup_args);
290
-        // get class name for addon
291
-        $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args);
292
-        // setup $_settings array from incoming values.
293
-        $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args);
294
-        // allow early addon setup or modification of addon api settings
295
-        self::$_settings = (array) apply_filters(
296
-            'FHEE__EE_Register_Addon__register',
297
-            self::$_settings,
298
-            $addon_name,
299
-            $class_name,
300
-            $setup_args
301
-        );
302
-        // does this addon work with this version of core or WordPress ?
303
-        // does this addon work with this version of core or WordPress ?
304
-        if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
305
-            return false;
306
-        }
307
-        // register namespaces
308
-        EE_Register_Addon::_setup_namespaces($addon_settings);
309
-        // check if this is an activation request
310
-        if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) {
311
-            // dont bother setting up the rest of the addon atm
312
-            return false;
313
-        }
314
-        // we need cars
315
-        EE_Register_Addon::_setup_autoloaders($addon_name);
316
-        // register new models and extensions
317
-        EE_Register_Addon::_register_models_and_extensions($addon_name);
318
-        // setup DMS
319
-        EE_Register_Addon::_register_data_migration_scripts($addon_name);
320
-        // if config_class is present let's register config.
321
-        EE_Register_Addon::_register_config($addon_name);
322
-        // register admin pages
323
-        EE_Register_Addon::_register_admin_pages($addon_name);
324
-        // add to list of modules to be registered
325
-        EE_Register_Addon::_register_modules($addon_name);
326
-        // add to list of shortcodes to be registered
327
-        EE_Register_Addon::_register_shortcodes($addon_name);
328
-        // add to list of widgets to be registered
329
-        EE_Register_Addon::_register_widgets($addon_name);
330
-        // register capability related stuff.
331
-        EE_Register_Addon::_register_capabilities($addon_name);
332
-        // any message type to register?
333
-        EE_Register_Addon::_register_message_types($addon_name);
334
-        // any custom post type/ custom capabilities or default terms to register
335
-        EE_Register_Addon::_register_custom_post_types($addon_name);
336
-        // and any payment methods
337
-        EE_Register_Addon::_register_payment_methods($addon_name);
338
-        // and privacy policy generators
339
-        EE_Register_Addon::registerPrivacyPolicies($addon_name);
340
-        // and privacy policy generators
341
-        EE_Register_Addon::registerPersonalDataExporters($addon_name);
342
-        // and privacy policy generators
343
-        EE_Register_Addon::registerPersonalDataErasers($addon_name);
344
-        EE_Register_Addon::registerLicense($addon_name);
345
-        // load and instantiate main addon class
346
-        $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name);
347
-        // delay calling after_registration hook on each addon until after all add-ons have been registered.
348
-        add_action('AHEE__EE_System__load_espresso_addons__complete', [$addon, 'after_registration'], 999);
349
-        return $addon instanceof EE_Addon;
350
-    }
351
-
352
-
353
-    /**
354
-     * @param string $addon_name
355
-     * @param array  $setup_args
356
-     * @return void
357
-     * @throws EE_Error
358
-     */
359
-    private static function _verify_parameters(string $addon_name, array $setup_args)
360
-    {
361
-        // required fields MUST be present, so let's make sure they are.
362
-        if (empty($addon_name) || empty($setup_args)) {
363
-            throw new EE_Error(
364
-                esc_html__(
365
-                    'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.',
366
-                    'event_espresso'
367
-                )
368
-            );
369
-        }
370
-        if (empty($setup_args['main_file_path'])) {
371
-            throw new EE_Error(
372
-                sprintf(
373
-                    esc_html__(
374
-                        'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s',
375
-                        'event_espresso'
376
-                    ),
377
-                    implode(',', array_keys($setup_args))
378
-                )
379
-            );
380
-        }
381
-        // check that addon has not already been registered with that name
382
-        if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) {
383
-            throw new EE_Error(
384
-                sprintf(
385
-                    esc_html__(
386
-                        'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.',
387
-                        'event_espresso'
388
-                    ),
389
-                    $addon_name
390
-                )
391
-            );
392
-        }
393
-    }
394
-
395
-
396
-    /**
397
-     * @param string $addon_name
398
-     * @param array  $setup_args
399
-     * @return string
400
-     */
401
-    private static function _parse_class_name(string $addon_name, array $setup_args): string
402
-    {
403
-        if (empty($setup_args['class_name'])) {
404
-            // generate one by first separating name with spaces
405
-            $class_name = str_replace(['-', '_'], ' ', trim($addon_name));
406
-            // capitalize, then replace spaces with underscores
407
-            $class_name = str_replace(' ', '_', ucwords($class_name));
408
-        } else {
409
-            $class_name = $setup_args['class_name'];
410
-        }
411
-        // check if classname is fully  qualified or is a legacy classname already prefixed with 'EE_'
412
-        return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0
413
-            ? $class_name
414
-            : 'EE_' . $class_name;
415
-    }
416
-
417
-
418
-    /**
419
-     * @param string $class_name
420
-     * @param array  $setup_args
421
-     * @return array
422
-     */
423
-    private static function _get_addon_settings(string $class_name, array $setup_args): array
424
-    {
425
-        // setup $_settings array from incoming values.
426
-        $addon_settings = [
427
-            // generated from the addon name, changes something like "calendar" to "EE_Calendar"
428
-            'class_name'            => $class_name,
429
-            // the addon slug for use in URLs, etc
430
-            'plugin_slug'           => isset($setup_args['plugin_slug'])
431
-                ? (string) $setup_args['plugin_slug']
432
-                : sanitize_key($class_name),
433
-            // page slug to be used when generating the "Settings" link on the WP plugin page
434
-            'plugin_action_slug'    => isset($setup_args['plugin_action_slug'])
435
-                ? (string) $setup_args['plugin_action_slug']
436
-                : '',
437
-            // the "software" version for the addon
438
-            'version'               => isset($setup_args['version'])
439
-                ? (string) $setup_args['version']
440
-                : '',
441
-            // the minimum version of EE Core that the addon will work with
442
-            'min_core_version'      => isset($setup_args['min_core_version'])
443
-                ? (string) $setup_args['min_core_version']
444
-                : '',
445
-            // the minimum version of WordPress that the addon will work with
446
-            'min_wp_version'        => isset($setup_args['min_wp_version'])
447
-                ? (string) $setup_args['min_wp_version']
448
-                : EE_MIN_WP_VER_REQUIRED,
449
-            // full server path to main file (file loaded directly by WP)
450
-            'main_file_path'        => isset($setup_args['main_file_path'])
451
-                ? (string) $setup_args['main_file_path']
452
-                : '',
453
-            // instance of \EventEspresso\core\domain\DomainInterface
454
-            'domain'                => isset($setup_args['domain']) && $setup_args['domain'] instanceof DomainInterface
455
-                ? $setup_args['domain']
456
-                : null,
457
-            // Fully Qualified Class Name for the addon's Domain class
458
-            'domain_fqcn'           => isset($setup_args['domain_fqcn'])
459
-                ? (string) $setup_args['domain_fqcn']
460
-                : '',
461
-            // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages
462
-            'admin_path'            => isset($setup_args['admin_path'])
463
-                ? (string) $setup_args['admin_path']
464
-                : '',
465
-            // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page
466
-            'admin_callback'        => isset($setup_args['admin_callback'])
467
-                ? (string) $setup_args['admin_callback']
468
-                : '',
469
-            // the section name for this addon's configuration settings section (defaults to "addons")
470
-            'config_section'        => isset($setup_args['config_section'])
471
-                ? (string) $setup_args['config_section']
472
-                : 'addons',
473
-            // the class name for this addon's configuration settings object
474
-            'config_class'          => isset($setup_args['config_class'])
475
-                ? (string) $setup_args['config_class']
476
-                : '',
477
-            // the name given to the config for this addons' configuration settings object (optional)
478
-            'config_name'           => isset($setup_args['config_name'])
479
-                ? (string) $setup_args['config_name']
480
-                : '',
481
-            // an array of "class names" => "full server paths" for any classes that might be invoked by the addon
482
-            'autoloader_paths'      => isset($setup_args['autoloader_paths'])
483
-                ? (array) $setup_args['autoloader_paths']
484
-                : [],
485
-            // an array of  "full server paths" for any folders containing classes that might be invoked by the addon
486
-            'autoloader_folders'    => isset($setup_args['autoloader_folders'])
487
-                ? (array) $setup_args['autoloader_folders']
488
-                : [],
489
-            // array of full server paths to any EE_DMS data migration scripts used by the addon.
490
-            // The key should be the EE_Addon class name that this set of data migration scripts belongs to.
491
-            // If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name
492
-            'dms_paths'             => isset($setup_args['dms_paths'])
493
-                ? (array) $setup_args['dms_paths']
494
-                : [],
495
-            // array of full server paths to any EED_Modules used by the addon
496
-            'module_paths'          => isset($setup_args['module_paths'])
497
-                ? (array) $setup_args['module_paths']
498
-                : [],
499
-            // array of full server paths to any EES_Shortcodes used by the addon
500
-            'shortcode_paths'       => isset($setup_args['shortcode_paths'])
501
-                ? (array) $setup_args['shortcode_paths']
502
-                : [],
503
-            'shortcode_fqcns'       => isset($setup_args['shortcode_fqcns'])
504
-                ? (array) $setup_args['shortcode_fqcns']
505
-                : [],
506
-            // array of full server paths to any WP_Widgets used by the addon
507
-            'widget_paths'          => isset($setup_args['widget_paths'])
508
-                ? (array) $setup_args['widget_paths']
509
-                : [],
510
-            'message_types'         => isset($setup_args['message_types'])
511
-                ? (array) $setup_args['message_types']
512
-                : [],
513
-            'capabilities'          => isset($setup_args['capabilities'])
514
-                ? (array) $setup_args['capabilities']
515
-                : [],
516
-            'capability_maps'       => isset($setup_args['capability_maps'])
517
-                ? (array) $setup_args['capability_maps']
518
-                : [],
519
-            'model_paths'           => isset($setup_args['model_paths'])
520
-                ? (array) $setup_args['model_paths']
521
-                : [],
522
-            'class_paths'           => isset($setup_args['class_paths'])
523
-                ? (array) $setup_args['class_paths']
524
-                : [],
525
-            'model_extension_paths' => isset($setup_args['model_extension_paths'])
526
-                ? (array) $setup_args['model_extension_paths']
527
-                : [],
528
-            'class_extension_paths' => isset($setup_args['class_extension_paths'])
529
-                ? (array) $setup_args['class_extension_paths']
530
-                : [],
531
-            'custom_post_types'     => isset($setup_args['custom_post_types'])
532
-                ? (array) $setup_args['custom_post_types']
533
-                : [],
534
-            'custom_taxonomies'     => isset($setup_args['custom_taxonomies'])
535
-                ? (array) $setup_args['custom_taxonomies']
536
-                : [],
537
-            'payment_method_paths'  => isset($setup_args['payment_method_paths'])
538
-                ? (array) $setup_args['payment_method_paths']
539
-                : [],
540
-            'default_terms'         => isset($setup_args['default_terms'])
541
-                ? (array) $setup_args['default_terms']
542
-                : [],
543
-            // if not empty, inserts a new table row after this plugin's row on the WP Plugins page
544
-            // that can be used for adding upgrading/marketing info
545
-            'plugins_page_row'      => isset($setup_args['plugins_page_row'])
546
-                ? (array) $setup_args['plugins_page_row']
547
-                : [],
548
-            'namespace'             => isset(
549
-                $setup_args['namespace']['FQNS'],
550
-                $setup_args['namespace']['DIR']
551
-            )
552
-                ? (array) $setup_args['namespace']
553
-                : [],
554
-            'privacy_policies'      => isset($setup_args['privacy_policies'])
555
-                ? (array) $setup_args['privacy_policies']
556
-                : [],
557
-            'license'               => isset($setup_args['license'])
558
-                ? (array) $setup_args['license']
559
-                : [],
560
-        ];
561
-        // if plugin_action_slug is NOT set, but an admin page path IS set,
562
-        // then let's just use the plugin_slug since that will be used for linking to the admin page
563
-        $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug'])
564
-                                                && ! empty($addon_settings['admin_path'])
565
-            ? $addon_settings['plugin_slug']
566
-            : $addon_settings['plugin_action_slug'];
567
-        // full server path to main file (file loaded directly by WP)
568
-        $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']);
569
-        return $addon_settings;
570
-    }
571
-
572
-
573
-    /**
574
-     * @param string $addon_name
575
-     * @param array  $addon_settings
576
-     * @return bool
577
-     */
578
-    private static function _addon_is_compatible(string $addon_name, array $addon_settings): bool
579
-    {
580
-        global $wp_version;
581
-        $incompatibility_message = '';
582
-        // check whether this addon version is compatible with EE core
583
-        if (
584
-            isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ])
585
-            && ! self::_meets_min_core_version_requirement(
586
-                EE_Register_Addon::$_incompatible_addons[ $addon_name ],
587
-                $addon_settings['version']
588
-            )
589
-        ) {
590
-            $incompatibility_message = sprintf(
591
-                esc_html__(
592
-                    '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.',
593
-                    'event_espresso'
594
-                ),
595
-                $addon_name,
596
-                '<br />',
597
-                EE_Register_Addon::$_incompatible_addons[ $addon_name ],
598
-                '<span style="font-weight: bold; color: #D54E21;">',
599
-                '</span><br />'
600
-            );
601
-        } elseif (
602
-            ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version())
603
-        ) {
604
-            $incompatibility_message = sprintf(
605
-                esc_html__(
606
-                    '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".',
607
-                    'event_espresso'
608
-                ),
609
-                $addon_name,
610
-                self::_effective_version($addon_settings['min_core_version']),
611
-                self::_effective_version(espresso_version()),
612
-                '<br />',
613
-                '<span style="font-weight: bold; color: #D54E21;">',
614
-                '</span><br />'
615
-            );
616
-        } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) {
617
-            $incompatibility_message = sprintf(
618
-                esc_html__(
619
-                    '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.',
620
-                    'event_espresso'
621
-                ),
622
-                $addon_name,
623
-                $addon_settings['min_wp_version'],
624
-                '<br />',
625
-                '<span style="font-weight: bold; color: #D54E21;">',
626
-                '</span><br />'
627
-            );
628
-        }
629
-        if (! empty($incompatibility_message)) {
630
-            // remove 'activate' from the REQUEST
631
-            // so WP doesn't erroneously tell the user the plugin activated fine when it didn't
632
-            /** @var RequestInterface $request */
633
-            $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
634
-            $request->unSetRequestParam('activate', true);
635
-            if (current_user_can('activate_plugins')) {
636
-                // show an error message indicating the plugin didn't activate properly
637
-                EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__);
638
-            }
639
-            unset($_GET['activate'], $_REQUEST['activate']);
640
-            if (! function_exists('deactivate_plugins')) {
641
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
642
-            }
643
-            deactivate_plugins(plugin_basename($addon_settings['main_file_path']));
644
-            // BAIL FROM THE ADDON REGISTRATION PROCESS
645
-            return false;
646
-        }
647
-        // addon IS compatible
648
-        return true;
649
-    }
650
-
651
-
652
-    /**
653
-     * register namespaces right away before any other files or classes get loaded, but AFTER the version checks
654
-     *
655
-     * @param array $addon_settings
656
-     * @return void
657
-     * @throws EE_Error
658
-     */
659
-    private static function _setup_namespaces(array $addon_settings)
660
-    {
661
-        //
662
-        if (
663
-            isset(
664
-                $addon_settings['namespace']['FQNS'],
665
-                $addon_settings['namespace']['DIR']
666
-            )
667
-        ) {
668
-            EE_Psr4AutoloaderInit::psr4_loader()->addNamespace(
669
-                $addon_settings['namespace']['FQNS'],
670
-                $addon_settings['namespace']['DIR']
671
-            );
672
-        }
673
-    }
674
-
675
-
676
-    /**
677
-     * @param string $addon_name
678
-     * @param array  $addon_settings
679
-     * @return bool
680
-     * @throws InvalidArgumentException
681
-     * @throws InvalidDataTypeException
682
-     * @throws InvalidInterfaceException
683
-     */
684
-    private static function _addon_activation(string $addon_name, array $addon_settings): bool
685
-    {
686
-        // this is an activation request
687
-        if (did_action('activate_plugin')) {
688
-            // to find if THIS is the addon that was activated, just check if we have already registered it or not
689
-            // (as the newly-activated addon wasn't around the first time addons were registered).
690
-            if (
691
-                ! isset(self::$_settings[ $addon_name ])
692
-                || (isset(self::$_settings[ $addon_name ])
693
-                    && ! isset(self::$_settings[ $addon_name ]['class_name'])
694
-                )
695
-            ) {
696
-                self::$_settings[ $addon_name ] = $addon_settings;
697
-                $addon                          = self::_load_and_init_addon_class($addon_name);
698
-                $addon->set_activation_indicator_option();
699
-                // dont bother setting up the rest of the addon.
700
-                // we know it was just activated and the request will end soon
701
-            }
702
-            return true;
703
-        }
704
-        // make sure addon settings are set correctly without overwriting anything existing
705
-        if (isset(self::$_settings[ $addon_name ])) {
706
-            self::$_settings[ $addon_name ] += $addon_settings;
707
-        } else {
708
-            self::$_settings[ $addon_name ] = $addon_settings;
709
-        }
710
-        return false;
711
-    }
712
-
713
-
714
-    /**
715
-     * @param string $addon_name
716
-     * @return void
717
-     * @throws EE_Error
718
-     */
719
-    private static function _setup_autoloaders(string $addon_name)
720
-    {
721
-        if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) {
722
-            // setup autoloader for single file
723
-            EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']);
724
-        }
725
-        // setup autoloaders for folders
726
-        if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) {
727
-            foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) {
728
-                EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
729
-            }
730
-        }
731
-    }
732
-
733
-
734
-    /**
735
-     * register new models and extensions
736
-     *
737
-     * @param string $addon_name
738
-     * @return void
739
-     * @throws EE_Error
740
-     */
741
-    private static function _register_models_and_extensions(string $addon_name)
742
-    {
743
-        // register new models
744
-        if (
745
-            ! empty(self::$_settings[ $addon_name ]['model_paths'])
746
-            || ! empty(self::$_settings[ $addon_name ]['class_paths'])
747
-        ) {
748
-            EE_Register_Model::register(
749
-                $addon_name,
750
-                [
751
-                    'model_paths' => self::$_settings[ $addon_name ]['model_paths'],
752
-                    'class_paths' => self::$_settings[ $addon_name ]['class_paths'],
753
-                ]
754
-            );
755
-        }
756
-        // register model extensions
757
-        if (
758
-            ! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
759
-            || ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
760
-        ) {
761
-            EE_Register_Model_Extensions::register(
762
-                $addon_name,
763
-                [
764
-                    'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'],
765
-                    'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'],
766
-                ]
767
-            );
768
-        }
769
-    }
770
-
771
-
772
-    /**
773
-     * @param string $addon_name
774
-     * @return void
775
-     * @throws EE_Error
776
-     */
777
-    private static function _register_data_migration_scripts(string $addon_name)
778
-    {
779
-        // setup DMS
780
-        if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
781
-            EE_Register_Data_Migration_Scripts::register(
782
-                $addon_name,
783
-                ['dms_paths' => self::$_settings[ $addon_name ]['dms_paths']]
784
-            );
785
-        }
786
-    }
787
-
788
-
789
-    /**
790
-     * @param string $addon_name
791
-     * @return void
792
-     * @throws EE_Error
793
-     */
794
-    private static function _register_config(string $addon_name)
795
-    {
796
-        // if config_class is present let's register config.
797
-        if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
798
-            EE_Register_Config::register(
799
-                self::$_settings[ $addon_name ]['config_class'],
800
-                [
801
-                    'config_section' => self::$_settings[ $addon_name ]['config_section'],
802
-                    'config_name'    => self::$_settings[ $addon_name ]['config_name'],
803
-                ]
804
-            );
805
-        }
806
-    }
807
-
808
-
809
-    /**
810
-     * @param string $addon_name
811
-     * @return void
812
-     * @throws EE_Error
813
-     */
814
-    private static function _register_admin_pages(string $addon_name)
815
-    {
816
-        if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
817
-            EE_Register_Admin_Page::register(
818
-                $addon_name,
819
-                ['page_path' => self::$_settings[ $addon_name ]['admin_path']]
820
-            );
821
-        }
822
-    }
823
-
824
-
825
-    /**
826
-     * @param string $addon_name
827
-     * @return void
828
-     * @throws EE_Error
829
-     */
830
-    private static function _register_modules(string $addon_name)
831
-    {
832
-        if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
833
-            EE_Register_Module::register(
834
-                $addon_name,
835
-                ['module_paths' => self::$_settings[ $addon_name ]['module_paths']]
836
-            );
837
-        }
838
-    }
839
-
840
-
841
-    /**
842
-     * @param string $addon_name
843
-     * @return void
844
-     * @throws EE_Error
845
-     */
846
-    private static function _register_shortcodes(string $addon_name)
847
-    {
848
-        if (
849
-            ! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
850
-            || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
851
-        ) {
852
-            EE_Register_Shortcode::register(
853
-                $addon_name,
854
-                [
855
-                    'shortcode_paths' => self::$_settings[ $addon_name ]['shortcode_paths'] ?? [],
856
-                    'shortcode_fqcns' => self::$_settings[ $addon_name ]['shortcode_fqcns'] ?? [],
857
-                ]
858
-            );
859
-        }
860
-    }
861
-
862
-
863
-    /**
864
-     * @param string $addon_name
865
-     * @return void
866
-     * @throws EE_Error
867
-     */
868
-    private static function _register_widgets(string $addon_name)
869
-    {
870
-        if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
871
-            EE_Register_Widget::register(
872
-                $addon_name,
873
-                ['widget_paths' => self::$_settings[ $addon_name ]['widget_paths']]
874
-            );
875
-        }
876
-    }
877
-
878
-
879
-    /**
880
-     * @param string $addon_name
881
-     * @return void
882
-     * @throws EE_Error
883
-     */
884
-    private static function _register_capabilities(string $addon_name)
885
-    {
886
-        if (! empty(self::$_settings[ $addon_name ]['capabilities'])) {
887
-            EE_Register_Capabilities::register(
888
-                $addon_name,
889
-                [
890
-                    'capabilities'    => self::$_settings[ $addon_name ]['capabilities'],
891
-                    'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'],
892
-                ]
893
-            );
894
-        }
895
-    }
896
-
897
-
898
-    /**
899
-     * @param string $addon_name
900
-     * @return void
901
-     */
902
-    private static function _register_message_types(string $addon_name)
903
-    {
904
-        if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
905
-            add_action(
906
-                'EE_Brewing_Regular___messages_caf',
907
-                ['EE_Register_Addon', 'register_message_types']
908
-            );
909
-        }
910
-    }
911
-
912
-
913
-    /**
914
-     * @param string $addon_name
915
-     * @return void
916
-     * @throws EE_Error
917
-     */
918
-    private static function _register_custom_post_types(string $addon_name)
919
-    {
920
-        if (
921
-            ! empty(self::$_settings[ $addon_name ]['custom_post_types'])
922
-            || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies'])
923
-        ) {
924
-            EE_Register_CPT::register(
925
-                $addon_name,
926
-                [
927
-                    'cpts'          => self::$_settings[ $addon_name ]['custom_post_types'],
928
-                    'cts'           => self::$_settings[ $addon_name ]['custom_taxonomies'],
929
-                    'default_terms' => self::$_settings[ $addon_name ]['default_terms'],
930
-                ]
931
-            );
932
-        }
933
-    }
934
-
935
-
936
-    /**
937
-     * @param string $addon_name
938
-     * @return void
939
-     * @throws InvalidArgumentException
940
-     * @throws InvalidInterfaceException
941
-     * @throws InvalidDataTypeException
942
-     * @throws DomainException
943
-     * @throws EE_Error
944
-     */
945
-    private static function _register_payment_methods(string $addon_name)
946
-    {
947
-        if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
948
-            EE_Register_Payment_Method::register(
949
-                $addon_name,
950
-                ['payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']]
951
-            );
952
-        }
953
-    }
954
-
955
-
956
-    /**
957
-     * @param string $addon_name
958
-     * @return void
959
-     * @throws InvalidArgumentException
960
-     * @throws InvalidInterfaceException
961
-     * @throws InvalidDataTypeException
962
-     * @throws DomainException
963
-     */
964
-    private static function registerPrivacyPolicies(string $addon_name)
965
-    {
966
-        if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) {
967
-            EE_Register_Privacy_Policy::register(
968
-                $addon_name,
969
-                self::$_settings[ $addon_name ]['privacy_policies']
970
-            );
971
-        }
972
-    }
973
-
974
-
975
-    /**
976
-     * @param string $addon_name
977
-     * @return void
978
-     */
979
-    private static function registerPersonalDataExporters(string $addon_name)
980
-    {
981
-        if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) {
982
-            EE_Register_Personal_Data_Eraser::register(
983
-                $addon_name,
984
-                self::$_settings[ $addon_name ]['personal_data_exporters']
985
-            );
986
-        }
987
-    }
988
-
989
-
990
-    /**
991
-     * @param string $addon_name
992
-     * @return void
993
-     */
994
-    private static function registerPersonalDataErasers(string $addon_name)
995
-    {
996
-        if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) {
997
-            EE_Register_Personal_Data_Eraser::register(
998
-                $addon_name,
999
-                self::$_settings[ $addon_name ]['personal_data_erasers']
1000
-            );
1001
-        }
1002
-    }
1003
-
1004
-
1005
-    /**
1006
-     * Loads and instantiates the EE_Addon class and adds it onto the registry
1007
-     *
1008
-     * @param string $addon_name
1009
-     * @return EE_Addon
1010
-     * @throws InvalidArgumentException
1011
-     * @throws InvalidInterfaceException
1012
-     * @throws InvalidDataTypeException
1013
-     */
1014
-    private static function _load_and_init_addon_class(string $addon_name): EE_Addon
1015
-    {
1016
-        $addon = self::$loader->getShared(
1017
-            self::$_settings[ $addon_name ]['class_name'],
1018
-            ['EE_Registry::create(addon)' => true]
1019
-        );
1020
-        if (! $addon instanceof EE_Addon) {
1021
-            throw new DomainException(
1022
-                sprintf(
1023
-                    esc_html__('The "%1$s" EE_Addon class failed to instantiate!', 'event_espresso'),
1024
-                    self::$_settings[ $addon_name ]['class_name']
1025
-                )
1026
-            );
1027
-        }
1028
-        // setter inject dep map if required
1029
-        if ($addon->dependencyMap() === null) {
1030
-            $addon->setDependencyMap(self::$loader->getShared('EE_Dependency_Map'));
1031
-        }
1032
-        // setter inject domain if required
1033
-        EE_Register_Addon::injectAddonDomain($addon_name, $addon);
1034
-
1035
-        $addon->set_name($addon_name);
1036
-        $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']);
1037
-        $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']);
1038
-        $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']);
1039
-        $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']);
1040
-        $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']);
1041
-        $addon->set_version(self::$_settings[ $addon_name ]['version']);
1042
-        $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version']));
1043
-        $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']);
1044
-        $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']);
1045
-        $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']);
1046
-        do_action(
1047
-            'AHEE__EE_Register_Addon___load_and_init_addon_class',
1048
-            $addon,
1049
-            $addon_name,
1050
-            self::$_settings
1051
-        );
1052
-        // unfortunately this can't be hooked in upon construction,
1053
-        // because we don't have the plugin's mainfile path upon construction.
1054
-        register_deactivation_hook($addon->get_main_plugin_file(), [$addon, 'deactivation']);
1055
-        // call any additional admin_callback functions during load_admin_controller hook
1056
-        if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) {
1057
-            add_action(
1058
-                'AHEE__EE_System__load_controllers__load_admin_controllers',
1059
-                [$addon, self::$_settings[ $addon_name ]['admin_callback']]
1060
-            );
1061
-        }
1062
-        return $addon;
1063
-    }
1064
-
1065
-
1066
-    /**
1067
-     * @param string   $addon_name
1068
-     * @param EE_Addon $addon
1069
-     * @since   4.10.13.p
1070
-     */
1071
-    private static function injectAddonDomain(string $addon_name, EE_Addon $addon)
1072
-    {
1073
-        if ($addon instanceof RequiresDomainInterface && $addon->domain() === null) {
1074
-            // using supplied Domain object
1075
-            $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface
1076
-                ? self::$_settings[ $addon_name ]['domain']
1077
-                : null;
1078
-            // or construct one using Domain FQCN
1079
-            if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') {
1080
-                $domain = self::$loader->getShared(
1081
-                    self::$_settings[ $addon_name ]['domain_fqcn'],
1082
-                    [
1083
-                        new EventEspresso\core\domain\values\FilePath(
1084
-                            self::$_settings[ $addon_name ]['main_file_path']
1085
-                        ),
1086
-                        EventEspresso\core\domain\values\Version::fromString(
1087
-                            self::$_settings[ $addon_name ]['version']
1088
-                        ),
1089
-                    ]
1090
-                );
1091
-            }
1092
-            if ($domain instanceof DomainInterface) {
1093
-                $addon->setDomain($domain);
1094
-            }
1095
-        }
1096
-    }
1097
-
1098
-
1099
-    /**
1100
-     * @return void
1101
-     * @deprecated 5.0.0.p
1102
-     */
1103
-    public static function load_pue_update()
1104
-    {
1105
-    }
1106
-
1107
-
1108
-    /**
1109
-     * Callback for EE_Brewing_Regular__messages_caf hook used to register message types.
1110
-     *
1111
-     * @return void
1112
-     * @throws EE_Error
1113
-     * @since 4.4.0
1114
-     */
1115
-    public static function register_message_types()
1116
-    {
1117
-        foreach (self::$_settings as $settings) {
1118
-            if (! empty($settings['message_types'])) {
1119
-                foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) {
1120
-                    EE_Register_Message_Type::register($message_type, $message_type_settings);
1121
-                }
1122
-            }
1123
-        }
1124
-    }
1125
-
1126
-
1127
-    private static function registerLicense($addon_name)
1128
-    {
1129
-        static $request = null;
1130
-        if ($request === null) {
1131
-            /** @var RequestInterface $request */
1132
-            $request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1133
-        }
1134
-        if ($request->isWordPressHeartbeat()) {
1135
-            return;
1136
-        }
1137
-        $addon_settings = self::$_settings[ $addon_name ] ?? [];
1138
-        if (empty($addon_settings)) {
1139
-            return;
1140
-        }
1141
-        $license_data = isset($addon_settings['license']) ? (array) $addon_settings['license'] : [];
1142
-        // copy known values from addon settings to license data if anything's missing
1143
-        $license_data += [
1144
-            'main_file_path'   => $addon_settings['main_file_path'] ?? '',
1145
-            'min_core_version' => $addon_settings['min_core_version'] ?? '',
1146
-            'plugin_id'        => 0, // no corresponding value in addon settings
1147
-            'plugin_slug'      => $addon_settings['plugin_slug'] ?? '',
1148
-            'version'          => $addon_settings['version'] ?? '',
1149
-        ];
1150
-        EventEspresso\core\services\licensing\AddonLicense::register($addon_name, $license_data);
1151
-    }
1152
-
1153
-
1154
-    /**
1155
-     * This deregisters an addon that was previously registered with a specific addon_name.
1156
-     *
1157
-     * @param string $addon_name the name for the addon that was previously registered
1158
-     * @throws DomainException
1159
-     * @throws InvalidArgumentException
1160
-     * @throws InvalidDataTypeException
1161
-     * @throws InvalidInterfaceException
1162
-     * @since    4.3.0
1163
-     */
1164
-    public static function deregister(string $addon_name = '')
1165
-    {
1166
-        if (isset(self::$_settings[ $addon_name ]['class_name'])) {
1167
-            try {
1168
-                do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name);
1169
-                $class_name = self::$_settings[ $addon_name ]['class_name'];
1170
-                if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
1171
-                    // setup DMS
1172
-                    EE_Register_Data_Migration_Scripts::deregister($addon_name);
1173
-                }
1174
-                if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
1175
-                    // register admin page
1176
-                    EE_Register_Admin_Page::deregister($addon_name);
1177
-                }
1178
-                if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
1179
-                    // add to list of modules to be registered
1180
-                    EE_Register_Module::deregister($addon_name);
1181
-                }
1182
-                if (
1183
-                    ! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
1184
-                    || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
1185
-                ) {
1186
-                    // add to list of shortcodes to be registered
1187
-                    EE_Register_Shortcode::deregister($addon_name);
1188
-                }
1189
-                if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
1190
-                    // if config_class present let's register config.
1191
-                    EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']);
1192
-                }
1193
-                if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
1194
-                    // add to list of widgets to be registered
1195
-                    EE_Register_Widget::deregister($addon_name);
1196
-                }
1197
-                if (
1198
-                    ! empty(self::$_settings[ $addon_name ]['model_paths'])
1199
-                    || ! empty(self::$_settings[ $addon_name ]['class_paths'])
1200
-                ) {
1201
-                    // add to list of shortcodes to be registered
1202
-                    EE_Register_Model::deregister($addon_name);
1203
-                }
1204
-                if (
1205
-                    ! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
1206
-                    || ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
1207
-                ) {
1208
-                    // add to list of shortcodes to be registered
1209
-                    EE_Register_Model_Extensions::deregister($addon_name);
1210
-                }
1211
-                if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
1212
-                    foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) {
1213
-                        EE_Register_Message_Type::deregister($message_type);
1214
-                    }
1215
-                }
1216
-                // deregister capabilities for addon
1217
-                if (
1218
-                    ! empty(self::$_settings[ $addon_name ]['capabilities'])
1219
-                    || ! empty(self::$_settings[ $addon_name ]['capability_maps'])
1220
-                ) {
1221
-                    EE_Register_Capabilities::deregister($addon_name);
1222
-                }
1223
-                // deregister custom_post_types for addon
1224
-                if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) {
1225
-                    EE_Register_CPT::deregister($addon_name);
1226
-                }
1227
-                if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
1228
-                    EE_Register_Payment_Method::deregister($addon_name);
1229
-                }
1230
-                $addon = EE_Registry::instance()->getAddon($class_name);
1231
-                if ($addon instanceof EE_Addon) {
1232
-                    remove_action(
1233
-                        'deactivate_' . $addon->get_main_plugin_file_basename(),
1234
-                        [$addon, 'deactivation']
1235
-                    );
1236
-                    remove_action(
1237
-                        'AHEE__EE_System__perform_activations_upgrades_and_migrations',
1238
-                        [$addon, 'initialize_db_if_no_migrations_required']
1239
-                    );
1240
-                    // remove `after_registration` call
1241
-                    remove_action(
1242
-                        'AHEE__EE_System__load_espresso_addons__complete',
1243
-                        [$addon, 'after_registration'],
1244
-                        999
1245
-                    );
1246
-                }
1247
-                EE_Registry::instance()->removeAddon($class_name);
1248
-                LoaderFactory::getLoader()->remove($class_name);
1249
-            } catch (OutOfBoundsException $addon_not_yet_registered_exception) {
1250
-                // the add-on was not yet registered in the registry,
1251
-                // so RegistryContainer::__get() throws this exception.
1252
-                // also no need to worry about this or log it,
1253
-                // it's ok to deregister an add-on before its registered in the registry
1254
-            } catch (Exception $e) {
1255
-                new ExceptionLogger($e);
1256
-            }
1257
-            unset(self::$_settings[ $addon_name ]);
1258
-            do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name);
1259
-        }
1260
-    }
1261
-
1262
-
1263
-    public static function reset(): void
1264
-    {
1265
-        EE_Register_Addon::$_settings = [];
1266
-    }
1267
-
1268
-
1269
-    public static function resetAll(): void
1270
-    {
1271
-        // EE_Register_Addon::reset();
1272
-        EE_Register_Admin_Page::reset();
1273
-        EE_Register_Capabilities::reset();
1274
-        EE_Register_Config::reset();
1275
-        EE_Register_CPT::reset();
1276
-        EE_Register_Data_Migration_Scripts::reset();
1277
-        EE_Register_Message_Type::reset();
1278
-        EE_Register_Messages_Shortcode_Library::reset();
1279
-        EE_Register_Messages_Template_Pack::reset();
1280
-        EE_Register_Messages_Template_Variations::reset();
1281
-        EE_Register_Model::reset();
1282
-        EE_Register_Model_Extensions::reset();
1283
-        EE_Register_Module::reset();
1284
-        EE_Register_Payment_Method::reset();
1285
-        EE_Register_Personal_Data_Eraser::reset();
1286
-        EE_Register_Personal_Data_Exporter::reset();
1287
-        EE_Register_Privacy_Policy::reset();
1288
-        EE_Register_Shortcode::reset();
1289
-        EE_Register_Widget::reset();
1290
-    }
27
+	/**
28
+	 * possibly truncated version of the EE core version string
29
+	 *
30
+	 * @var string
31
+	 */
32
+	protected static $_core_version = '';
33
+
34
+	/**
35
+	 * Holds values for registered addons
36
+	 *
37
+	 * @var array
38
+	 */
39
+	protected static $_settings = [];
40
+
41
+	/**
42
+	 * @var  array $_incompatible_addons keys are addon SLUGS
43
+	 *                                   (first argument passed to EE_Register_Addon::register()), keys are
44
+	 *                                   their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004).
45
+	 *                                   Generally this should be used sparingly, as we don't want to muddle up
46
+	 *                                   EE core with knowledge of ALL the addons out there.
47
+	 *                                   If you want NO versions of an addon to run with a certain version of core,
48
+	 *                                   it's usually best to define the addon's "min_core_version" as part of its call
49
+	 *                                   to EE_Register_Addon::register(), rather than using this array with a super
50
+	 *                                   high value for its minimum plugin version.
51
+	 */
52
+	protected static $_incompatible_addons = [
53
+		'Multi_Event_Registration' => '2.0.11.rc.002',
54
+		'Promotions'               => '1.0.0.rc.084',
55
+		'EE_WPUsers'               => '2.1.3.p',
56
+	];
57
+
58
+	/**
59
+	 * @var LoaderInterface
60
+	 */
61
+	protected static $loader;
62
+
63
+
64
+	/**
65
+	 * We should always be comparing core to a version like '4.3.0.rc.000',
66
+	 * not just '4.3.0'.
67
+	 * So if the addon developer doesn't provide that full version string,
68
+	 * fill in the blanks for them
69
+	 *
70
+	 * @param string $min_core_version
71
+	 * @return string always like '4.3.0.rc.000'
72
+	 */
73
+	protected static function _effective_version(string $min_core_version): string
74
+	{
75
+		// versions: 4 . 3 . 1 . p . 123
76
+		// offsets:    0 . 1 . 2 . 3 . 4
77
+		$version_parts = explode('.', $min_core_version);
78
+		// check they specified the micro version (after 2nd period)
79
+		if (! isset($version_parts[2])) {
80
+			$version_parts[2] = '0';
81
+		}
82
+		// if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible
83
+		// soon we can assume that's 'rc', but this current version is 'alpha'
84
+		if (! isset($version_parts[3])) {
85
+			$version_parts[3] = 'dev';
86
+		}
87
+		if (! isset($version_parts[4])) {
88
+			$version_parts[4] = '000';
89
+		}
90
+		return implode('.', $version_parts);
91
+	}
92
+
93
+
94
+	/**
95
+	 * Returns whether or not the min core version requirement of the addon is met
96
+	 *
97
+	 * @param string $min_core_version    the minimum core version required by the addon
98
+	 * @param string $actual_core_version the actual core version, optional
99
+	 * @return bool
100
+	 */
101
+	public static function _meets_min_core_version_requirement(
102
+		string $min_core_version,
103
+		string $actual_core_version = EVENT_ESPRESSO_VERSION
104
+	): bool {
105
+		return version_compare(
106
+			self::_effective_version($actual_core_version),
107
+			self::_effective_version($min_core_version),
108
+			'>='
109
+		);
110
+	}
111
+
112
+
113
+	/**
114
+	 * Method for registering new EE_Addons.
115
+	 * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE
116
+	 * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it
117
+	 * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon
118
+	 * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after
119
+	 * 'activate_plugin', it registers the addon still, but its components are not registered
120
+	 * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do
121
+	 * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns
122
+	 * (so that we can detect that the addon has activated on the subsequent request)
123
+	 *
124
+	 * @param string                  $addon_name                       [Required] the EE_Addon's name.
125
+	 * @param array                   $setup_args                       {
126
+	 *                                                                  An array of arguments provided for registering
127
+	 *                                                                  the message type.
128
+	 * @type  string                  $class_name                       the addon's main file name.
129
+	 *                                                                  If left blank, generated from the addon name,
130
+	 *                                                                  changes something like "calendar" to
131
+	 *                                                                  "EE_Calendar"
132
+	 * @type string                   $min_core_version                 the minimum version of EE Core that the
133
+	 *                                                                  addon will work with. eg "4.8.1.rc.084"
134
+	 * @type string                   $version                          the "software" version for the addon. eg
135
+	 *                                                                  "1.0.0.p" for a first stable release, or
136
+	 *                                                                  "1.0.0.rc.043" for a version in progress
137
+	 * @type string                   $main_file_path                   the full server path to the main file
138
+	 *                                                                  loaded directly by WP
139
+	 * @type DomainInterface          $domain                           child class of
140
+	 *                                                                  EventEspresso\core\domain\DomainBase
141
+	 * @type string                   $domain_fqcn                      Fully Qualified Class Name
142
+	 *                                                                  for the addon's Domain class
143
+	 *                                                                  (see EventEspresso\core\domain\Domain)
144
+	 * @type string                   $admin_path                       full server path to the folder where the
145
+	 *                                                                  addon\'s admin files reside
146
+	 * @type string                   $admin_callback                   a method to be called when the EE Admin is
147
+	 *                                                                  first invoked, can be used for hooking into
148
+	 *                                                                  any admin page
149
+	 * @type string                   $config_section                   the section name for this addon's
150
+	 *                                                                  configuration settings section
151
+	 *                                                                  (defaults to "addons")
152
+	 * @type string                   $config_class                     the class name for this addon's
153
+	 *                                                                  configuration settings object
154
+	 * @type string                   $config_name                      the class name for this addon's
155
+	 *                                                                  configuration settings object
156
+	 * @type string                   $autoloader_paths                 [Required] an array of class names and the full
157
+	 *                                                                  server paths to those files.
158
+	 * @type string                   $autoloader_folders               an array of  "full server paths" for any
159
+	 *                                                                  folders containing classes that might be
160
+	 *                                                                  invoked by the addon
161
+	 * @type string                   $dms_paths                        [Required] an array of full server paths to
162
+	 *                                                                  folders that contain data migration scripts.
163
+	 *                                                                  The key should be the EE_Addon class name that
164
+	 *                                                                  this set of data migration scripts belongs to.
165
+	 *                                                                  If the EE_Addon class is namespaced, then this
166
+	 *                                                                  needs to be the Fully Qualified Class Name
167
+	 * @type string                   $module_paths                     an array of full server paths to any
168
+	 *                                                                  EED_Modules used by the addon
169
+	 * @type string                   $shortcode_paths                  an array of full server paths to folders
170
+	 *                                                                  that contain EES_Shortcodes
171
+	 * @type string                   $widget_paths                     an array of full server paths to folders
172
+	 *                                                                  that contain WP_Widgets
173
+	 * @type array                    $capabilities                     an array indexed by role name
174
+	 *                                                                  (i.e administrator,author ) and the values
175
+	 *                                                                  are an array of caps to add to the role.
176
+	 *                                                                  'administrator' => array(
177
+	 *                                                                  'read_addon',
178
+	 *                                                                  'edit_addon',
179
+	 *                                                                  etc.
180
+	 *                                                                  ).
181
+	 * @type EE_Meta_Capability_Map[] $capability_maps                  an array of EE_Meta_Capability_Map object
182
+	 *                                                                  for any addons that need to register any
183
+	 *                                                                  special meta mapped capabilities.  Should
184
+	 *                                                                  be indexed where the key is the
185
+	 *                                                                  EE_Meta_Capability_Map class name and the
186
+	 *                                                                  values are the arguments sent to the class.
187
+	 * @type array                    $model_paths                      array of folders containing DB models
188
+	 * @return bool
189
+	 * @throws DomainException
190
+	 * @throws EE_Error
191
+	 * @throws InvalidArgumentException
192
+	 * @throws InvalidDataTypeException
193
+	 * @throws InvalidInterfaceException
194
+	 * @since                                                           4.3.0
195
+	 * @see                                                             EE_Register_Model
196
+	 * @type array                    $class_paths                      array of folders containing DB classes
197
+	 * @see                                                             EE_Register_Model
198
+	 * @type array                    $model_extension_paths            array of folders containing DB model
199
+	 *                                                                  extensions
200
+	 * @see                                                             EE_Register_Model_Extension
201
+	 * @type array                    $class_extension_paths            array of folders containing DB class
202
+	 *                                                                  extensions
203
+	 * @see                                                             EE_Register_Model_Extension
204
+	 * @type array message_types {
205
+	 *                                                                  An array of message types with the key as
206
+	 *                                                                  the message type name and the values as
207
+	 *                                                                  below:
208
+	 * @type string                   $mtfilename                       [Required] The filename of the message type
209
+	 *                                                                  being registered. This will be the main
210
+	 *                                                                  EE_{Message Type Name}_message_type class.
211
+	 *                                                                  for example:
212
+	 *                                                                  EE_Declined_Registration_message_type.class.php
213
+	 * @type array                    $autoloadpaths                    [Required] An array of paths to add to the
214
+	 *                                                                  messages autoloader for the new message type.
215
+	 * @type array                    $messengers_to_activate_with      An array of messengers that this message
216
+	 *                                                                  type should activate with. Each value in
217
+	 *                                                                  the
218
+	 *                                                                  array
219
+	 *                                                                  should match the name property of a
220
+	 *                                                                  EE_messenger. Optional.
221
+	 * @type array                    $messengers_to_validate_with      An array of messengers that this message
222
+	 *                                                                  type should validate with. Each value in
223
+	 *                                                                  the
224
+	 *                                                                  array
225
+	 *                                                                  should match the name property of an
226
+	 *                                                                  EE_messenger.
227
+	 *                                                                  Optional.
228
+	 *                                                                  }
229
+	 * @type array                    $custom_post_types
230
+	 * @type array                    $custom_taxonomies
231
+	 * @type array                    $payment_method_paths             each element is the folder containing the
232
+	 *                                                                  EE_PMT_Base child class
233
+	 *                                                                  (eg,
234
+	 *                                                                  '/wp-content/plugins/my_plugin/Payomatic/'
235
+	 *                                                                  which contains the files
236
+	 *                                                                  EE_PMT_Payomatic.pm.php)
237
+	 * @type array                    $default_terms
238
+	 * @type array                    $namespace                        {
239
+	 *                                                                  An array with two items for registering the
240
+	 *                                                                  addon's namespace. (If, for some reason, you
241
+	 *                                                                  require additional namespaces,
242
+	 *                                                                  use
243
+	 *                                                                  EventEspresso\core\Psr4Autoloader::addNamespace()
244
+	 *                                                                  directly)
245
+	 * @see                                                             EventEspresso\core\Psr4Autoloader::addNamespace()
246
+	 * @type string                   $FQNS                             the namespace prefix
247
+	 * @type string                   $DIR                              a base directory for class files in the
248
+	 *                                                                  namespace.
249
+	 *                                                                  }
250
+	 *                                                                  }
251
+	 * @type string                   $privacy_policies                 FQNSs (namespaces, each of which contains only
252
+	 *                                                                  privacy policy classes) or FQCNs (specific
253
+	 *                                                                  classnames of privacy policy classes)
254
+	 * @type string                   $personal_data_exporters          FQNSs (namespaces, each of which contains only
255
+	 *                                                                  privacy policy classes) or FQCNs (specific
256
+	 *                                                                  classnames of privacy policy classes)
257
+	 * @type string                   $personal_data_erasers            FQNSs (namespaces, each of which contains only
258
+	 *                                                                  privacy policy classes) or FQCNs (specific
259
+	 *                                                                  classnames of privacy policy classes)
260
+	 */
261
+	public static function register(string $addon_name = '', array $setup_args = []): bool
262
+	{
263
+		// $addon_name = basename($addon_name);
264
+		if (! self::$loader instanceof LoaderInterface) {
265
+			self::$loader = LoaderFactory::getLoader();
266
+		}
267
+		// make sure this was called in the right place!
268
+		if (
269
+			! did_action('activate_plugin')
270
+			&& (
271
+				! did_action('AHEE__EE_System__load_espresso_addons')
272
+				|| did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin')
273
+			)
274
+		) {
275
+			EE_Error::doing_it_wrong(
276
+				__METHOD__,
277
+				sprintf(
278
+					esc_html__(
279
+						'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time.  Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.',
280
+						'event_espresso'
281
+					),
282
+					$addon_name
283
+				),
284
+				'4.3.0'
285
+			);
286
+			return false;
287
+		}
288
+		// required fields MUST be present, so let's make sure they are.
289
+		EE_Register_Addon::_verify_parameters($addon_name, $setup_args);
290
+		// get class name for addon
291
+		$class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args);
292
+		// setup $_settings array from incoming values.
293
+		$addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args);
294
+		// allow early addon setup or modification of addon api settings
295
+		self::$_settings = (array) apply_filters(
296
+			'FHEE__EE_Register_Addon__register',
297
+			self::$_settings,
298
+			$addon_name,
299
+			$class_name,
300
+			$setup_args
301
+		);
302
+		// does this addon work with this version of core or WordPress ?
303
+		// does this addon work with this version of core or WordPress ?
304
+		if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
305
+			return false;
306
+		}
307
+		// register namespaces
308
+		EE_Register_Addon::_setup_namespaces($addon_settings);
309
+		// check if this is an activation request
310
+		if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) {
311
+			// dont bother setting up the rest of the addon atm
312
+			return false;
313
+		}
314
+		// we need cars
315
+		EE_Register_Addon::_setup_autoloaders($addon_name);
316
+		// register new models and extensions
317
+		EE_Register_Addon::_register_models_and_extensions($addon_name);
318
+		// setup DMS
319
+		EE_Register_Addon::_register_data_migration_scripts($addon_name);
320
+		// if config_class is present let's register config.
321
+		EE_Register_Addon::_register_config($addon_name);
322
+		// register admin pages
323
+		EE_Register_Addon::_register_admin_pages($addon_name);
324
+		// add to list of modules to be registered
325
+		EE_Register_Addon::_register_modules($addon_name);
326
+		// add to list of shortcodes to be registered
327
+		EE_Register_Addon::_register_shortcodes($addon_name);
328
+		// add to list of widgets to be registered
329
+		EE_Register_Addon::_register_widgets($addon_name);
330
+		// register capability related stuff.
331
+		EE_Register_Addon::_register_capabilities($addon_name);
332
+		// any message type to register?
333
+		EE_Register_Addon::_register_message_types($addon_name);
334
+		// any custom post type/ custom capabilities or default terms to register
335
+		EE_Register_Addon::_register_custom_post_types($addon_name);
336
+		// and any payment methods
337
+		EE_Register_Addon::_register_payment_methods($addon_name);
338
+		// and privacy policy generators
339
+		EE_Register_Addon::registerPrivacyPolicies($addon_name);
340
+		// and privacy policy generators
341
+		EE_Register_Addon::registerPersonalDataExporters($addon_name);
342
+		// and privacy policy generators
343
+		EE_Register_Addon::registerPersonalDataErasers($addon_name);
344
+		EE_Register_Addon::registerLicense($addon_name);
345
+		// load and instantiate main addon class
346
+		$addon = EE_Register_Addon::_load_and_init_addon_class($addon_name);
347
+		// delay calling after_registration hook on each addon until after all add-ons have been registered.
348
+		add_action('AHEE__EE_System__load_espresso_addons__complete', [$addon, 'after_registration'], 999);
349
+		return $addon instanceof EE_Addon;
350
+	}
351
+
352
+
353
+	/**
354
+	 * @param string $addon_name
355
+	 * @param array  $setup_args
356
+	 * @return void
357
+	 * @throws EE_Error
358
+	 */
359
+	private static function _verify_parameters(string $addon_name, array $setup_args)
360
+	{
361
+		// required fields MUST be present, so let's make sure they are.
362
+		if (empty($addon_name) || empty($setup_args)) {
363
+			throw new EE_Error(
364
+				esc_html__(
365
+					'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.',
366
+					'event_espresso'
367
+				)
368
+			);
369
+		}
370
+		if (empty($setup_args['main_file_path'])) {
371
+			throw new EE_Error(
372
+				sprintf(
373
+					esc_html__(
374
+						'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s',
375
+						'event_espresso'
376
+					),
377
+					implode(',', array_keys($setup_args))
378
+				)
379
+			);
380
+		}
381
+		// check that addon has not already been registered with that name
382
+		if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) {
383
+			throw new EE_Error(
384
+				sprintf(
385
+					esc_html__(
386
+						'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.',
387
+						'event_espresso'
388
+					),
389
+					$addon_name
390
+				)
391
+			);
392
+		}
393
+	}
394
+
395
+
396
+	/**
397
+	 * @param string $addon_name
398
+	 * @param array  $setup_args
399
+	 * @return string
400
+	 */
401
+	private static function _parse_class_name(string $addon_name, array $setup_args): string
402
+	{
403
+		if (empty($setup_args['class_name'])) {
404
+			// generate one by first separating name with spaces
405
+			$class_name = str_replace(['-', '_'], ' ', trim($addon_name));
406
+			// capitalize, then replace spaces with underscores
407
+			$class_name = str_replace(' ', '_', ucwords($class_name));
408
+		} else {
409
+			$class_name = $setup_args['class_name'];
410
+		}
411
+		// check if classname is fully  qualified or is a legacy classname already prefixed with 'EE_'
412
+		return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0
413
+			? $class_name
414
+			: 'EE_' . $class_name;
415
+	}
416
+
417
+
418
+	/**
419
+	 * @param string $class_name
420
+	 * @param array  $setup_args
421
+	 * @return array
422
+	 */
423
+	private static function _get_addon_settings(string $class_name, array $setup_args): array
424
+	{
425
+		// setup $_settings array from incoming values.
426
+		$addon_settings = [
427
+			// generated from the addon name, changes something like "calendar" to "EE_Calendar"
428
+			'class_name'            => $class_name,
429
+			// the addon slug for use in URLs, etc
430
+			'plugin_slug'           => isset($setup_args['plugin_slug'])
431
+				? (string) $setup_args['plugin_slug']
432
+				: sanitize_key($class_name),
433
+			// page slug to be used when generating the "Settings" link on the WP plugin page
434
+			'plugin_action_slug'    => isset($setup_args['plugin_action_slug'])
435
+				? (string) $setup_args['plugin_action_slug']
436
+				: '',
437
+			// the "software" version for the addon
438
+			'version'               => isset($setup_args['version'])
439
+				? (string) $setup_args['version']
440
+				: '',
441
+			// the minimum version of EE Core that the addon will work with
442
+			'min_core_version'      => isset($setup_args['min_core_version'])
443
+				? (string) $setup_args['min_core_version']
444
+				: '',
445
+			// the minimum version of WordPress that the addon will work with
446
+			'min_wp_version'        => isset($setup_args['min_wp_version'])
447
+				? (string) $setup_args['min_wp_version']
448
+				: EE_MIN_WP_VER_REQUIRED,
449
+			// full server path to main file (file loaded directly by WP)
450
+			'main_file_path'        => isset($setup_args['main_file_path'])
451
+				? (string) $setup_args['main_file_path']
452
+				: '',
453
+			// instance of \EventEspresso\core\domain\DomainInterface
454
+			'domain'                => isset($setup_args['domain']) && $setup_args['domain'] instanceof DomainInterface
455
+				? $setup_args['domain']
456
+				: null,
457
+			// Fully Qualified Class Name for the addon's Domain class
458
+			'domain_fqcn'           => isset($setup_args['domain_fqcn'])
459
+				? (string) $setup_args['domain_fqcn']
460
+				: '',
461
+			// path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages
462
+			'admin_path'            => isset($setup_args['admin_path'])
463
+				? (string) $setup_args['admin_path']
464
+				: '',
465
+			// a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page
466
+			'admin_callback'        => isset($setup_args['admin_callback'])
467
+				? (string) $setup_args['admin_callback']
468
+				: '',
469
+			// the section name for this addon's configuration settings section (defaults to "addons")
470
+			'config_section'        => isset($setup_args['config_section'])
471
+				? (string) $setup_args['config_section']
472
+				: 'addons',
473
+			// the class name for this addon's configuration settings object
474
+			'config_class'          => isset($setup_args['config_class'])
475
+				? (string) $setup_args['config_class']
476
+				: '',
477
+			// the name given to the config for this addons' configuration settings object (optional)
478
+			'config_name'           => isset($setup_args['config_name'])
479
+				? (string) $setup_args['config_name']
480
+				: '',
481
+			// an array of "class names" => "full server paths" for any classes that might be invoked by the addon
482
+			'autoloader_paths'      => isset($setup_args['autoloader_paths'])
483
+				? (array) $setup_args['autoloader_paths']
484
+				: [],
485
+			// an array of  "full server paths" for any folders containing classes that might be invoked by the addon
486
+			'autoloader_folders'    => isset($setup_args['autoloader_folders'])
487
+				? (array) $setup_args['autoloader_folders']
488
+				: [],
489
+			// array of full server paths to any EE_DMS data migration scripts used by the addon.
490
+			// The key should be the EE_Addon class name that this set of data migration scripts belongs to.
491
+			// If the EE_Addon class is namespaced, then this needs to be the Fully Qualified Class Name
492
+			'dms_paths'             => isset($setup_args['dms_paths'])
493
+				? (array) $setup_args['dms_paths']
494
+				: [],
495
+			// array of full server paths to any EED_Modules used by the addon
496
+			'module_paths'          => isset($setup_args['module_paths'])
497
+				? (array) $setup_args['module_paths']
498
+				: [],
499
+			// array of full server paths to any EES_Shortcodes used by the addon
500
+			'shortcode_paths'       => isset($setup_args['shortcode_paths'])
501
+				? (array) $setup_args['shortcode_paths']
502
+				: [],
503
+			'shortcode_fqcns'       => isset($setup_args['shortcode_fqcns'])
504
+				? (array) $setup_args['shortcode_fqcns']
505
+				: [],
506
+			// array of full server paths to any WP_Widgets used by the addon
507
+			'widget_paths'          => isset($setup_args['widget_paths'])
508
+				? (array) $setup_args['widget_paths']
509
+				: [],
510
+			'message_types'         => isset($setup_args['message_types'])
511
+				? (array) $setup_args['message_types']
512
+				: [],
513
+			'capabilities'          => isset($setup_args['capabilities'])
514
+				? (array) $setup_args['capabilities']
515
+				: [],
516
+			'capability_maps'       => isset($setup_args['capability_maps'])
517
+				? (array) $setup_args['capability_maps']
518
+				: [],
519
+			'model_paths'           => isset($setup_args['model_paths'])
520
+				? (array) $setup_args['model_paths']
521
+				: [],
522
+			'class_paths'           => isset($setup_args['class_paths'])
523
+				? (array) $setup_args['class_paths']
524
+				: [],
525
+			'model_extension_paths' => isset($setup_args['model_extension_paths'])
526
+				? (array) $setup_args['model_extension_paths']
527
+				: [],
528
+			'class_extension_paths' => isset($setup_args['class_extension_paths'])
529
+				? (array) $setup_args['class_extension_paths']
530
+				: [],
531
+			'custom_post_types'     => isset($setup_args['custom_post_types'])
532
+				? (array) $setup_args['custom_post_types']
533
+				: [],
534
+			'custom_taxonomies'     => isset($setup_args['custom_taxonomies'])
535
+				? (array) $setup_args['custom_taxonomies']
536
+				: [],
537
+			'payment_method_paths'  => isset($setup_args['payment_method_paths'])
538
+				? (array) $setup_args['payment_method_paths']
539
+				: [],
540
+			'default_terms'         => isset($setup_args['default_terms'])
541
+				? (array) $setup_args['default_terms']
542
+				: [],
543
+			// if not empty, inserts a new table row after this plugin's row on the WP Plugins page
544
+			// that can be used for adding upgrading/marketing info
545
+			'plugins_page_row'      => isset($setup_args['plugins_page_row'])
546
+				? (array) $setup_args['plugins_page_row']
547
+				: [],
548
+			'namespace'             => isset(
549
+				$setup_args['namespace']['FQNS'],
550
+				$setup_args['namespace']['DIR']
551
+			)
552
+				? (array) $setup_args['namespace']
553
+				: [],
554
+			'privacy_policies'      => isset($setup_args['privacy_policies'])
555
+				? (array) $setup_args['privacy_policies']
556
+				: [],
557
+			'license'               => isset($setup_args['license'])
558
+				? (array) $setup_args['license']
559
+				: [],
560
+		];
561
+		// if plugin_action_slug is NOT set, but an admin page path IS set,
562
+		// then let's just use the plugin_slug since that will be used for linking to the admin page
563
+		$addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug'])
564
+												&& ! empty($addon_settings['admin_path'])
565
+			? $addon_settings['plugin_slug']
566
+			: $addon_settings['plugin_action_slug'];
567
+		// full server path to main file (file loaded directly by WP)
568
+		$addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']);
569
+		return $addon_settings;
570
+	}
571
+
572
+
573
+	/**
574
+	 * @param string $addon_name
575
+	 * @param array  $addon_settings
576
+	 * @return bool
577
+	 */
578
+	private static function _addon_is_compatible(string $addon_name, array $addon_settings): bool
579
+	{
580
+		global $wp_version;
581
+		$incompatibility_message = '';
582
+		// check whether this addon version is compatible with EE core
583
+		if (
584
+			isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ])
585
+			&& ! self::_meets_min_core_version_requirement(
586
+				EE_Register_Addon::$_incompatible_addons[ $addon_name ],
587
+				$addon_settings['version']
588
+			)
589
+		) {
590
+			$incompatibility_message = sprintf(
591
+				esc_html__(
592
+					'%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.',
593
+					'event_espresso'
594
+				),
595
+				$addon_name,
596
+				'<br />',
597
+				EE_Register_Addon::$_incompatible_addons[ $addon_name ],
598
+				'<span style="font-weight: bold; color: #D54E21;">',
599
+				'</span><br />'
600
+			);
601
+		} elseif (
602
+			! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version())
603
+		) {
604
+			$incompatibility_message = sprintf(
605
+				esc_html__(
606
+					'%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".',
607
+					'event_espresso'
608
+				),
609
+				$addon_name,
610
+				self::_effective_version($addon_settings['min_core_version']),
611
+				self::_effective_version(espresso_version()),
612
+				'<br />',
613
+				'<span style="font-weight: bold; color: #D54E21;">',
614
+				'</span><br />'
615
+			);
616
+		} elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) {
617
+			$incompatibility_message = sprintf(
618
+				esc_html__(
619
+					'%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.',
620
+					'event_espresso'
621
+				),
622
+				$addon_name,
623
+				$addon_settings['min_wp_version'],
624
+				'<br />',
625
+				'<span style="font-weight: bold; color: #D54E21;">',
626
+				'</span><br />'
627
+			);
628
+		}
629
+		if (! empty($incompatibility_message)) {
630
+			// remove 'activate' from the REQUEST
631
+			// so WP doesn't erroneously tell the user the plugin activated fine when it didn't
632
+			/** @var RequestInterface $request */
633
+			$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
634
+			$request->unSetRequestParam('activate', true);
635
+			if (current_user_can('activate_plugins')) {
636
+				// show an error message indicating the plugin didn't activate properly
637
+				EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__);
638
+			}
639
+			unset($_GET['activate'], $_REQUEST['activate']);
640
+			if (! function_exists('deactivate_plugins')) {
641
+				require_once ABSPATH . 'wp-admin/includes/plugin.php';
642
+			}
643
+			deactivate_plugins(plugin_basename($addon_settings['main_file_path']));
644
+			// BAIL FROM THE ADDON REGISTRATION PROCESS
645
+			return false;
646
+		}
647
+		// addon IS compatible
648
+		return true;
649
+	}
650
+
651
+
652
+	/**
653
+	 * register namespaces right away before any other files or classes get loaded, but AFTER the version checks
654
+	 *
655
+	 * @param array $addon_settings
656
+	 * @return void
657
+	 * @throws EE_Error
658
+	 */
659
+	private static function _setup_namespaces(array $addon_settings)
660
+	{
661
+		//
662
+		if (
663
+			isset(
664
+				$addon_settings['namespace']['FQNS'],
665
+				$addon_settings['namespace']['DIR']
666
+			)
667
+		) {
668
+			EE_Psr4AutoloaderInit::psr4_loader()->addNamespace(
669
+				$addon_settings['namespace']['FQNS'],
670
+				$addon_settings['namespace']['DIR']
671
+			);
672
+		}
673
+	}
674
+
675
+
676
+	/**
677
+	 * @param string $addon_name
678
+	 * @param array  $addon_settings
679
+	 * @return bool
680
+	 * @throws InvalidArgumentException
681
+	 * @throws InvalidDataTypeException
682
+	 * @throws InvalidInterfaceException
683
+	 */
684
+	private static function _addon_activation(string $addon_name, array $addon_settings): bool
685
+	{
686
+		// this is an activation request
687
+		if (did_action('activate_plugin')) {
688
+			// to find if THIS is the addon that was activated, just check if we have already registered it or not
689
+			// (as the newly-activated addon wasn't around the first time addons were registered).
690
+			if (
691
+				! isset(self::$_settings[ $addon_name ])
692
+				|| (isset(self::$_settings[ $addon_name ])
693
+					&& ! isset(self::$_settings[ $addon_name ]['class_name'])
694
+				)
695
+			) {
696
+				self::$_settings[ $addon_name ] = $addon_settings;
697
+				$addon                          = self::_load_and_init_addon_class($addon_name);
698
+				$addon->set_activation_indicator_option();
699
+				// dont bother setting up the rest of the addon.
700
+				// we know it was just activated and the request will end soon
701
+			}
702
+			return true;
703
+		}
704
+		// make sure addon settings are set correctly without overwriting anything existing
705
+		if (isset(self::$_settings[ $addon_name ])) {
706
+			self::$_settings[ $addon_name ] += $addon_settings;
707
+		} else {
708
+			self::$_settings[ $addon_name ] = $addon_settings;
709
+		}
710
+		return false;
711
+	}
712
+
713
+
714
+	/**
715
+	 * @param string $addon_name
716
+	 * @return void
717
+	 * @throws EE_Error
718
+	 */
719
+	private static function _setup_autoloaders(string $addon_name)
720
+	{
721
+		if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) {
722
+			// setup autoloader for single file
723
+			EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']);
724
+		}
725
+		// setup autoloaders for folders
726
+		if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) {
727
+			foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) {
728
+				EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
729
+			}
730
+		}
731
+	}
732
+
733
+
734
+	/**
735
+	 * register new models and extensions
736
+	 *
737
+	 * @param string $addon_name
738
+	 * @return void
739
+	 * @throws EE_Error
740
+	 */
741
+	private static function _register_models_and_extensions(string $addon_name)
742
+	{
743
+		// register new models
744
+		if (
745
+			! empty(self::$_settings[ $addon_name ]['model_paths'])
746
+			|| ! empty(self::$_settings[ $addon_name ]['class_paths'])
747
+		) {
748
+			EE_Register_Model::register(
749
+				$addon_name,
750
+				[
751
+					'model_paths' => self::$_settings[ $addon_name ]['model_paths'],
752
+					'class_paths' => self::$_settings[ $addon_name ]['class_paths'],
753
+				]
754
+			);
755
+		}
756
+		// register model extensions
757
+		if (
758
+			! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
759
+			|| ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
760
+		) {
761
+			EE_Register_Model_Extensions::register(
762
+				$addon_name,
763
+				[
764
+					'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'],
765
+					'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'],
766
+				]
767
+			);
768
+		}
769
+	}
770
+
771
+
772
+	/**
773
+	 * @param string $addon_name
774
+	 * @return void
775
+	 * @throws EE_Error
776
+	 */
777
+	private static function _register_data_migration_scripts(string $addon_name)
778
+	{
779
+		// setup DMS
780
+		if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
781
+			EE_Register_Data_Migration_Scripts::register(
782
+				$addon_name,
783
+				['dms_paths' => self::$_settings[ $addon_name ]['dms_paths']]
784
+			);
785
+		}
786
+	}
787
+
788
+
789
+	/**
790
+	 * @param string $addon_name
791
+	 * @return void
792
+	 * @throws EE_Error
793
+	 */
794
+	private static function _register_config(string $addon_name)
795
+	{
796
+		// if config_class is present let's register config.
797
+		if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
798
+			EE_Register_Config::register(
799
+				self::$_settings[ $addon_name ]['config_class'],
800
+				[
801
+					'config_section' => self::$_settings[ $addon_name ]['config_section'],
802
+					'config_name'    => self::$_settings[ $addon_name ]['config_name'],
803
+				]
804
+			);
805
+		}
806
+	}
807
+
808
+
809
+	/**
810
+	 * @param string $addon_name
811
+	 * @return void
812
+	 * @throws EE_Error
813
+	 */
814
+	private static function _register_admin_pages(string $addon_name)
815
+	{
816
+		if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
817
+			EE_Register_Admin_Page::register(
818
+				$addon_name,
819
+				['page_path' => self::$_settings[ $addon_name ]['admin_path']]
820
+			);
821
+		}
822
+	}
823
+
824
+
825
+	/**
826
+	 * @param string $addon_name
827
+	 * @return void
828
+	 * @throws EE_Error
829
+	 */
830
+	private static function _register_modules(string $addon_name)
831
+	{
832
+		if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
833
+			EE_Register_Module::register(
834
+				$addon_name,
835
+				['module_paths' => self::$_settings[ $addon_name ]['module_paths']]
836
+			);
837
+		}
838
+	}
839
+
840
+
841
+	/**
842
+	 * @param string $addon_name
843
+	 * @return void
844
+	 * @throws EE_Error
845
+	 */
846
+	private static function _register_shortcodes(string $addon_name)
847
+	{
848
+		if (
849
+			! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
850
+			|| ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
851
+		) {
852
+			EE_Register_Shortcode::register(
853
+				$addon_name,
854
+				[
855
+					'shortcode_paths' => self::$_settings[ $addon_name ]['shortcode_paths'] ?? [],
856
+					'shortcode_fqcns' => self::$_settings[ $addon_name ]['shortcode_fqcns'] ?? [],
857
+				]
858
+			);
859
+		}
860
+	}
861
+
862
+
863
+	/**
864
+	 * @param string $addon_name
865
+	 * @return void
866
+	 * @throws EE_Error
867
+	 */
868
+	private static function _register_widgets(string $addon_name)
869
+	{
870
+		if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
871
+			EE_Register_Widget::register(
872
+				$addon_name,
873
+				['widget_paths' => self::$_settings[ $addon_name ]['widget_paths']]
874
+			);
875
+		}
876
+	}
877
+
878
+
879
+	/**
880
+	 * @param string $addon_name
881
+	 * @return void
882
+	 * @throws EE_Error
883
+	 */
884
+	private static function _register_capabilities(string $addon_name)
885
+	{
886
+		if (! empty(self::$_settings[ $addon_name ]['capabilities'])) {
887
+			EE_Register_Capabilities::register(
888
+				$addon_name,
889
+				[
890
+					'capabilities'    => self::$_settings[ $addon_name ]['capabilities'],
891
+					'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'],
892
+				]
893
+			);
894
+		}
895
+	}
896
+
897
+
898
+	/**
899
+	 * @param string $addon_name
900
+	 * @return void
901
+	 */
902
+	private static function _register_message_types(string $addon_name)
903
+	{
904
+		if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
905
+			add_action(
906
+				'EE_Brewing_Regular___messages_caf',
907
+				['EE_Register_Addon', 'register_message_types']
908
+			);
909
+		}
910
+	}
911
+
912
+
913
+	/**
914
+	 * @param string $addon_name
915
+	 * @return void
916
+	 * @throws EE_Error
917
+	 */
918
+	private static function _register_custom_post_types(string $addon_name)
919
+	{
920
+		if (
921
+			! empty(self::$_settings[ $addon_name ]['custom_post_types'])
922
+			|| ! empty(self::$_settings[ $addon_name ]['custom_taxonomies'])
923
+		) {
924
+			EE_Register_CPT::register(
925
+				$addon_name,
926
+				[
927
+					'cpts'          => self::$_settings[ $addon_name ]['custom_post_types'],
928
+					'cts'           => self::$_settings[ $addon_name ]['custom_taxonomies'],
929
+					'default_terms' => self::$_settings[ $addon_name ]['default_terms'],
930
+				]
931
+			);
932
+		}
933
+	}
934
+
935
+
936
+	/**
937
+	 * @param string $addon_name
938
+	 * @return void
939
+	 * @throws InvalidArgumentException
940
+	 * @throws InvalidInterfaceException
941
+	 * @throws InvalidDataTypeException
942
+	 * @throws DomainException
943
+	 * @throws EE_Error
944
+	 */
945
+	private static function _register_payment_methods(string $addon_name)
946
+	{
947
+		if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
948
+			EE_Register_Payment_Method::register(
949
+				$addon_name,
950
+				['payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']]
951
+			);
952
+		}
953
+	}
954
+
955
+
956
+	/**
957
+	 * @param string $addon_name
958
+	 * @return void
959
+	 * @throws InvalidArgumentException
960
+	 * @throws InvalidInterfaceException
961
+	 * @throws InvalidDataTypeException
962
+	 * @throws DomainException
963
+	 */
964
+	private static function registerPrivacyPolicies(string $addon_name)
965
+	{
966
+		if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) {
967
+			EE_Register_Privacy_Policy::register(
968
+				$addon_name,
969
+				self::$_settings[ $addon_name ]['privacy_policies']
970
+			);
971
+		}
972
+	}
973
+
974
+
975
+	/**
976
+	 * @param string $addon_name
977
+	 * @return void
978
+	 */
979
+	private static function registerPersonalDataExporters(string $addon_name)
980
+	{
981
+		if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) {
982
+			EE_Register_Personal_Data_Eraser::register(
983
+				$addon_name,
984
+				self::$_settings[ $addon_name ]['personal_data_exporters']
985
+			);
986
+		}
987
+	}
988
+
989
+
990
+	/**
991
+	 * @param string $addon_name
992
+	 * @return void
993
+	 */
994
+	private static function registerPersonalDataErasers(string $addon_name)
995
+	{
996
+		if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) {
997
+			EE_Register_Personal_Data_Eraser::register(
998
+				$addon_name,
999
+				self::$_settings[ $addon_name ]['personal_data_erasers']
1000
+			);
1001
+		}
1002
+	}
1003
+
1004
+
1005
+	/**
1006
+	 * Loads and instantiates the EE_Addon class and adds it onto the registry
1007
+	 *
1008
+	 * @param string $addon_name
1009
+	 * @return EE_Addon
1010
+	 * @throws InvalidArgumentException
1011
+	 * @throws InvalidInterfaceException
1012
+	 * @throws InvalidDataTypeException
1013
+	 */
1014
+	private static function _load_and_init_addon_class(string $addon_name): EE_Addon
1015
+	{
1016
+		$addon = self::$loader->getShared(
1017
+			self::$_settings[ $addon_name ]['class_name'],
1018
+			['EE_Registry::create(addon)' => true]
1019
+		);
1020
+		if (! $addon instanceof EE_Addon) {
1021
+			throw new DomainException(
1022
+				sprintf(
1023
+					esc_html__('The "%1$s" EE_Addon class failed to instantiate!', 'event_espresso'),
1024
+					self::$_settings[ $addon_name ]['class_name']
1025
+				)
1026
+			);
1027
+		}
1028
+		// setter inject dep map if required
1029
+		if ($addon->dependencyMap() === null) {
1030
+			$addon->setDependencyMap(self::$loader->getShared('EE_Dependency_Map'));
1031
+		}
1032
+		// setter inject domain if required
1033
+		EE_Register_Addon::injectAddonDomain($addon_name, $addon);
1034
+
1035
+		$addon->set_name($addon_name);
1036
+		$addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']);
1037
+		$addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']);
1038
+		$addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']);
1039
+		$addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']);
1040
+		$addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']);
1041
+		$addon->set_version(self::$_settings[ $addon_name ]['version']);
1042
+		$addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version']));
1043
+		$addon->set_config_section(self::$_settings[ $addon_name ]['config_section']);
1044
+		$addon->set_config_class(self::$_settings[ $addon_name ]['config_class']);
1045
+		$addon->set_config_name(self::$_settings[ $addon_name ]['config_name']);
1046
+		do_action(
1047
+			'AHEE__EE_Register_Addon___load_and_init_addon_class',
1048
+			$addon,
1049
+			$addon_name,
1050
+			self::$_settings
1051
+		);
1052
+		// unfortunately this can't be hooked in upon construction,
1053
+		// because we don't have the plugin's mainfile path upon construction.
1054
+		register_deactivation_hook($addon->get_main_plugin_file(), [$addon, 'deactivation']);
1055
+		// call any additional admin_callback functions during load_admin_controller hook
1056
+		if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) {
1057
+			add_action(
1058
+				'AHEE__EE_System__load_controllers__load_admin_controllers',
1059
+				[$addon, self::$_settings[ $addon_name ]['admin_callback']]
1060
+			);
1061
+		}
1062
+		return $addon;
1063
+	}
1064
+
1065
+
1066
+	/**
1067
+	 * @param string   $addon_name
1068
+	 * @param EE_Addon $addon
1069
+	 * @since   4.10.13.p
1070
+	 */
1071
+	private static function injectAddonDomain(string $addon_name, EE_Addon $addon)
1072
+	{
1073
+		if ($addon instanceof RequiresDomainInterface && $addon->domain() === null) {
1074
+			// using supplied Domain object
1075
+			$domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface
1076
+				? self::$_settings[ $addon_name ]['domain']
1077
+				: null;
1078
+			// or construct one using Domain FQCN
1079
+			if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') {
1080
+				$domain = self::$loader->getShared(
1081
+					self::$_settings[ $addon_name ]['domain_fqcn'],
1082
+					[
1083
+						new EventEspresso\core\domain\values\FilePath(
1084
+							self::$_settings[ $addon_name ]['main_file_path']
1085
+						),
1086
+						EventEspresso\core\domain\values\Version::fromString(
1087
+							self::$_settings[ $addon_name ]['version']
1088
+						),
1089
+					]
1090
+				);
1091
+			}
1092
+			if ($domain instanceof DomainInterface) {
1093
+				$addon->setDomain($domain);
1094
+			}
1095
+		}
1096
+	}
1097
+
1098
+
1099
+	/**
1100
+	 * @return void
1101
+	 * @deprecated 5.0.0.p
1102
+	 */
1103
+	public static function load_pue_update()
1104
+	{
1105
+	}
1106
+
1107
+
1108
+	/**
1109
+	 * Callback for EE_Brewing_Regular__messages_caf hook used to register message types.
1110
+	 *
1111
+	 * @return void
1112
+	 * @throws EE_Error
1113
+	 * @since 4.4.0
1114
+	 */
1115
+	public static function register_message_types()
1116
+	{
1117
+		foreach (self::$_settings as $settings) {
1118
+			if (! empty($settings['message_types'])) {
1119
+				foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) {
1120
+					EE_Register_Message_Type::register($message_type, $message_type_settings);
1121
+				}
1122
+			}
1123
+		}
1124
+	}
1125
+
1126
+
1127
+	private static function registerLicense($addon_name)
1128
+	{
1129
+		static $request = null;
1130
+		if ($request === null) {
1131
+			/** @var RequestInterface $request */
1132
+			$request = LoaderFactory::getLoader()->getShared(RequestInterface::class);
1133
+		}
1134
+		if ($request->isWordPressHeartbeat()) {
1135
+			return;
1136
+		}
1137
+		$addon_settings = self::$_settings[ $addon_name ] ?? [];
1138
+		if (empty($addon_settings)) {
1139
+			return;
1140
+		}
1141
+		$license_data = isset($addon_settings['license']) ? (array) $addon_settings['license'] : [];
1142
+		// copy known values from addon settings to license data if anything's missing
1143
+		$license_data += [
1144
+			'main_file_path'   => $addon_settings['main_file_path'] ?? '',
1145
+			'min_core_version' => $addon_settings['min_core_version'] ?? '',
1146
+			'plugin_id'        => 0, // no corresponding value in addon settings
1147
+			'plugin_slug'      => $addon_settings['plugin_slug'] ?? '',
1148
+			'version'          => $addon_settings['version'] ?? '',
1149
+		];
1150
+		EventEspresso\core\services\licensing\AddonLicense::register($addon_name, $license_data);
1151
+	}
1152
+
1153
+
1154
+	/**
1155
+	 * This deregisters an addon that was previously registered with a specific addon_name.
1156
+	 *
1157
+	 * @param string $addon_name the name for the addon that was previously registered
1158
+	 * @throws DomainException
1159
+	 * @throws InvalidArgumentException
1160
+	 * @throws InvalidDataTypeException
1161
+	 * @throws InvalidInterfaceException
1162
+	 * @since    4.3.0
1163
+	 */
1164
+	public static function deregister(string $addon_name = '')
1165
+	{
1166
+		if (isset(self::$_settings[ $addon_name ]['class_name'])) {
1167
+			try {
1168
+				do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name);
1169
+				$class_name = self::$_settings[ $addon_name ]['class_name'];
1170
+				if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
1171
+					// setup DMS
1172
+					EE_Register_Data_Migration_Scripts::deregister($addon_name);
1173
+				}
1174
+				if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
1175
+					// register admin page
1176
+					EE_Register_Admin_Page::deregister($addon_name);
1177
+				}
1178
+				if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
1179
+					// add to list of modules to be registered
1180
+					EE_Register_Module::deregister($addon_name);
1181
+				}
1182
+				if (
1183
+					! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
1184
+					|| ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
1185
+				) {
1186
+					// add to list of shortcodes to be registered
1187
+					EE_Register_Shortcode::deregister($addon_name);
1188
+				}
1189
+				if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
1190
+					// if config_class present let's register config.
1191
+					EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']);
1192
+				}
1193
+				if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
1194
+					// add to list of widgets to be registered
1195
+					EE_Register_Widget::deregister($addon_name);
1196
+				}
1197
+				if (
1198
+					! empty(self::$_settings[ $addon_name ]['model_paths'])
1199
+					|| ! empty(self::$_settings[ $addon_name ]['class_paths'])
1200
+				) {
1201
+					// add to list of shortcodes to be registered
1202
+					EE_Register_Model::deregister($addon_name);
1203
+				}
1204
+				if (
1205
+					! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
1206
+					|| ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
1207
+				) {
1208
+					// add to list of shortcodes to be registered
1209
+					EE_Register_Model_Extensions::deregister($addon_name);
1210
+				}
1211
+				if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
1212
+					foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) {
1213
+						EE_Register_Message_Type::deregister($message_type);
1214
+					}
1215
+				}
1216
+				// deregister capabilities for addon
1217
+				if (
1218
+					! empty(self::$_settings[ $addon_name ]['capabilities'])
1219
+					|| ! empty(self::$_settings[ $addon_name ]['capability_maps'])
1220
+				) {
1221
+					EE_Register_Capabilities::deregister($addon_name);
1222
+				}
1223
+				// deregister custom_post_types for addon
1224
+				if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) {
1225
+					EE_Register_CPT::deregister($addon_name);
1226
+				}
1227
+				if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
1228
+					EE_Register_Payment_Method::deregister($addon_name);
1229
+				}
1230
+				$addon = EE_Registry::instance()->getAddon($class_name);
1231
+				if ($addon instanceof EE_Addon) {
1232
+					remove_action(
1233
+						'deactivate_' . $addon->get_main_plugin_file_basename(),
1234
+						[$addon, 'deactivation']
1235
+					);
1236
+					remove_action(
1237
+						'AHEE__EE_System__perform_activations_upgrades_and_migrations',
1238
+						[$addon, 'initialize_db_if_no_migrations_required']
1239
+					);
1240
+					// remove `after_registration` call
1241
+					remove_action(
1242
+						'AHEE__EE_System__load_espresso_addons__complete',
1243
+						[$addon, 'after_registration'],
1244
+						999
1245
+					);
1246
+				}
1247
+				EE_Registry::instance()->removeAddon($class_name);
1248
+				LoaderFactory::getLoader()->remove($class_name);
1249
+			} catch (OutOfBoundsException $addon_not_yet_registered_exception) {
1250
+				// the add-on was not yet registered in the registry,
1251
+				// so RegistryContainer::__get() throws this exception.
1252
+				// also no need to worry about this or log it,
1253
+				// it's ok to deregister an add-on before its registered in the registry
1254
+			} catch (Exception $e) {
1255
+				new ExceptionLogger($e);
1256
+			}
1257
+			unset(self::$_settings[ $addon_name ]);
1258
+			do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name);
1259
+		}
1260
+	}
1261
+
1262
+
1263
+	public static function reset(): void
1264
+	{
1265
+		EE_Register_Addon::$_settings = [];
1266
+	}
1267
+
1268
+
1269
+	public static function resetAll(): void
1270
+	{
1271
+		// EE_Register_Addon::reset();
1272
+		EE_Register_Admin_Page::reset();
1273
+		EE_Register_Capabilities::reset();
1274
+		EE_Register_Config::reset();
1275
+		EE_Register_CPT::reset();
1276
+		EE_Register_Data_Migration_Scripts::reset();
1277
+		EE_Register_Message_Type::reset();
1278
+		EE_Register_Messages_Shortcode_Library::reset();
1279
+		EE_Register_Messages_Template_Pack::reset();
1280
+		EE_Register_Messages_Template_Variations::reset();
1281
+		EE_Register_Model::reset();
1282
+		EE_Register_Model_Extensions::reset();
1283
+		EE_Register_Module::reset();
1284
+		EE_Register_Payment_Method::reset();
1285
+		EE_Register_Personal_Data_Eraser::reset();
1286
+		EE_Register_Personal_Data_Exporter::reset();
1287
+		EE_Register_Privacy_Policy::reset();
1288
+		EE_Register_Shortcode::reset();
1289
+		EE_Register_Widget::reset();
1290
+	}
1291 1291
 }
Please login to merge, or discard this patch.
Spacing   +110 added lines, -110 removed lines patch added patch discarded remove patch
@@ -76,15 +76,15 @@  discard block
 block discarded – undo
76 76
         // offsets:    0 . 1 . 2 . 3 . 4
77 77
         $version_parts = explode('.', $min_core_version);
78 78
         // check they specified the micro version (after 2nd period)
79
-        if (! isset($version_parts[2])) {
79
+        if ( ! isset($version_parts[2])) {
80 80
             $version_parts[2] = '0';
81 81
         }
82 82
         // if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible
83 83
         // soon we can assume that's 'rc', but this current version is 'alpha'
84
-        if (! isset($version_parts[3])) {
84
+        if ( ! isset($version_parts[3])) {
85 85
             $version_parts[3] = 'dev';
86 86
         }
87
-        if (! isset($version_parts[4])) {
87
+        if ( ! isset($version_parts[4])) {
88 88
             $version_parts[4] = '000';
89 89
         }
90 90
         return implode('.', $version_parts);
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
     public static function register(string $addon_name = '', array $setup_args = []): bool
262 262
     {
263 263
         // $addon_name = basename($addon_name);
264
-        if (! self::$loader instanceof LoaderInterface) {
264
+        if ( ! self::$loader instanceof LoaderInterface) {
265 265
             self::$loader = LoaderFactory::getLoader();
266 266
         }
267 267
         // make sure this was called in the right place!
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
         );
302 302
         // does this addon work with this version of core or WordPress ?
303 303
         // does this addon work with this version of core or WordPress ?
304
-        if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
304
+        if ( ! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) {
305 305
             return false;
306 306
         }
307 307
         // register namespaces
@@ -379,7 +379,7 @@  discard block
 block discarded – undo
379 379
             );
380 380
         }
381 381
         // check that addon has not already been registered with that name
382
-        if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) {
382
+        if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) {
383 383
             throw new EE_Error(
384 384
                 sprintf(
385 385
                     esc_html__(
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
         // check if classname is fully  qualified or is a legacy classname already prefixed with 'EE_'
412 412
         return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0
413 413
             ? $class_name
414
-            : 'EE_' . $class_name;
414
+            : 'EE_'.$class_name;
415 415
     }
416 416
 
417 417
 
@@ -581,9 +581,9 @@  discard block
 block discarded – undo
581 581
         $incompatibility_message = '';
582 582
         // check whether this addon version is compatible with EE core
583 583
         if (
584
-            isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ])
584
+            isset(EE_Register_Addon::$_incompatible_addons[$addon_name])
585 585
             && ! self::_meets_min_core_version_requirement(
586
-                EE_Register_Addon::$_incompatible_addons[ $addon_name ],
586
+                EE_Register_Addon::$_incompatible_addons[$addon_name],
587 587
                 $addon_settings['version']
588 588
             )
589 589
         ) {
@@ -594,7 +594,7 @@  discard block
 block discarded – undo
594 594
                 ),
595 595
                 $addon_name,
596 596
                 '<br />',
597
-                EE_Register_Addon::$_incompatible_addons[ $addon_name ],
597
+                EE_Register_Addon::$_incompatible_addons[$addon_name],
598 598
                 '<span style="font-weight: bold; color: #D54E21;">',
599 599
                 '</span><br />'
600 600
             );
@@ -626,7 +626,7 @@  discard block
 block discarded – undo
626 626
                 '</span><br />'
627 627
             );
628 628
         }
629
-        if (! empty($incompatibility_message)) {
629
+        if ( ! empty($incompatibility_message)) {
630 630
             // remove 'activate' from the REQUEST
631 631
             // so WP doesn't erroneously tell the user the plugin activated fine when it didn't
632 632
             /** @var RequestInterface $request */
@@ -637,8 +637,8 @@  discard block
 block discarded – undo
637 637
                 EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__);
638 638
             }
639 639
             unset($_GET['activate'], $_REQUEST['activate']);
640
-            if (! function_exists('deactivate_plugins')) {
641
-                require_once ABSPATH . 'wp-admin/includes/plugin.php';
640
+            if ( ! function_exists('deactivate_plugins')) {
641
+                require_once ABSPATH.'wp-admin/includes/plugin.php';
642 642
             }
643 643
             deactivate_plugins(plugin_basename($addon_settings['main_file_path']));
644 644
             // BAIL FROM THE ADDON REGISTRATION PROCESS
@@ -688,12 +688,12 @@  discard block
 block discarded – undo
688 688
             // to find if THIS is the addon that was activated, just check if we have already registered it or not
689 689
             // (as the newly-activated addon wasn't around the first time addons were registered).
690 690
             if (
691
-                ! isset(self::$_settings[ $addon_name ])
692
-                || (isset(self::$_settings[ $addon_name ])
693
-                    && ! isset(self::$_settings[ $addon_name ]['class_name'])
691
+                ! isset(self::$_settings[$addon_name])
692
+                || (isset(self::$_settings[$addon_name])
693
+                    && ! isset(self::$_settings[$addon_name]['class_name'])
694 694
                 )
695 695
             ) {
696
-                self::$_settings[ $addon_name ] = $addon_settings;
696
+                self::$_settings[$addon_name] = $addon_settings;
697 697
                 $addon                          = self::_load_and_init_addon_class($addon_name);
698 698
                 $addon->set_activation_indicator_option();
699 699
                 // dont bother setting up the rest of the addon.
@@ -702,10 +702,10 @@  discard block
 block discarded – undo
702 702
             return true;
703 703
         }
704 704
         // make sure addon settings are set correctly without overwriting anything existing
705
-        if (isset(self::$_settings[ $addon_name ])) {
706
-            self::$_settings[ $addon_name ] += $addon_settings;
705
+        if (isset(self::$_settings[$addon_name])) {
706
+            self::$_settings[$addon_name] += $addon_settings;
707 707
         } else {
708
-            self::$_settings[ $addon_name ] = $addon_settings;
708
+            self::$_settings[$addon_name] = $addon_settings;
709 709
         }
710 710
         return false;
711 711
     }
@@ -718,13 +718,13 @@  discard block
 block discarded – undo
718 718
      */
719 719
     private static function _setup_autoloaders(string $addon_name)
720 720
     {
721
-        if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) {
721
+        if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) {
722 722
             // setup autoloader for single file
723
-            EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']);
723
+            EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']);
724 724
         }
725 725
         // setup autoloaders for folders
726
-        if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) {
727
-            foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) {
726
+        if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) {
727
+            foreach ((array) self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) {
728 728
                 EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder);
729 729
             }
730 730
         }
@@ -742,27 +742,27 @@  discard block
 block discarded – undo
742 742
     {
743 743
         // register new models
744 744
         if (
745
-            ! empty(self::$_settings[ $addon_name ]['model_paths'])
746
-            || ! empty(self::$_settings[ $addon_name ]['class_paths'])
745
+            ! empty(self::$_settings[$addon_name]['model_paths'])
746
+            || ! empty(self::$_settings[$addon_name]['class_paths'])
747 747
         ) {
748 748
             EE_Register_Model::register(
749 749
                 $addon_name,
750 750
                 [
751
-                    'model_paths' => self::$_settings[ $addon_name ]['model_paths'],
752
-                    'class_paths' => self::$_settings[ $addon_name ]['class_paths'],
751
+                    'model_paths' => self::$_settings[$addon_name]['model_paths'],
752
+                    'class_paths' => self::$_settings[$addon_name]['class_paths'],
753 753
                 ]
754 754
             );
755 755
         }
756 756
         // register model extensions
757 757
         if (
758
-            ! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
759
-            || ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
758
+            ! empty(self::$_settings[$addon_name]['model_extension_paths'])
759
+            || ! empty(self::$_settings[$addon_name]['class_extension_paths'])
760 760
         ) {
761 761
             EE_Register_Model_Extensions::register(
762 762
                 $addon_name,
763 763
                 [
764
-                    'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'],
765
-                    'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'],
764
+                    'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'],
765
+                    'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'],
766 766
                 ]
767 767
             );
768 768
         }
@@ -777,10 +777,10 @@  discard block
 block discarded – undo
777 777
     private static function _register_data_migration_scripts(string $addon_name)
778 778
     {
779 779
         // setup DMS
780
-        if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
780
+        if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) {
781 781
             EE_Register_Data_Migration_Scripts::register(
782 782
                 $addon_name,
783
-                ['dms_paths' => self::$_settings[ $addon_name ]['dms_paths']]
783
+                ['dms_paths' => self::$_settings[$addon_name]['dms_paths']]
784 784
             );
785 785
         }
786 786
     }
@@ -794,12 +794,12 @@  discard block
 block discarded – undo
794 794
     private static function _register_config(string $addon_name)
795 795
     {
796 796
         // if config_class is present let's register config.
797
-        if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
797
+        if ( ! empty(self::$_settings[$addon_name]['config_class'])) {
798 798
             EE_Register_Config::register(
799
-                self::$_settings[ $addon_name ]['config_class'],
799
+                self::$_settings[$addon_name]['config_class'],
800 800
                 [
801
-                    'config_section' => self::$_settings[ $addon_name ]['config_section'],
802
-                    'config_name'    => self::$_settings[ $addon_name ]['config_name'],
801
+                    'config_section' => self::$_settings[$addon_name]['config_section'],
802
+                    'config_name'    => self::$_settings[$addon_name]['config_name'],
803 803
                 ]
804 804
             );
805 805
         }
@@ -813,10 +813,10 @@  discard block
 block discarded – undo
813 813
      */
814 814
     private static function _register_admin_pages(string $addon_name)
815 815
     {
816
-        if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
816
+        if ( ! empty(self::$_settings[$addon_name]['admin_path'])) {
817 817
             EE_Register_Admin_Page::register(
818 818
                 $addon_name,
819
-                ['page_path' => self::$_settings[ $addon_name ]['admin_path']]
819
+                ['page_path' => self::$_settings[$addon_name]['admin_path']]
820 820
             );
821 821
         }
822 822
     }
@@ -829,10 +829,10 @@  discard block
 block discarded – undo
829 829
      */
830 830
     private static function _register_modules(string $addon_name)
831 831
     {
832
-        if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
832
+        if ( ! empty(self::$_settings[$addon_name]['module_paths'])) {
833 833
             EE_Register_Module::register(
834 834
                 $addon_name,
835
-                ['module_paths' => self::$_settings[ $addon_name ]['module_paths']]
835
+                ['module_paths' => self::$_settings[$addon_name]['module_paths']]
836 836
             );
837 837
         }
838 838
     }
@@ -846,14 +846,14 @@  discard block
 block discarded – undo
846 846
     private static function _register_shortcodes(string $addon_name)
847 847
     {
848 848
         if (
849
-            ! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
850
-            || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
849
+            ! empty(self::$_settings[$addon_name]['shortcode_paths'])
850
+            || ! empty(self::$_settings[$addon_name]['shortcode_fqcns'])
851 851
         ) {
852 852
             EE_Register_Shortcode::register(
853 853
                 $addon_name,
854 854
                 [
855
-                    'shortcode_paths' => self::$_settings[ $addon_name ]['shortcode_paths'] ?? [],
856
-                    'shortcode_fqcns' => self::$_settings[ $addon_name ]['shortcode_fqcns'] ?? [],
855
+                    'shortcode_paths' => self::$_settings[$addon_name]['shortcode_paths'] ?? [],
856
+                    'shortcode_fqcns' => self::$_settings[$addon_name]['shortcode_fqcns'] ?? [],
857 857
                 ]
858 858
             );
859 859
         }
@@ -867,10 +867,10 @@  discard block
 block discarded – undo
867 867
      */
868 868
     private static function _register_widgets(string $addon_name)
869 869
     {
870
-        if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
870
+        if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) {
871 871
             EE_Register_Widget::register(
872 872
                 $addon_name,
873
-                ['widget_paths' => self::$_settings[ $addon_name ]['widget_paths']]
873
+                ['widget_paths' => self::$_settings[$addon_name]['widget_paths']]
874 874
             );
875 875
         }
876 876
     }
@@ -883,12 +883,12 @@  discard block
 block discarded – undo
883 883
      */
884 884
     private static function _register_capabilities(string $addon_name)
885 885
     {
886
-        if (! empty(self::$_settings[ $addon_name ]['capabilities'])) {
886
+        if ( ! empty(self::$_settings[$addon_name]['capabilities'])) {
887 887
             EE_Register_Capabilities::register(
888 888
                 $addon_name,
889 889
                 [
890
-                    'capabilities'    => self::$_settings[ $addon_name ]['capabilities'],
891
-                    'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'],
890
+                    'capabilities'    => self::$_settings[$addon_name]['capabilities'],
891
+                    'capability_maps' => self::$_settings[$addon_name]['capability_maps'],
892 892
                 ]
893 893
             );
894 894
         }
@@ -901,7 +901,7 @@  discard block
 block discarded – undo
901 901
      */
902 902
     private static function _register_message_types(string $addon_name)
903 903
     {
904
-        if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
904
+        if ( ! empty(self::$_settings[$addon_name]['message_types'])) {
905 905
             add_action(
906 906
                 'EE_Brewing_Regular___messages_caf',
907 907
                 ['EE_Register_Addon', 'register_message_types']
@@ -918,15 +918,15 @@  discard block
 block discarded – undo
918 918
     private static function _register_custom_post_types(string $addon_name)
919 919
     {
920 920
         if (
921
-            ! empty(self::$_settings[ $addon_name ]['custom_post_types'])
922
-            || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies'])
921
+            ! empty(self::$_settings[$addon_name]['custom_post_types'])
922
+            || ! empty(self::$_settings[$addon_name]['custom_taxonomies'])
923 923
         ) {
924 924
             EE_Register_CPT::register(
925 925
                 $addon_name,
926 926
                 [
927
-                    'cpts'          => self::$_settings[ $addon_name ]['custom_post_types'],
928
-                    'cts'           => self::$_settings[ $addon_name ]['custom_taxonomies'],
929
-                    'default_terms' => self::$_settings[ $addon_name ]['default_terms'],
927
+                    'cpts'          => self::$_settings[$addon_name]['custom_post_types'],
928
+                    'cts'           => self::$_settings[$addon_name]['custom_taxonomies'],
929
+                    'default_terms' => self::$_settings[$addon_name]['default_terms'],
930 930
                 ]
931 931
             );
932 932
         }
@@ -944,10 +944,10 @@  discard block
 block discarded – undo
944 944
      */
945 945
     private static function _register_payment_methods(string $addon_name)
946 946
     {
947
-        if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
947
+        if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
948 948
             EE_Register_Payment_Method::register(
949 949
                 $addon_name,
950
-                ['payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']]
950
+                ['payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']]
951 951
             );
952 952
         }
953 953
     }
@@ -963,10 +963,10 @@  discard block
 block discarded – undo
963 963
      */
964 964
     private static function registerPrivacyPolicies(string $addon_name)
965 965
     {
966
-        if (! empty(self::$_settings[ $addon_name ]['privacy_policies'])) {
966
+        if ( ! empty(self::$_settings[$addon_name]['privacy_policies'])) {
967 967
             EE_Register_Privacy_Policy::register(
968 968
                 $addon_name,
969
-                self::$_settings[ $addon_name ]['privacy_policies']
969
+                self::$_settings[$addon_name]['privacy_policies']
970 970
             );
971 971
         }
972 972
     }
@@ -978,10 +978,10 @@  discard block
 block discarded – undo
978 978
      */
979 979
     private static function registerPersonalDataExporters(string $addon_name)
980 980
     {
981
-        if (! empty(self::$_settings[ $addon_name ]['personal_data_exporters'])) {
981
+        if ( ! empty(self::$_settings[$addon_name]['personal_data_exporters'])) {
982 982
             EE_Register_Personal_Data_Eraser::register(
983 983
                 $addon_name,
984
-                self::$_settings[ $addon_name ]['personal_data_exporters']
984
+                self::$_settings[$addon_name]['personal_data_exporters']
985 985
             );
986 986
         }
987 987
     }
@@ -993,10 +993,10 @@  discard block
 block discarded – undo
993 993
      */
994 994
     private static function registerPersonalDataErasers(string $addon_name)
995 995
     {
996
-        if (! empty(self::$_settings[ $addon_name ]['personal_data_erasers'])) {
996
+        if ( ! empty(self::$_settings[$addon_name]['personal_data_erasers'])) {
997 997
             EE_Register_Personal_Data_Eraser::register(
998 998
                 $addon_name,
999
-                self::$_settings[ $addon_name ]['personal_data_erasers']
999
+                self::$_settings[$addon_name]['personal_data_erasers']
1000 1000
             );
1001 1001
         }
1002 1002
     }
@@ -1014,14 +1014,14 @@  discard block
 block discarded – undo
1014 1014
     private static function _load_and_init_addon_class(string $addon_name): EE_Addon
1015 1015
     {
1016 1016
         $addon = self::$loader->getShared(
1017
-            self::$_settings[ $addon_name ]['class_name'],
1017
+            self::$_settings[$addon_name]['class_name'],
1018 1018
             ['EE_Registry::create(addon)' => true]
1019 1019
         );
1020
-        if (! $addon instanceof EE_Addon) {
1020
+        if ( ! $addon instanceof EE_Addon) {
1021 1021
             throw new DomainException(
1022 1022
                 sprintf(
1023 1023
                     esc_html__('The "%1$s" EE_Addon class failed to instantiate!', 'event_espresso'),
1024
-                    self::$_settings[ $addon_name ]['class_name']
1024
+                    self::$_settings[$addon_name]['class_name']
1025 1025
                 )
1026 1026
             );
1027 1027
         }
@@ -1033,16 +1033,16 @@  discard block
 block discarded – undo
1033 1033
         EE_Register_Addon::injectAddonDomain($addon_name, $addon);
1034 1034
 
1035 1035
         $addon->set_name($addon_name);
1036
-        $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']);
1037
-        $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']);
1038
-        $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']);
1039
-        $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']);
1040
-        $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']);
1041
-        $addon->set_version(self::$_settings[ $addon_name ]['version']);
1042
-        $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version']));
1043
-        $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']);
1044
-        $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']);
1045
-        $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']);
1036
+        $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']);
1037
+        $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']);
1038
+        $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']);
1039
+        $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']);
1040
+        $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']);
1041
+        $addon->set_version(self::$_settings[$addon_name]['version']);
1042
+        $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version']));
1043
+        $addon->set_config_section(self::$_settings[$addon_name]['config_section']);
1044
+        $addon->set_config_class(self::$_settings[$addon_name]['config_class']);
1045
+        $addon->set_config_name(self::$_settings[$addon_name]['config_name']);
1046 1046
         do_action(
1047 1047
             'AHEE__EE_Register_Addon___load_and_init_addon_class',
1048 1048
             $addon,
@@ -1053,10 +1053,10 @@  discard block
 block discarded – undo
1053 1053
         // because we don't have the plugin's mainfile path upon construction.
1054 1054
         register_deactivation_hook($addon->get_main_plugin_file(), [$addon, 'deactivation']);
1055 1055
         // call any additional admin_callback functions during load_admin_controller hook
1056
-        if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) {
1056
+        if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) {
1057 1057
             add_action(
1058 1058
                 'AHEE__EE_System__load_controllers__load_admin_controllers',
1059
-                [$addon, self::$_settings[ $addon_name ]['admin_callback']]
1059
+                [$addon, self::$_settings[$addon_name]['admin_callback']]
1060 1060
             );
1061 1061
         }
1062 1062
         return $addon;
@@ -1072,19 +1072,19 @@  discard block
 block discarded – undo
1072 1072
     {
1073 1073
         if ($addon instanceof RequiresDomainInterface && $addon->domain() === null) {
1074 1074
             // using supplied Domain object
1075
-            $domain = self::$_settings[ $addon_name ]['domain'] instanceof DomainInterface
1076
-                ? self::$_settings[ $addon_name ]['domain']
1075
+            $domain = self::$_settings[$addon_name]['domain'] instanceof DomainInterface
1076
+                ? self::$_settings[$addon_name]['domain']
1077 1077
                 : null;
1078 1078
             // or construct one using Domain FQCN
1079
-            if ($domain === null && self::$_settings[ $addon_name ]['domain_fqcn'] !== '') {
1079
+            if ($domain === null && self::$_settings[$addon_name]['domain_fqcn'] !== '') {
1080 1080
                 $domain = self::$loader->getShared(
1081
-                    self::$_settings[ $addon_name ]['domain_fqcn'],
1081
+                    self::$_settings[$addon_name]['domain_fqcn'],
1082 1082
                     [
1083 1083
                         new EventEspresso\core\domain\values\FilePath(
1084
-                            self::$_settings[ $addon_name ]['main_file_path']
1084
+                            self::$_settings[$addon_name]['main_file_path']
1085 1085
                         ),
1086 1086
                         EventEspresso\core\domain\values\Version::fromString(
1087
-                            self::$_settings[ $addon_name ]['version']
1087
+                            self::$_settings[$addon_name]['version']
1088 1088
                         ),
1089 1089
                     ]
1090 1090
                 );
@@ -1115,7 +1115,7 @@  discard block
 block discarded – undo
1115 1115
     public static function register_message_types()
1116 1116
     {
1117 1117
         foreach (self::$_settings as $settings) {
1118
-            if (! empty($settings['message_types'])) {
1118
+            if ( ! empty($settings['message_types'])) {
1119 1119
                 foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) {
1120 1120
                     EE_Register_Message_Type::register($message_type, $message_type_settings);
1121 1121
                 }
@@ -1134,7 +1134,7 @@  discard block
 block discarded – undo
1134 1134
         if ($request->isWordPressHeartbeat()) {
1135 1135
             return;
1136 1136
         }
1137
-        $addon_settings = self::$_settings[ $addon_name ] ?? [];
1137
+        $addon_settings = self::$_settings[$addon_name] ?? [];
1138 1138
         if (empty($addon_settings)) {
1139 1139
             return;
1140 1140
         }
@@ -1163,74 +1163,74 @@  discard block
 block discarded – undo
1163 1163
      */
1164 1164
     public static function deregister(string $addon_name = '')
1165 1165
     {
1166
-        if (isset(self::$_settings[ $addon_name ]['class_name'])) {
1166
+        if (isset(self::$_settings[$addon_name]['class_name'])) {
1167 1167
             try {
1168 1168
                 do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name);
1169
-                $class_name = self::$_settings[ $addon_name ]['class_name'];
1170
-                if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) {
1169
+                $class_name = self::$_settings[$addon_name]['class_name'];
1170
+                if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) {
1171 1171
                     // setup DMS
1172 1172
                     EE_Register_Data_Migration_Scripts::deregister($addon_name);
1173 1173
                 }
1174
-                if (! empty(self::$_settings[ $addon_name ]['admin_path'])) {
1174
+                if ( ! empty(self::$_settings[$addon_name]['admin_path'])) {
1175 1175
                     // register admin page
1176 1176
                     EE_Register_Admin_Page::deregister($addon_name);
1177 1177
                 }
1178
-                if (! empty(self::$_settings[ $addon_name ]['module_paths'])) {
1178
+                if ( ! empty(self::$_settings[$addon_name]['module_paths'])) {
1179 1179
                     // add to list of modules to be registered
1180 1180
                     EE_Register_Module::deregister($addon_name);
1181 1181
                 }
1182 1182
                 if (
1183
-                    ! empty(self::$_settings[ $addon_name ]['shortcode_paths'])
1184
-                    || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns'])
1183
+                    ! empty(self::$_settings[$addon_name]['shortcode_paths'])
1184
+                    || ! empty(self::$_settings[$addon_name]['shortcode_fqcns'])
1185 1185
                 ) {
1186 1186
                     // add to list of shortcodes to be registered
1187 1187
                     EE_Register_Shortcode::deregister($addon_name);
1188 1188
                 }
1189
-                if (! empty(self::$_settings[ $addon_name ]['config_class'])) {
1189
+                if ( ! empty(self::$_settings[$addon_name]['config_class'])) {
1190 1190
                     // if config_class present let's register config.
1191
-                    EE_Register_Config::deregister(self::$_settings[ $addon_name ]['config_class']);
1191
+                    EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']);
1192 1192
                 }
1193
-                if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) {
1193
+                if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) {
1194 1194
                     // add to list of widgets to be registered
1195 1195
                     EE_Register_Widget::deregister($addon_name);
1196 1196
                 }
1197 1197
                 if (
1198
-                    ! empty(self::$_settings[ $addon_name ]['model_paths'])
1199
-                    || ! empty(self::$_settings[ $addon_name ]['class_paths'])
1198
+                    ! empty(self::$_settings[$addon_name]['model_paths'])
1199
+                    || ! empty(self::$_settings[$addon_name]['class_paths'])
1200 1200
                 ) {
1201 1201
                     // add to list of shortcodes to be registered
1202 1202
                     EE_Register_Model::deregister($addon_name);
1203 1203
                 }
1204 1204
                 if (
1205
-                    ! empty(self::$_settings[ $addon_name ]['model_extension_paths'])
1206
-                    || ! empty(self::$_settings[ $addon_name ]['class_extension_paths'])
1205
+                    ! empty(self::$_settings[$addon_name]['model_extension_paths'])
1206
+                    || ! empty(self::$_settings[$addon_name]['class_extension_paths'])
1207 1207
                 ) {
1208 1208
                     // add to list of shortcodes to be registered
1209 1209
                     EE_Register_Model_Extensions::deregister($addon_name);
1210 1210
                 }
1211
-                if (! empty(self::$_settings[ $addon_name ]['message_types'])) {
1212
-                    foreach ((array) self::$_settings[ $addon_name ]['message_types'] as $message_type => $message_type_settings) {
1211
+                if ( ! empty(self::$_settings[$addon_name]['message_types'])) {
1212
+                    foreach ((array) self::$_settings[$addon_name]['message_types'] as $message_type => $message_type_settings) {
1213 1213
                         EE_Register_Message_Type::deregister($message_type);
1214 1214
                     }
1215 1215
                 }
1216 1216
                 // deregister capabilities for addon
1217 1217
                 if (
1218
-                    ! empty(self::$_settings[ $addon_name ]['capabilities'])
1219
-                    || ! empty(self::$_settings[ $addon_name ]['capability_maps'])
1218
+                    ! empty(self::$_settings[$addon_name]['capabilities'])
1219
+                    || ! empty(self::$_settings[$addon_name]['capability_maps'])
1220 1220
                 ) {
1221 1221
                     EE_Register_Capabilities::deregister($addon_name);
1222 1222
                 }
1223 1223
                 // deregister custom_post_types for addon
1224
-                if (! empty(self::$_settings[ $addon_name ]['custom_post_types'])) {
1224
+                if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])) {
1225 1225
                     EE_Register_CPT::deregister($addon_name);
1226 1226
                 }
1227
-                if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) {
1227
+                if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) {
1228 1228
                     EE_Register_Payment_Method::deregister($addon_name);
1229 1229
                 }
1230 1230
                 $addon = EE_Registry::instance()->getAddon($class_name);
1231 1231
                 if ($addon instanceof EE_Addon) {
1232 1232
                     remove_action(
1233
-                        'deactivate_' . $addon->get_main_plugin_file_basename(),
1233
+                        'deactivate_'.$addon->get_main_plugin_file_basename(),
1234 1234
                         [$addon, 'deactivation']
1235 1235
                     );
1236 1236
                     remove_action(
@@ -1254,7 +1254,7 @@  discard block
 block discarded – undo
1254 1254
             } catch (Exception $e) {
1255 1255
                 new ExceptionLogger($e);
1256 1256
             }
1257
-            unset(self::$_settings[ $addon_name ]);
1257
+            unset(self::$_settings[$addon_name]);
1258 1258
             do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name);
1259 1259
         }
1260 1260
     }
Please login to merge, or discard this patch.
core/libraries/messages/EE_Messages_Scheduler.lib.php 2 patches
Indentation   +236 added lines, -236 removed lines patch added patch discarded remove patch
@@ -15,240 +15,240 @@
 block discarded – undo
15 15
  */
16 16
 class EE_Messages_Scheduler extends EE_Base
17 17
 {
18
-    /**
19
-     * Number of seconds between batch sends/generates on the cron job.
20
-     * Defaults to 5 minutes in seconds.  If you want to change this interval, you can use the native WordPress
21
-     * `cron_schedules` filter and modify the existing custom `ee_message_cron` schedule interval added.
22
-     *
23
-     * @type int
24
-     */
25
-    const message_cron_schedule = 300;
26
-
27
-
28
-    /**
29
-     * Constructor
30
-     */
31
-    public function __construct()
32
-    {
33
-        $this->setHooks();
34
-    }
35
-
36
-
37
-    public function setHooks(): void
38
-    {
39
-        // register tasks (and make sure only registered once).
40
-        if (! has_action('FHEE__EEH_Activation__get_cron_tasks', [$this, 'register_scheduled_tasks'])) {
41
-            add_action('FHEE__EEH_Activation__get_cron_tasks', [$this, 'register_scheduled_tasks']);
42
-        }
43
-
44
-        // register callbacks for scheduled events (but make sure they are set only once).
45
-        if (
46
-            ! has_action(
47
-                'AHEE__EE_Messages_Scheduler__generation',
48
-                ['EE_Messages_Scheduler', 'batch_generation']
49
-            )
50
-        ) {
51
-            add_action('AHEE__EE_Messages_Scheduler__generation', ['EE_Messages_Scheduler', 'batch_generation']);
52
-            add_action('AHEE__EE_Messages_Scheduler__sending', ['EE_Messages_Scheduler', 'batch_sending']);
53
-            add_action('AHEE__EE_Messages_Scheduler__cleanup', ['EE_Messages_Scheduler', 'cleanup']);
54
-        }
55
-
56
-        // add custom schedules
57
-        add_filter('cron_schedules', [$this, 'custom_schedules']);
58
-    }
59
-
60
-
61
-    /**
62
-     * Add custom schedules for wp_cron
63
-     *
64
-     * @param array $schedules
65
-     * @return array
66
-     */
67
-    public function custom_schedules(array $schedules): array
68
-    {
69
-        $schedules['ee_message_cron'] = [
70
-            'interval' => self::message_cron_schedule,
71
-            'display'  => esc_html__(
72
-                'This is the cron time interval for EE Message schedules (defaults to once every 5 minutes)',
73
-                'event_espresso'
74
-            ),
75
-        ];
76
-        return $schedules;
77
-    }
78
-
79
-
80
-    /**
81
-     * Callback for FHEE__EEH_Activation__get_cron_tasks that is used to retrieve scheduled Cron events to add and
82
-     * remove.
83
-     *
84
-     * @param array $tasks already existing scheduled tasks
85
-     * @return array
86
-     * @throws EE_Error
87
-     * @throws ReflectionException
88
-     */
89
-    public function register_scheduled_tasks(array $tasks): array
90
-    {
91
-        EE_Registry::instance()->load_helper('DTT_Helper');
92
-        $tasks['AHEE__EE_Messages_Scheduler__generation'] = 'ee_message_cron';
93
-        $tasks['AHEE__EE_Messages_Scheduler__sending']    = 'ee_message_cron';
94
-        $tasks['AHEE__EE_Messages_Scheduler__cleanup']    = [EEH_DTT_Helper::tomorrow(), 'daily'];
95
-        return $tasks;
96
-    }
97
-
98
-
99
-    /**
100
-     * This initiates a non-blocking separate request to execute on a scheduled task.
101
-     * Note: The EED_Messages module has the handlers for these requests.
102
-     *
103
-     * @param string $task The task the request is being generated for.
104
-     * @throws EE_Error
105
-     * @throws ReflectionException
106
-     */
107
-    public static function initiate_scheduled_non_blocking_request(string $task)
108
-    {
109
-        if (
110
-            apply_filters(
111
-                'EE_Messages_Scheduler__initiate_scheduled_non_blocking_request__do_separate_request',
112
-                true
113
-            )
114
-        ) {
115
-            $request_url  = add_query_arg(
116
-                array_merge(
117
-                    ['ee' => 'msg_cron_trigger'],
118
-                    EE_Messages_Scheduler::get_request_params($task)
119
-                ),
120
-                site_url()
121
-            );
122
-            $request_args = [
123
-                'timeout'     => 300,
124
-                'blocking'    => (defined('DOING_CRON') && DOING_CRON)
125
-                    || (defined('DOING_AJAX') && DOING_AJAX),
126
-                'sslverify'   => Manager::verifySSL(),
127
-                'redirection' => 10,
128
-            ];
129
-            $response     = wp_remote_get($request_url, $request_args);
130
-            if (is_wp_error($response)) {
131
-                trigger_error($response->get_error_message());
132
-            }
133
-        } else {
134
-            EE_Messages_Scheduler::initiate_immediate_request_on_cron($task);
135
-        }
136
-    }
137
-
138
-
139
-    /**
140
-     * This returns
141
-     * the request params used for a scheduled message task request.
142
-     *
143
-     * @param string $task The task the request is for.
144
-     * @return array
145
-     */
146
-    public static function get_request_params(string $task): array
147
-    {
148
-        // transient is used for flood control on msg_cron_trigger requests
149
-        $transient_key = 'ee_trans_' . uniqid($task);
150
-        set_transient($transient_key, 1, 5 * MINUTE_IN_SECONDS);
151
-        return [
152
-            'type' => $task,
153
-            'key'  => $transient_key,
154
-        ];
155
-    }
156
-
157
-
158
-    /**
159
-     * This is used to execute an immediate call to the run_cron task performed by EED_Messages
160
-     *
161
-     * @param string $task The task the request is being generated for.
162
-     * @throws EE_Error
163
-     * @throws ReflectionException
164
-     */
165
-    public static function initiate_immediate_request_on_cron(string $task)
166
-    {
167
-        /** @var RequestInterface $request */
168
-        $request      = LoaderFactory::getLoader()->getShared(RequestInterface::class);
169
-        $request_args = EE_Messages_Scheduler::get_request_params($task);
170
-        // set those request args in the request so it gets picked up
171
-        foreach ($request_args as $request_key => $request_value) {
172
-            $request->setRequestParam($request_key, $request_value);
173
-        }
174
-        EED_Messages::instance()->run_cron();
175
-    }
176
-
177
-
178
-    /**
179
-     * Callback for scheduled AHEE__EE_Messages_Scheduler__generation wp cron event
180
-     *
181
-     * @throws EE_Error
182
-     * @throws ReflectionException
183
-     */
184
-    public static function batch_generation()
185
-    {
186
-        /**
187
-         * @see filter usage in EE_Messages_Queue::initiate_request_by_priority()
188
-         */
189
-        if (
190
-            ! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
191
-            || ! EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
192
-        ) {
193
-            EE_Messages_Scheduler::initiate_immediate_request_on_cron('generate');
194
-        }
195
-    }
196
-
197
-
198
-    /**
199
-     * Callback for scheduled AHEE__EE_Messages_Scheduler__sending
200
-     *
201
-     * @throws EE_Error
202
-     * @throws ReflectionException
203
-     */
204
-    public static function batch_sending()
205
-    {
206
-        /**
207
-         * @see filter usage in EE_Messages_Queue::initiate_request_by_priority()
208
-         */
209
-        if (
210
-            ! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
211
-            || ! EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
212
-        ) {
213
-            EE_Messages_Scheduler::initiate_immediate_request_on_cron('send');
214
-        }
215
-    }
216
-
217
-
218
-    /**
219
-     * This is the callback for the `AHEE__EE_Messages_Scheduler__cleanup` scheduled event action.
220
-     * This runs once a day and if cleanup is active (set via messages settings), it will (by default) delete
221
-     * permanently from the database messages that have a MSG_modified date older than 30 days.
222
-     *
223
-     * @throws EE_Error
224
-     * @throws ReflectionException
225
-     */
226
-    public static function cleanup()
227
-    {
228
-        // First, confirm that the generation and sending EE_Messages_Scheduler crons are
229
-        // set and reschedule them if they are not.
230
-        $message_crons_to_check = [
231
-            'AHEE__EE_Messages_Scheduler__generation' => 'ee_message_cron',
232
-            'AHEE__EE_Messages_Scheduler__sending'    => 'ee_message_cron',
233
-        ];
234
-        foreach ($message_crons_to_check as $hook_name => $frequency) {
235
-            if (! wp_next_scheduled($hook_name)) {
236
-                wp_schedule_event(time(), $frequency, $hook_name);
237
-            }
238
-        }
239
-
240
-        // check if user has cleanup turned on or if we're in maintenance mode.  If in maintenance mode we'll wait
241
-        // until the next scheduled event.
242
-        if (! EE_Registry::instance()->CFG->messages->delete_threshold || DbStatus::isOffline()) {
243
-            return;
244
-        }
245
-
246
-        /**
247
-         * This filter switch allows other code (such as the EE_Worker_Queue add-on) to replace this with its own handling
248
-         * of deleting messages.
249
-         */
250
-        if (apply_filters('FHEE__EE_Messages_Scheduler__cleanup__handle_cleanup_on_cron', true)) {
251
-            EEM_Message::instance()->delete_old_messages(EE_Registry::instance()->CFG->messages->delete_threshold);
252
-        }
253
-    }
18
+	/**
19
+	 * Number of seconds between batch sends/generates on the cron job.
20
+	 * Defaults to 5 minutes in seconds.  If you want to change this interval, you can use the native WordPress
21
+	 * `cron_schedules` filter and modify the existing custom `ee_message_cron` schedule interval added.
22
+	 *
23
+	 * @type int
24
+	 */
25
+	const message_cron_schedule = 300;
26
+
27
+
28
+	/**
29
+	 * Constructor
30
+	 */
31
+	public function __construct()
32
+	{
33
+		$this->setHooks();
34
+	}
35
+
36
+
37
+	public function setHooks(): void
38
+	{
39
+		// register tasks (and make sure only registered once).
40
+		if (! has_action('FHEE__EEH_Activation__get_cron_tasks', [$this, 'register_scheduled_tasks'])) {
41
+			add_action('FHEE__EEH_Activation__get_cron_tasks', [$this, 'register_scheduled_tasks']);
42
+		}
43
+
44
+		// register callbacks for scheduled events (but make sure they are set only once).
45
+		if (
46
+			! has_action(
47
+				'AHEE__EE_Messages_Scheduler__generation',
48
+				['EE_Messages_Scheduler', 'batch_generation']
49
+			)
50
+		) {
51
+			add_action('AHEE__EE_Messages_Scheduler__generation', ['EE_Messages_Scheduler', 'batch_generation']);
52
+			add_action('AHEE__EE_Messages_Scheduler__sending', ['EE_Messages_Scheduler', 'batch_sending']);
53
+			add_action('AHEE__EE_Messages_Scheduler__cleanup', ['EE_Messages_Scheduler', 'cleanup']);
54
+		}
55
+
56
+		// add custom schedules
57
+		add_filter('cron_schedules', [$this, 'custom_schedules']);
58
+	}
59
+
60
+
61
+	/**
62
+	 * Add custom schedules for wp_cron
63
+	 *
64
+	 * @param array $schedules
65
+	 * @return array
66
+	 */
67
+	public function custom_schedules(array $schedules): array
68
+	{
69
+		$schedules['ee_message_cron'] = [
70
+			'interval' => self::message_cron_schedule,
71
+			'display'  => esc_html__(
72
+				'This is the cron time interval for EE Message schedules (defaults to once every 5 minutes)',
73
+				'event_espresso'
74
+			),
75
+		];
76
+		return $schedules;
77
+	}
78
+
79
+
80
+	/**
81
+	 * Callback for FHEE__EEH_Activation__get_cron_tasks that is used to retrieve scheduled Cron events to add and
82
+	 * remove.
83
+	 *
84
+	 * @param array $tasks already existing scheduled tasks
85
+	 * @return array
86
+	 * @throws EE_Error
87
+	 * @throws ReflectionException
88
+	 */
89
+	public function register_scheduled_tasks(array $tasks): array
90
+	{
91
+		EE_Registry::instance()->load_helper('DTT_Helper');
92
+		$tasks['AHEE__EE_Messages_Scheduler__generation'] = 'ee_message_cron';
93
+		$tasks['AHEE__EE_Messages_Scheduler__sending']    = 'ee_message_cron';
94
+		$tasks['AHEE__EE_Messages_Scheduler__cleanup']    = [EEH_DTT_Helper::tomorrow(), 'daily'];
95
+		return $tasks;
96
+	}
97
+
98
+
99
+	/**
100
+	 * This initiates a non-blocking separate request to execute on a scheduled task.
101
+	 * Note: The EED_Messages module has the handlers for these requests.
102
+	 *
103
+	 * @param string $task The task the request is being generated for.
104
+	 * @throws EE_Error
105
+	 * @throws ReflectionException
106
+	 */
107
+	public static function initiate_scheduled_non_blocking_request(string $task)
108
+	{
109
+		if (
110
+			apply_filters(
111
+				'EE_Messages_Scheduler__initiate_scheduled_non_blocking_request__do_separate_request',
112
+				true
113
+			)
114
+		) {
115
+			$request_url  = add_query_arg(
116
+				array_merge(
117
+					['ee' => 'msg_cron_trigger'],
118
+					EE_Messages_Scheduler::get_request_params($task)
119
+				),
120
+				site_url()
121
+			);
122
+			$request_args = [
123
+				'timeout'     => 300,
124
+				'blocking'    => (defined('DOING_CRON') && DOING_CRON)
125
+					|| (defined('DOING_AJAX') && DOING_AJAX),
126
+				'sslverify'   => Manager::verifySSL(),
127
+				'redirection' => 10,
128
+			];
129
+			$response     = wp_remote_get($request_url, $request_args);
130
+			if (is_wp_error($response)) {
131
+				trigger_error($response->get_error_message());
132
+			}
133
+		} else {
134
+			EE_Messages_Scheduler::initiate_immediate_request_on_cron($task);
135
+		}
136
+	}
137
+
138
+
139
+	/**
140
+	 * This returns
141
+	 * the request params used for a scheduled message task request.
142
+	 *
143
+	 * @param string $task The task the request is for.
144
+	 * @return array
145
+	 */
146
+	public static function get_request_params(string $task): array
147
+	{
148
+		// transient is used for flood control on msg_cron_trigger requests
149
+		$transient_key = 'ee_trans_' . uniqid($task);
150
+		set_transient($transient_key, 1, 5 * MINUTE_IN_SECONDS);
151
+		return [
152
+			'type' => $task,
153
+			'key'  => $transient_key,
154
+		];
155
+	}
156
+
157
+
158
+	/**
159
+	 * This is used to execute an immediate call to the run_cron task performed by EED_Messages
160
+	 *
161
+	 * @param string $task The task the request is being generated for.
162
+	 * @throws EE_Error
163
+	 * @throws ReflectionException
164
+	 */
165
+	public static function initiate_immediate_request_on_cron(string $task)
166
+	{
167
+		/** @var RequestInterface $request */
168
+		$request      = LoaderFactory::getLoader()->getShared(RequestInterface::class);
169
+		$request_args = EE_Messages_Scheduler::get_request_params($task);
170
+		// set those request args in the request so it gets picked up
171
+		foreach ($request_args as $request_key => $request_value) {
172
+			$request->setRequestParam($request_key, $request_value);
173
+		}
174
+		EED_Messages::instance()->run_cron();
175
+	}
176
+
177
+
178
+	/**
179
+	 * Callback for scheduled AHEE__EE_Messages_Scheduler__generation wp cron event
180
+	 *
181
+	 * @throws EE_Error
182
+	 * @throws ReflectionException
183
+	 */
184
+	public static function batch_generation()
185
+	{
186
+		/**
187
+		 * @see filter usage in EE_Messages_Queue::initiate_request_by_priority()
188
+		 */
189
+		if (
190
+			! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
191
+			|| ! EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
192
+		) {
193
+			EE_Messages_Scheduler::initiate_immediate_request_on_cron('generate');
194
+		}
195
+	}
196
+
197
+
198
+	/**
199
+	 * Callback for scheduled AHEE__EE_Messages_Scheduler__sending
200
+	 *
201
+	 * @throws EE_Error
202
+	 * @throws ReflectionException
203
+	 */
204
+	public static function batch_sending()
205
+	{
206
+		/**
207
+		 * @see filter usage in EE_Messages_Queue::initiate_request_by_priority()
208
+		 */
209
+		if (
210
+			! apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
211
+			|| ! EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
212
+		) {
213
+			EE_Messages_Scheduler::initiate_immediate_request_on_cron('send');
214
+		}
215
+	}
216
+
217
+
218
+	/**
219
+	 * This is the callback for the `AHEE__EE_Messages_Scheduler__cleanup` scheduled event action.
220
+	 * This runs once a day and if cleanup is active (set via messages settings), it will (by default) delete
221
+	 * permanently from the database messages that have a MSG_modified date older than 30 days.
222
+	 *
223
+	 * @throws EE_Error
224
+	 * @throws ReflectionException
225
+	 */
226
+	public static function cleanup()
227
+	{
228
+		// First, confirm that the generation and sending EE_Messages_Scheduler crons are
229
+		// set and reschedule them if they are not.
230
+		$message_crons_to_check = [
231
+			'AHEE__EE_Messages_Scheduler__generation' => 'ee_message_cron',
232
+			'AHEE__EE_Messages_Scheduler__sending'    => 'ee_message_cron',
233
+		];
234
+		foreach ($message_crons_to_check as $hook_name => $frequency) {
235
+			if (! wp_next_scheduled($hook_name)) {
236
+				wp_schedule_event(time(), $frequency, $hook_name);
237
+			}
238
+		}
239
+
240
+		// check if user has cleanup turned on or if we're in maintenance mode.  If in maintenance mode we'll wait
241
+		// until the next scheduled event.
242
+		if (! EE_Registry::instance()->CFG->messages->delete_threshold || DbStatus::isOffline()) {
243
+			return;
244
+		}
245
+
246
+		/**
247
+		 * This filter switch allows other code (such as the EE_Worker_Queue add-on) to replace this with its own handling
248
+		 * of deleting messages.
249
+		 */
250
+		if (apply_filters('FHEE__EE_Messages_Scheduler__cleanup__handle_cleanup_on_cron', true)) {
251
+			EEM_Message::instance()->delete_old_messages(EE_Registry::instance()->CFG->messages->delete_threshold);
252
+		}
253
+	}
254 254
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
     public function setHooks(): void
38 38
     {
39 39
         // register tasks (and make sure only registered once).
40
-        if (! has_action('FHEE__EEH_Activation__get_cron_tasks', [$this, 'register_scheduled_tasks'])) {
40
+        if ( ! has_action('FHEE__EEH_Activation__get_cron_tasks', [$this, 'register_scheduled_tasks'])) {
41 41
             add_action('FHEE__EEH_Activation__get_cron_tasks', [$this, 'register_scheduled_tasks']);
42 42
         }
43 43
 
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
                 true
113 113
             )
114 114
         ) {
115
-            $request_url  = add_query_arg(
115
+            $request_url = add_query_arg(
116 116
                 array_merge(
117 117
                     ['ee' => 'msg_cron_trigger'],
118 118
                     EE_Messages_Scheduler::get_request_params($task)
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
                 'sslverify'   => Manager::verifySSL(),
127 127
                 'redirection' => 10,
128 128
             ];
129
-            $response     = wp_remote_get($request_url, $request_args);
129
+            $response = wp_remote_get($request_url, $request_args);
130 130
             if (is_wp_error($response)) {
131 131
                 trigger_error($response->get_error_message());
132 132
             }
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
     public static function get_request_params(string $task): array
147 147
     {
148 148
         // transient is used for flood control on msg_cron_trigger requests
149
-        $transient_key = 'ee_trans_' . uniqid($task);
149
+        $transient_key = 'ee_trans_'.uniqid($task);
150 150
         set_transient($transient_key, 1, 5 * MINUTE_IN_SECONDS);
151 151
         return [
152 152
             'type' => $task,
@@ -232,14 +232,14 @@  discard block
 block discarded – undo
232 232
             'AHEE__EE_Messages_Scheduler__sending'    => 'ee_message_cron',
233 233
         ];
234 234
         foreach ($message_crons_to_check as $hook_name => $frequency) {
235
-            if (! wp_next_scheduled($hook_name)) {
235
+            if ( ! wp_next_scheduled($hook_name)) {
236 236
                 wp_schedule_event(time(), $frequency, $hook_name);
237 237
             }
238 238
         }
239 239
 
240 240
         // check if user has cleanup turned on or if we're in maintenance mode.  If in maintenance mode we'll wait
241 241
         // until the next scheduled event.
242
-        if (! EE_Registry::instance()->CFG->messages->delete_threshold || DbStatus::isOffline()) {
242
+        if ( ! EE_Registry::instance()->CFG->messages->delete_threshold || DbStatus::isOffline()) {
243 243
             return;
244 244
         }
245 245
 
Please login to merge, or discard this patch.
core/EE_Cron_Tasks.core.php 2 patches
Indentation   +562 added lines, -562 removed lines patch added patch discarded remove patch
@@ -17,568 +17,568 @@
 block discarded – undo
17 17
  */
18 18
 class EE_Cron_Tasks extends EE_Base
19 19
 {
20
-    /**
21
-     * WordPress doesn't allow duplicate crons within 10 minutes of the original,
22
-     * so we'll set our retry time for just over 10 minutes to avoid that
23
-     */
24
-    const reschedule_timeout = 605;
25
-
26
-
27
-    private static ?EE_Cron_Tasks $_instance = null;
28
-
29
-
30
-    public static function instance(): ?EE_Cron_Tasks
31
-    {
32
-        if (! self::$_instance instanceof EE_Cron_Tasks) {
33
-            self::$_instance = new self();
34
-        }
35
-        return self::$_instance;
36
-    }
37
-
38
-
39
-    /**
40
-     * @throws InvalidDataTypeException
41
-     * @throws InvalidInterfaceException
42
-     * @throws InvalidArgumentException
43
-     * @throws EE_Error
44
-     * @throws ReflectionException
45
-     */
46
-    private function __construct()
47
-    {
48
-        // verify that WP Cron is enabled
49
-        if (
50
-            defined('DISABLE_WP_CRON')
51
-            && DISABLE_WP_CRON
52
-            && is_admin()
53
-            && ! get_option('ee_disabled_wp_cron_check')
54
-        ) {
55
-            /**
56
-             * This needs to be delayed until after the config is loaded because EE_Cron_Tasks is constructed before
57
-             * config is loaded.
58
-             * This is intentionally using a anonymous function so that its not easily de-registered.  Client code
59
-             * wanting to not have this functionality can just register its own action at a priority after this one to
60
-             * reverse any changes.
61
-             */
62
-            add_action(
63
-                'AHEE__EE_System__load_core_configuration__complete',
64
-                function () {
65
-                    EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true;
66
-                    EE_Registry::instance()->NET_CFG->update_config(true, false);
67
-                    add_option('ee_disabled_wp_cron_check', 1, '', false);
68
-                }
69
-            );
70
-        }
71
-        // UPDATE TRANSACTION WITH PAYMENT
72
-        add_action(
73
-            'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2',
74
-            ['EE_Cron_Tasks', 'setup_update_for_transaction_with_payment'],
75
-            10,
76
-            2
77
-        );
78
-        // ABANDONED / EXPIRED TRANSACTION CHECK
79
-        add_action(
80
-            'AHEE__EE_Cron_Tasks__expired_transaction_check',
81
-            ['EE_Cron_Tasks', 'expired_transaction_check']
82
-        );
83
-        // CLEAN OUT JUNK TRANSACTIONS AND RELATED DATA
84
-        add_action(
85
-            'AHEE__EE_Cron_Tasks__clean_up_junk_transactions',
86
-            ['EE_Cron_Tasks', 'clean_out_junk_transactions']
87
-        );
88
-        // logging
89
-        add_action(
90
-            'AHEE__EE_System__load_core_configuration__complete',
91
-            [CronUtilities::class, 'logScheduledEspressoCrons']
92
-        );
93
-        EE_Registry::instance()->load_lib('Messages_Scheduler');
94
-        // clean out old gateway logs
95
-        add_action(
96
-            'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs',
97
-            ['EE_Cron_Tasks', 'clean_out_old_gateway_logs']
98
-        );
99
-    }
100
-
101
-
102
-    /**
103
-     * @return void
104
-     * @deprecated 5.0.40.p
105
-     */
106
-    public static function log_scheduled_ee_crons(): void
107
-    {
108
-        CronUtilities::logScheduledEspressoCrons();
109
-    }
110
-
111
-
112
-    /**
113
-     * reschedule_cron_for_transactions_if_maintenance_mode
114
-     * if Maintenance Mode is active, this will reschedule a cron to run again in 10 minutes
115
-     *
116
-     * @param string $cron_task
117
-     * @param array  $TXN_IDs
118
-     * @return bool
119
-     * @throws DomainException
120
-     */
121
-    public static function reschedule_cron_for_transactions_if_maintenance_mode(string $cron_task, array $TXN_IDs): bool
122
-    {
123
-        if (! method_exists('EE_Cron_Tasks', $cron_task)) {
124
-            throw new DomainException(
125
-                sprintf(
126
-                    esc_html__('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'),
127
-                    $cron_task
128
-                )
129
-            );
130
-        }
131
-        // reschedule the cron if we can't hit the db right now
132
-        if (DbStatus::isOffline()) {
133
-            foreach ($TXN_IDs as $TXN_ID => $additional_vars) {
134
-                // ensure $additional_vars is an array
135
-                $additional_vars = is_array($additional_vars) ? $additional_vars : [$additional_vars];
136
-                // reset cron job for the TXN
137
-                call_user_func_array(
138
-                    ['EE_Cron_Tasks', $cron_task],
139
-                    array_merge(
140
-                        [
141
-                            time() + (10 * MINUTE_IN_SECONDS),
142
-                            $TXN_ID,
143
-                        ],
144
-                        $additional_vars
145
-                    )
146
-                );
147
-            }
148
-            return true;
149
-        }
150
-        return false;
151
-    }
152
-
153
-
154
-
155
-
156
-    /****************  UPDATE TRANSACTION WITH PAYMENT ****************/
157
-
158
-
159
-    /**
160
-     * array of TXN IDs and the payment
161
-     *
162
-     * @var array
163
-     */
164
-    protected static array $_update_transactions_with_payment = [];
165
-
166
-
167
-    /**
168
-     * schedule_update_transaction_with_payment
169
-     * sets a wp_schedule_single_event() for updating any TXNs that may
170
-     * require updating due to recently received payments
171
-     *
172
-     * @param int $timestamp
173
-     * @param int $TXN_ID
174
-     * @param int $PAY_ID
175
-     */
176
-    public static function schedule_update_transaction_with_payment(
177
-        int $timestamp,
178
-        int $TXN_ID,
179
-        int $PAY_ID
180
-    ): void {
181
-        // validate $TXN_ID and $timestamp
182
-        $TXN_ID    = absint($TXN_ID);
183
-        $timestamp = absint($timestamp);
184
-        if ($TXN_ID && $timestamp) {
185
-            wp_schedule_single_event(
186
-                $timestamp,
187
-                'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2',
188
-                [$TXN_ID, $PAY_ID]
189
-            );
190
-        }
191
-    }
192
-
193
-
194
-    /**
195
-     * setup_update_for_transaction_with_payment
196
-     * this is the callback for the action hook:
197
-     * 'AHEE__EE_Cron_Tasks__update_transaction_with_payment'
198
-     * which is setup by EE_Cron_Tasks::schedule_update_transaction_with_payment().
199
-     * The passed TXN_ID and associated payment gets added to an array, and then
200
-     * the EE_Cron_Tasks::update_transaction_with_payment() function is hooked into
201
-     * 'shutdown' which will actually handle the processing of any
202
-     * transactions requiring updating, because doing so now would be too early
203
-     * and the required resources may not be available
204
-     *
205
-     * @param int $TXN_ID
206
-     * @param int $PAY_ID
207
-     */
208
-    public static function setup_update_for_transaction_with_payment(int $TXN_ID = 0, int $PAY_ID = 0): void
209
-    {
210
-        do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID');
211
-        if (absint($TXN_ID)) {
212
-            self::$_update_transactions_with_payment[ $TXN_ID ] = $PAY_ID;
213
-            add_action(
214
-                'shutdown',
215
-                ['EE_Cron_Tasks', 'update_transaction_with_payment'],
216
-                5
217
-            );
218
-        }
219
-    }
220
-
221
-
222
-    /**
223
-     * update_transaction_with_payment
224
-     * loops through the self::$_abandoned_transactions array
225
-     * and attempts to finalize any TXNs that have not been completed
226
-     * but have had their sessions expired, most likely due to a user not
227
-     * returning from an off-site payment gateway
228
-     *
229
-     * @throws EE_Error
230
-     * @throws DomainException
231
-     * @throws InvalidDataTypeException
232
-     * @throws InvalidInterfaceException
233
-     * @throws InvalidArgumentException
234
-     * @throws ReflectionException
235
-     * @throws RuntimeException
236
-     */
237
-    public static function update_transaction_with_payment(): void
238
-    {
239
-        if (
20
+	/**
21
+	 * WordPress doesn't allow duplicate crons within 10 minutes of the original,
22
+	 * so we'll set our retry time for just over 10 minutes to avoid that
23
+	 */
24
+	const reschedule_timeout = 605;
25
+
26
+
27
+	private static ?EE_Cron_Tasks $_instance = null;
28
+
29
+
30
+	public static function instance(): ?EE_Cron_Tasks
31
+	{
32
+		if (! self::$_instance instanceof EE_Cron_Tasks) {
33
+			self::$_instance = new self();
34
+		}
35
+		return self::$_instance;
36
+	}
37
+
38
+
39
+	/**
40
+	 * @throws InvalidDataTypeException
41
+	 * @throws InvalidInterfaceException
42
+	 * @throws InvalidArgumentException
43
+	 * @throws EE_Error
44
+	 * @throws ReflectionException
45
+	 */
46
+	private function __construct()
47
+	{
48
+		// verify that WP Cron is enabled
49
+		if (
50
+			defined('DISABLE_WP_CRON')
51
+			&& DISABLE_WP_CRON
52
+			&& is_admin()
53
+			&& ! get_option('ee_disabled_wp_cron_check')
54
+		) {
55
+			/**
56
+			 * This needs to be delayed until after the config is loaded because EE_Cron_Tasks is constructed before
57
+			 * config is loaded.
58
+			 * This is intentionally using a anonymous function so that its not easily de-registered.  Client code
59
+			 * wanting to not have this functionality can just register its own action at a priority after this one to
60
+			 * reverse any changes.
61
+			 */
62
+			add_action(
63
+				'AHEE__EE_System__load_core_configuration__complete',
64
+				function () {
65
+					EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true;
66
+					EE_Registry::instance()->NET_CFG->update_config(true, false);
67
+					add_option('ee_disabled_wp_cron_check', 1, '', false);
68
+				}
69
+			);
70
+		}
71
+		// UPDATE TRANSACTION WITH PAYMENT
72
+		add_action(
73
+			'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2',
74
+			['EE_Cron_Tasks', 'setup_update_for_transaction_with_payment'],
75
+			10,
76
+			2
77
+		);
78
+		// ABANDONED / EXPIRED TRANSACTION CHECK
79
+		add_action(
80
+			'AHEE__EE_Cron_Tasks__expired_transaction_check',
81
+			['EE_Cron_Tasks', 'expired_transaction_check']
82
+		);
83
+		// CLEAN OUT JUNK TRANSACTIONS AND RELATED DATA
84
+		add_action(
85
+			'AHEE__EE_Cron_Tasks__clean_up_junk_transactions',
86
+			['EE_Cron_Tasks', 'clean_out_junk_transactions']
87
+		);
88
+		// logging
89
+		add_action(
90
+			'AHEE__EE_System__load_core_configuration__complete',
91
+			[CronUtilities::class, 'logScheduledEspressoCrons']
92
+		);
93
+		EE_Registry::instance()->load_lib('Messages_Scheduler');
94
+		// clean out old gateway logs
95
+		add_action(
96
+			'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs',
97
+			['EE_Cron_Tasks', 'clean_out_old_gateway_logs']
98
+		);
99
+	}
100
+
101
+
102
+	/**
103
+	 * @return void
104
+	 * @deprecated 5.0.40.p
105
+	 */
106
+	public static function log_scheduled_ee_crons(): void
107
+	{
108
+		CronUtilities::logScheduledEspressoCrons();
109
+	}
110
+
111
+
112
+	/**
113
+	 * reschedule_cron_for_transactions_if_maintenance_mode
114
+	 * if Maintenance Mode is active, this will reschedule a cron to run again in 10 minutes
115
+	 *
116
+	 * @param string $cron_task
117
+	 * @param array  $TXN_IDs
118
+	 * @return bool
119
+	 * @throws DomainException
120
+	 */
121
+	public static function reschedule_cron_for_transactions_if_maintenance_mode(string $cron_task, array $TXN_IDs): bool
122
+	{
123
+		if (! method_exists('EE_Cron_Tasks', $cron_task)) {
124
+			throw new DomainException(
125
+				sprintf(
126
+					esc_html__('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'),
127
+					$cron_task
128
+				)
129
+			);
130
+		}
131
+		// reschedule the cron if we can't hit the db right now
132
+		if (DbStatus::isOffline()) {
133
+			foreach ($TXN_IDs as $TXN_ID => $additional_vars) {
134
+				// ensure $additional_vars is an array
135
+				$additional_vars = is_array($additional_vars) ? $additional_vars : [$additional_vars];
136
+				// reset cron job for the TXN
137
+				call_user_func_array(
138
+					['EE_Cron_Tasks', $cron_task],
139
+					array_merge(
140
+						[
141
+							time() + (10 * MINUTE_IN_SECONDS),
142
+							$TXN_ID,
143
+						],
144
+						$additional_vars
145
+					)
146
+				);
147
+			}
148
+			return true;
149
+		}
150
+		return false;
151
+	}
152
+
153
+
154
+
155
+
156
+	/****************  UPDATE TRANSACTION WITH PAYMENT ****************/
157
+
158
+
159
+	/**
160
+	 * array of TXN IDs and the payment
161
+	 *
162
+	 * @var array
163
+	 */
164
+	protected static array $_update_transactions_with_payment = [];
165
+
166
+
167
+	/**
168
+	 * schedule_update_transaction_with_payment
169
+	 * sets a wp_schedule_single_event() for updating any TXNs that may
170
+	 * require updating due to recently received payments
171
+	 *
172
+	 * @param int $timestamp
173
+	 * @param int $TXN_ID
174
+	 * @param int $PAY_ID
175
+	 */
176
+	public static function schedule_update_transaction_with_payment(
177
+		int $timestamp,
178
+		int $TXN_ID,
179
+		int $PAY_ID
180
+	): void {
181
+		// validate $TXN_ID and $timestamp
182
+		$TXN_ID    = absint($TXN_ID);
183
+		$timestamp = absint($timestamp);
184
+		if ($TXN_ID && $timestamp) {
185
+			wp_schedule_single_event(
186
+				$timestamp,
187
+				'AHEE__EE_Cron_Tasks__update_transaction_with_payment_2',
188
+				[$TXN_ID, $PAY_ID]
189
+			);
190
+		}
191
+	}
192
+
193
+
194
+	/**
195
+	 * setup_update_for_transaction_with_payment
196
+	 * this is the callback for the action hook:
197
+	 * 'AHEE__EE_Cron_Tasks__update_transaction_with_payment'
198
+	 * which is setup by EE_Cron_Tasks::schedule_update_transaction_with_payment().
199
+	 * The passed TXN_ID and associated payment gets added to an array, and then
200
+	 * the EE_Cron_Tasks::update_transaction_with_payment() function is hooked into
201
+	 * 'shutdown' which will actually handle the processing of any
202
+	 * transactions requiring updating, because doing so now would be too early
203
+	 * and the required resources may not be available
204
+	 *
205
+	 * @param int $TXN_ID
206
+	 * @param int $PAY_ID
207
+	 */
208
+	public static function setup_update_for_transaction_with_payment(int $TXN_ID = 0, int $PAY_ID = 0): void
209
+	{
210
+		do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID');
211
+		if (absint($TXN_ID)) {
212
+			self::$_update_transactions_with_payment[ $TXN_ID ] = $PAY_ID;
213
+			add_action(
214
+				'shutdown',
215
+				['EE_Cron_Tasks', 'update_transaction_with_payment'],
216
+				5
217
+			);
218
+		}
219
+	}
220
+
221
+
222
+	/**
223
+	 * update_transaction_with_payment
224
+	 * loops through the self::$_abandoned_transactions array
225
+	 * and attempts to finalize any TXNs that have not been completed
226
+	 * but have had their sessions expired, most likely due to a user not
227
+	 * returning from an off-site payment gateway
228
+	 *
229
+	 * @throws EE_Error
230
+	 * @throws DomainException
231
+	 * @throws InvalidDataTypeException
232
+	 * @throws InvalidInterfaceException
233
+	 * @throws InvalidArgumentException
234
+	 * @throws ReflectionException
235
+	 * @throws RuntimeException
236
+	 */
237
+	public static function update_transaction_with_payment(): void
238
+	{
239
+		if (
240 240
 // are there any TXNs that need cleaning up ?
241
-            empty(self::$_update_transactions_with_payment)
242
-            // reschedule the cron if we can't hit the db right now
243
-            || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
244
-                'schedule_update_transaction_with_payment',
245
-                self::$_update_transactions_with_payment
246
-            )
247
-        ) {
248
-            return;
249
-        }
250
-        /** @var EE_Transaction_Processor $transaction_processor */
251
-        $transaction_processor = LoaderFactory::getShared(EE_Transaction_Processor::class);
252
-        if ($transaction_processor instanceof EE_Transaction_Processor) {
253
-            // set revisit flag for payment processor
254
-            $transaction_processor->set_revisit();
255
-        }
256
-        // load EEM_Transaction
257
-        EE_Registry::instance()->load_model('Transaction');
258
-        foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) {
259
-            // reschedule the cron if we can't hit the db right now
260
-            if (DbStatus::isOffline()) {
261
-                // reset cron job for updating the TXN
262
-                EE_Cron_Tasks::schedule_update_transaction_with_payment(
263
-                    time() + EE_Cron_Tasks::reschedule_timeout,
264
-                    $TXN_ID,
265
-                    $PAY_ID
266
-                );
267
-                continue;
268
-            }
269
-            $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
270
-            $payment     = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
271
-            // verify transaction && try to update the TXN with any payments
272
-            if ($transaction instanceof EE_Transaction && $payment instanceof EE_Payment) {
273
-                /** @var PaymentProcessor $payment_processor */
274
-                $payment_processor = LoaderFactory::getShared(PaymentProcessor::class);
275
-                $payment_processor->updateTransactionBasedOnPayment($transaction, $payment, true, true);
276
-            }
277
-            unset(self::$_update_transactions_with_payment[ $TXN_ID ]);
278
-        }
279
-    }
280
-
281
-
282
-
283
-    /************  END OF UPDATE TRANSACTION WITH PAYMENT  ************/
284
-
285
-
286
-    /*****************  EXPIRED TRANSACTION CHECK *****************/
287
-
288
-
289
-    /**
290
-     * array of TXN IDs
291
-     *
292
-     * @var array
293
-     */
294
-    protected static array $_expired_transactions = [];
295
-
296
-
297
-    /**
298
-     * schedule_expired_transaction_check
299
-     * sets a wp_schedule_single_event() for following up on TXNs after their session has expired
300
-     *
301
-     * @param int $timestamp
302
-     * @param int $TXN_ID
303
-     */
304
-    public static function schedule_expired_transaction_check(
305
-        int $timestamp,
306
-        int $TXN_ID
307
-    ): void {
308
-        // validate $TXN_ID and $timestamp
309
-        $TXN_ID    = absint($TXN_ID);
310
-        $timestamp = absint($timestamp);
311
-        if ($TXN_ID && $timestamp) {
312
-            wp_schedule_single_event(
313
-                $timestamp,
314
-                'AHEE__EE_Cron_Tasks__expired_transaction_check',
315
-                [$TXN_ID]
316
-            );
317
-        }
318
-    }
319
-
320
-
321
-    /**
322
-     * expired_transaction_check
323
-     * this is the callback for the action hook:
324
-     * 'AHEE__EE_Cron_Tasks__transaction_session_expiration_check'
325
-     * which is utilized by wp_schedule_single_event()
326
-     * in \EED_Single_Page_Checkout::_initialize_transaction().
327
-     * The passed TXN_ID gets added to an array, and then the
328
-     * process_expired_transactions() function is hooked into
329
-     * 'AHEE__EE_System__core_loaded_and_ready' which will actually handle the
330
-     * processing of any failed transactions, because doing so now would be
331
-     * too early and the required resources may not be available
332
-     *
333
-     * @param int $TXN_ID
334
-     */
335
-    public static function expired_transaction_check(int $TXN_ID = 0): void
336
-    {
337
-        if (absint($TXN_ID)) {
338
-            self::$_expired_transactions[ $TXN_ID ] = $TXN_ID;
339
-            add_action(
340
-                'shutdown',
341
-                ['EE_Cron_Tasks', 'process_expired_transactions'],
342
-                5
343
-            );
344
-        }
345
-    }
346
-
347
-
348
-    /**
349
-     * process_expired_transactions
350
-     * loops through the self::$_expired_transactions array and processes any failed TXNs
351
-     *
352
-     * @throws EE_Error
353
-     * @throws InvalidDataTypeException
354
-     * @throws InvalidInterfaceException
355
-     * @throws InvalidArgumentException
356
-     * @throws ReflectionException
357
-     * @throws DomainException
358
-     * @throws RuntimeException
359
-     */
360
-    public static function process_expired_transactions(): void
361
-    {
362
-        if (
241
+			empty(self::$_update_transactions_with_payment)
242
+			// reschedule the cron if we can't hit the db right now
243
+			|| EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
244
+				'schedule_update_transaction_with_payment',
245
+				self::$_update_transactions_with_payment
246
+			)
247
+		) {
248
+			return;
249
+		}
250
+		/** @var EE_Transaction_Processor $transaction_processor */
251
+		$transaction_processor = LoaderFactory::getShared(EE_Transaction_Processor::class);
252
+		if ($transaction_processor instanceof EE_Transaction_Processor) {
253
+			// set revisit flag for payment processor
254
+			$transaction_processor->set_revisit();
255
+		}
256
+		// load EEM_Transaction
257
+		EE_Registry::instance()->load_model('Transaction');
258
+		foreach (self::$_update_transactions_with_payment as $TXN_ID => $PAY_ID) {
259
+			// reschedule the cron if we can't hit the db right now
260
+			if (DbStatus::isOffline()) {
261
+				// reset cron job for updating the TXN
262
+				EE_Cron_Tasks::schedule_update_transaction_with_payment(
263
+					time() + EE_Cron_Tasks::reschedule_timeout,
264
+					$TXN_ID,
265
+					$PAY_ID
266
+				);
267
+				continue;
268
+			}
269
+			$transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
270
+			$payment     = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
271
+			// verify transaction && try to update the TXN with any payments
272
+			if ($transaction instanceof EE_Transaction && $payment instanceof EE_Payment) {
273
+				/** @var PaymentProcessor $payment_processor */
274
+				$payment_processor = LoaderFactory::getShared(PaymentProcessor::class);
275
+				$payment_processor->updateTransactionBasedOnPayment($transaction, $payment, true, true);
276
+			}
277
+			unset(self::$_update_transactions_with_payment[ $TXN_ID ]);
278
+		}
279
+	}
280
+
281
+
282
+
283
+	/************  END OF UPDATE TRANSACTION WITH PAYMENT  ************/
284
+
285
+
286
+	/*****************  EXPIRED TRANSACTION CHECK *****************/
287
+
288
+
289
+	/**
290
+	 * array of TXN IDs
291
+	 *
292
+	 * @var array
293
+	 */
294
+	protected static array $_expired_transactions = [];
295
+
296
+
297
+	/**
298
+	 * schedule_expired_transaction_check
299
+	 * sets a wp_schedule_single_event() for following up on TXNs after their session has expired
300
+	 *
301
+	 * @param int $timestamp
302
+	 * @param int $TXN_ID
303
+	 */
304
+	public static function schedule_expired_transaction_check(
305
+		int $timestamp,
306
+		int $TXN_ID
307
+	): void {
308
+		// validate $TXN_ID and $timestamp
309
+		$TXN_ID    = absint($TXN_ID);
310
+		$timestamp = absint($timestamp);
311
+		if ($TXN_ID && $timestamp) {
312
+			wp_schedule_single_event(
313
+				$timestamp,
314
+				'AHEE__EE_Cron_Tasks__expired_transaction_check',
315
+				[$TXN_ID]
316
+			);
317
+		}
318
+	}
319
+
320
+
321
+	/**
322
+	 * expired_transaction_check
323
+	 * this is the callback for the action hook:
324
+	 * 'AHEE__EE_Cron_Tasks__transaction_session_expiration_check'
325
+	 * which is utilized by wp_schedule_single_event()
326
+	 * in \EED_Single_Page_Checkout::_initialize_transaction().
327
+	 * The passed TXN_ID gets added to an array, and then the
328
+	 * process_expired_transactions() function is hooked into
329
+	 * 'AHEE__EE_System__core_loaded_and_ready' which will actually handle the
330
+	 * processing of any failed transactions, because doing so now would be
331
+	 * too early and the required resources may not be available
332
+	 *
333
+	 * @param int $TXN_ID
334
+	 */
335
+	public static function expired_transaction_check(int $TXN_ID = 0): void
336
+	{
337
+		if (absint($TXN_ID)) {
338
+			self::$_expired_transactions[ $TXN_ID ] = $TXN_ID;
339
+			add_action(
340
+				'shutdown',
341
+				['EE_Cron_Tasks', 'process_expired_transactions'],
342
+				5
343
+			);
344
+		}
345
+	}
346
+
347
+
348
+	/**
349
+	 * process_expired_transactions
350
+	 * loops through the self::$_expired_transactions array and processes any failed TXNs
351
+	 *
352
+	 * @throws EE_Error
353
+	 * @throws InvalidDataTypeException
354
+	 * @throws InvalidInterfaceException
355
+	 * @throws InvalidArgumentException
356
+	 * @throws ReflectionException
357
+	 * @throws DomainException
358
+	 * @throws RuntimeException
359
+	 */
360
+	public static function process_expired_transactions(): void
361
+	{
362
+		if (
363 363
 // are there any TXNs that need cleaning up ?
364
-            empty(self::$_expired_transactions)
365
-            // reschedule the cron if we can't hit the db right now
366
-            || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
367
-                'schedule_expired_transaction_check',
368
-                self::$_expired_transactions
369
-            )
370
-        ) {
371
-            return;
372
-        }
373
-        /** @type EE_Transaction_Processor $transaction_processor */
374
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
375
-        // set revisit flag for txn processor
376
-        $transaction_processor->set_revisit();
377
-        // load EEM_Transaction
378
-        EE_Registry::instance()->load_model('Transaction');
379
-        foreach (self::$_expired_transactions as $TXN_ID) {
380
-            $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
381
-            // verify transaction and whether it is failed or not
382
-            if ($transaction instanceof EE_Transaction) {
383
-                switch ($transaction->status_ID()) {
384
-                    // Completed TXNs
385
-                    case EEM_Transaction::complete_status_code:
386
-                        // Don't update the transaction/registrations if the Primary Registration is Not Approved.
387
-                        $primary_registration = $transaction->primary_registration();
388
-                        if (
389
-                            $primary_registration instanceof EE_Registration
390
-                            && $primary_registration->status_ID() !== RegStatus::AWAITING_REVIEW
391
-                        ) {
392
-                            /** @type EE_Transaction_Processor $transaction_processor */
393
-                            $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
394
-                            $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
395
-                                $transaction,
396
-                                $transaction->last_payment()
397
-                            );
398
-                            do_action(
399
-                                'AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction',
400
-                                $transaction
401
-                            );
402
-                        }
403
-                        break;
404
-                    // Overpaid TXNs
405
-                    case EEM_Transaction::overpaid_status_code:
406
-                        do_action(
407
-                            'AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction',
408
-                            $transaction
409
-                        );
410
-                        break;
411
-                    // Incomplete TXNs
412
-                    case EEM_Transaction::incomplete_status_code:
413
-                        do_action(
414
-                            'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction',
415
-                            $transaction
416
-                        );
417
-                        // todo : move business logic into EE_Transaction_Processor for finalizing abandoned transactions
418
-                        break;
419
-                    // Abandoned TXNs
420
-                    case EEM_Transaction::abandoned_status_code:
421
-                        // run hook before updating transaction, primarily so
422
-                        // EED_Ticket_Sales_Monitor::process_abandoned_transactions() can release reserved tickets
423
-                        do_action(
424
-                            'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction',
425
-                            $transaction
426
-                        );
427
-                        // don't finalize the TXN if it has already been completed
428
-                        if ($transaction->all_reg_steps_completed() !== true) {
429
-                            /** @var PaymentProcessor $payment_processor */
430
-                            $payment_processor = LoaderFactory::getShared(PaymentProcessor::class);
431
-                            // let's simulate an IPN here which will trigger any notifications that need to go out
432
-                            $payment_processor->updateTransactionBasedOnPayment(
433
-                                $transaction,
434
-                                $transaction->last_payment(),
435
-                                true,
436
-                                true
437
-                            );
438
-                        }
439
-                        break;
440
-                    // Failed TXNs
441
-                    case EEM_Transaction::failed_status_code:
442
-                        do_action(
443
-                            'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction',
444
-                            $transaction
445
-                        );
446
-                        // todo :
447
-                        // perform garbage collection here and remove clean_out_junk_transactions()
448
-                        // $registrations = $transaction->registrations();
449
-                        // if (! empty($registrations)) {
450
-                        //     foreach ($registrations as $registration) {
451
-                        //         if ($registration instanceof EE_Registration) {
452
-                        //             $delete_registration = true;
453
-                        //             if ($registration->attendee() instanceof EE_Attendee) {
454
-                        //                 $delete_registration = false;
455
-                        //             }
456
-                        //             if ($delete_registration) {
457
-                        //                 $registration->delete_permanently();
458
-                        //                 $registration->delete_related_permanently();
459
-                        //             }
460
-                        //         }
461
-                        //     }
462
-                        // }
463
-                        break;
464
-                }
465
-            }
466
-            unset(self::$_expired_transactions[ $TXN_ID ]);
467
-        }
468
-    }
469
-
470
-
471
-
472
-    /*************  END OF EXPIRED TRANSACTION CHECK  *************/
473
-
474
-
475
-    /************* START CLEAN UP BOT TRANSACTIONS **********************/
476
-
477
-
478
-    /**
479
-     * callback for 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'
480
-     * which is setup during activation to run on an hourly cron
481
-     *
482
-     * @throws EE_Error
483
-     * @throws InvalidArgumentException
484
-     * @throws InvalidDataTypeException
485
-     * @throws InvalidInterfaceException
486
-     * @throws DomainException
487
-     * @throws ReflectionException
488
-     */
489
-    public static function clean_out_junk_transactions(): void
490
-    {
491
-        if (DbStatus::isOnline()) {
492
-            EED_Ticket_Sales_Monitor::reset_reservation_counts();
493
-            EEM_Transaction::instance()->delete_junk_transactions();
494
-            EEM_Registration::instance()->delete_registrations_with_no_transaction();
495
-            EEM_Line_Item::instance()->delete_line_items_with_no_transaction();
496
-        }
497
-    }
498
-
499
-
500
-    /**
501
-     * Deletes old gateway logs. After about a week we usually don't need them for debugging. But folks can filter that.
502
-     *
503
-     * @throws EE_Error
504
-     * @throws InvalidDataTypeException
505
-     * @throws InvalidInterfaceException
506
-     * @throws InvalidArgumentException
507
-     * @throws ReflectionException
508
-     * @throws Exception
509
-     */
510
-    public static function clean_out_old_gateway_logs(): void
511
-    {
512
-        if (DbStatus::isOnline()) {
513
-            $reg_config               = LoaderFactory::getLoader()->load('EE_Registration_Config');
514
-            $time_diff_for_comparison = apply_filters(
515
-                'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison',
516
-                '-' . $reg_config->gateway_log_lifespan
517
-            );
518
-            EEM_Change_Log::instance()->delete_gateway_logs_older_than(new DateTime($time_diff_for_comparison));
519
-        }
520
-    }
521
-
522
-
523
-    /*****************  FINALIZE ABANDONED TRANSACTIONS *****************/
524
-
525
-
526
-    /**
527
-     * @var array
528
-     */
529
-    protected static array $_abandoned_transactions = [];
530
-
531
-
532
-    /**
533
-     * @param int $timestamp
534
-     * @param int $TXN_ID
535
-     * @deprecated
536
-     */
537
-    public static function schedule_finalize_abandoned_transactions_check(int $timestamp, int $TXN_ID): void
538
-    {
539
-        EE_Cron_Tasks::schedule_expired_transaction_check($timestamp, $TXN_ID);
540
-    }
541
-
542
-
543
-    /**
544
-     * @param int $TXN_ID
545
-     * @deprecated
546
-     */
547
-    public static function check_for_abandoned_transactions(int $TXN_ID = 0): void
548
-    {
549
-        EE_Cron_Tasks::expired_transaction_check($TXN_ID);
550
-    }
551
-
552
-
553
-    /**
554
-     * @throws EE_Error
555
-     * @throws DomainException
556
-     * @throws InvalidDataTypeException
557
-     * @throws InvalidInterfaceException
558
-     * @throws InvalidArgumentException
559
-     * @throws ReflectionException
560
-     * @throws RuntimeException
561
-     * @deprecated
562
-     */
563
-    public static function finalize_abandoned_transactions(): void
564
-    {
565
-        if (
566
-            // are there any TXNs that need cleaning up ?
567
-            empty(self::$_abandoned_transactions)
568
-            // reschedule the cron if we can't hit the db right now
569
-            || EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
570
-                'schedule_expired_transaction_check',
571
-                self::$_abandoned_transactions
572
-            )
573
-        ) {
574
-            return;
575
-        }
576
-        // combine our arrays of transaction IDs
577
-        self::$_expired_transactions = self::$_abandoned_transactions + self::$_expired_transactions;
578
-        // and deal with abandoned transactions here now...
579
-        EE_Cron_Tasks::process_expired_transactions();
580
-    }
581
-
582
-
583
-    /*************  END OF FINALIZE ABANDONED TRANSACTIONS  *************/
364
+			empty(self::$_expired_transactions)
365
+			// reschedule the cron if we can't hit the db right now
366
+			|| EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
367
+				'schedule_expired_transaction_check',
368
+				self::$_expired_transactions
369
+			)
370
+		) {
371
+			return;
372
+		}
373
+		/** @type EE_Transaction_Processor $transaction_processor */
374
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
375
+		// set revisit flag for txn processor
376
+		$transaction_processor->set_revisit();
377
+		// load EEM_Transaction
378
+		EE_Registry::instance()->load_model('Transaction');
379
+		foreach (self::$_expired_transactions as $TXN_ID) {
380
+			$transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
381
+			// verify transaction and whether it is failed or not
382
+			if ($transaction instanceof EE_Transaction) {
383
+				switch ($transaction->status_ID()) {
384
+					// Completed TXNs
385
+					case EEM_Transaction::complete_status_code:
386
+						// Don't update the transaction/registrations if the Primary Registration is Not Approved.
387
+						$primary_registration = $transaction->primary_registration();
388
+						if (
389
+							$primary_registration instanceof EE_Registration
390
+							&& $primary_registration->status_ID() !== RegStatus::AWAITING_REVIEW
391
+						) {
392
+							/** @type EE_Transaction_Processor $transaction_processor */
393
+							$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
394
+							$transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
395
+								$transaction,
396
+								$transaction->last_payment()
397
+							);
398
+							do_action(
399
+								'AHEE__EE_Cron_Tasks__process_expired_transactions__completed_transaction',
400
+								$transaction
401
+							);
402
+						}
403
+						break;
404
+					// Overpaid TXNs
405
+					case EEM_Transaction::overpaid_status_code:
406
+						do_action(
407
+							'AHEE__EE_Cron_Tasks__process_expired_transactions__overpaid_transaction',
408
+							$transaction
409
+						);
410
+						break;
411
+					// Incomplete TXNs
412
+					case EEM_Transaction::incomplete_status_code:
413
+						do_action(
414
+							'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction',
415
+							$transaction
416
+						);
417
+						// todo : move business logic into EE_Transaction_Processor for finalizing abandoned transactions
418
+						break;
419
+					// Abandoned TXNs
420
+					case EEM_Transaction::abandoned_status_code:
421
+						// run hook before updating transaction, primarily so
422
+						// EED_Ticket_Sales_Monitor::process_abandoned_transactions() can release reserved tickets
423
+						do_action(
424
+							'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction',
425
+							$transaction
426
+						);
427
+						// don't finalize the TXN if it has already been completed
428
+						if ($transaction->all_reg_steps_completed() !== true) {
429
+							/** @var PaymentProcessor $payment_processor */
430
+							$payment_processor = LoaderFactory::getShared(PaymentProcessor::class);
431
+							// let's simulate an IPN here which will trigger any notifications that need to go out
432
+							$payment_processor->updateTransactionBasedOnPayment(
433
+								$transaction,
434
+								$transaction->last_payment(),
435
+								true,
436
+								true
437
+							);
438
+						}
439
+						break;
440
+					// Failed TXNs
441
+					case EEM_Transaction::failed_status_code:
442
+						do_action(
443
+							'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction',
444
+							$transaction
445
+						);
446
+						// todo :
447
+						// perform garbage collection here and remove clean_out_junk_transactions()
448
+						// $registrations = $transaction->registrations();
449
+						// if (! empty($registrations)) {
450
+						//     foreach ($registrations as $registration) {
451
+						//         if ($registration instanceof EE_Registration) {
452
+						//             $delete_registration = true;
453
+						//             if ($registration->attendee() instanceof EE_Attendee) {
454
+						//                 $delete_registration = false;
455
+						//             }
456
+						//             if ($delete_registration) {
457
+						//                 $registration->delete_permanently();
458
+						//                 $registration->delete_related_permanently();
459
+						//             }
460
+						//         }
461
+						//     }
462
+						// }
463
+						break;
464
+				}
465
+			}
466
+			unset(self::$_expired_transactions[ $TXN_ID ]);
467
+		}
468
+	}
469
+
470
+
471
+
472
+	/*************  END OF EXPIRED TRANSACTION CHECK  *************/
473
+
474
+
475
+	/************* START CLEAN UP BOT TRANSACTIONS **********************/
476
+
477
+
478
+	/**
479
+	 * callback for 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'
480
+	 * which is setup during activation to run on an hourly cron
481
+	 *
482
+	 * @throws EE_Error
483
+	 * @throws InvalidArgumentException
484
+	 * @throws InvalidDataTypeException
485
+	 * @throws InvalidInterfaceException
486
+	 * @throws DomainException
487
+	 * @throws ReflectionException
488
+	 */
489
+	public static function clean_out_junk_transactions(): void
490
+	{
491
+		if (DbStatus::isOnline()) {
492
+			EED_Ticket_Sales_Monitor::reset_reservation_counts();
493
+			EEM_Transaction::instance()->delete_junk_transactions();
494
+			EEM_Registration::instance()->delete_registrations_with_no_transaction();
495
+			EEM_Line_Item::instance()->delete_line_items_with_no_transaction();
496
+		}
497
+	}
498
+
499
+
500
+	/**
501
+	 * Deletes old gateway logs. After about a week we usually don't need them for debugging. But folks can filter that.
502
+	 *
503
+	 * @throws EE_Error
504
+	 * @throws InvalidDataTypeException
505
+	 * @throws InvalidInterfaceException
506
+	 * @throws InvalidArgumentException
507
+	 * @throws ReflectionException
508
+	 * @throws Exception
509
+	 */
510
+	public static function clean_out_old_gateway_logs(): void
511
+	{
512
+		if (DbStatus::isOnline()) {
513
+			$reg_config               = LoaderFactory::getLoader()->load('EE_Registration_Config');
514
+			$time_diff_for_comparison = apply_filters(
515
+				'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison',
516
+				'-' . $reg_config->gateway_log_lifespan
517
+			);
518
+			EEM_Change_Log::instance()->delete_gateway_logs_older_than(new DateTime($time_diff_for_comparison));
519
+		}
520
+	}
521
+
522
+
523
+	/*****************  FINALIZE ABANDONED TRANSACTIONS *****************/
524
+
525
+
526
+	/**
527
+	 * @var array
528
+	 */
529
+	protected static array $_abandoned_transactions = [];
530
+
531
+
532
+	/**
533
+	 * @param int $timestamp
534
+	 * @param int $TXN_ID
535
+	 * @deprecated
536
+	 */
537
+	public static function schedule_finalize_abandoned_transactions_check(int $timestamp, int $TXN_ID): void
538
+	{
539
+		EE_Cron_Tasks::schedule_expired_transaction_check($timestamp, $TXN_ID);
540
+	}
541
+
542
+
543
+	/**
544
+	 * @param int $TXN_ID
545
+	 * @deprecated
546
+	 */
547
+	public static function check_for_abandoned_transactions(int $TXN_ID = 0): void
548
+	{
549
+		EE_Cron_Tasks::expired_transaction_check($TXN_ID);
550
+	}
551
+
552
+
553
+	/**
554
+	 * @throws EE_Error
555
+	 * @throws DomainException
556
+	 * @throws InvalidDataTypeException
557
+	 * @throws InvalidInterfaceException
558
+	 * @throws InvalidArgumentException
559
+	 * @throws ReflectionException
560
+	 * @throws RuntimeException
561
+	 * @deprecated
562
+	 */
563
+	public static function finalize_abandoned_transactions(): void
564
+	{
565
+		if (
566
+			// are there any TXNs that need cleaning up ?
567
+			empty(self::$_abandoned_transactions)
568
+			// reschedule the cron if we can't hit the db right now
569
+			|| EE_Cron_Tasks::reschedule_cron_for_transactions_if_maintenance_mode(
570
+				'schedule_expired_transaction_check',
571
+				self::$_abandoned_transactions
572
+			)
573
+		) {
574
+			return;
575
+		}
576
+		// combine our arrays of transaction IDs
577
+		self::$_expired_transactions = self::$_abandoned_transactions + self::$_expired_transactions;
578
+		// and deal with abandoned transactions here now...
579
+		EE_Cron_Tasks::process_expired_transactions();
580
+	}
581
+
582
+
583
+	/*************  END OF FINALIZE ABANDONED TRANSACTIONS  *************/
584 584
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 
30 30
     public static function instance(): ?EE_Cron_Tasks
31 31
     {
32
-        if (! self::$_instance instanceof EE_Cron_Tasks) {
32
+        if ( ! self::$_instance instanceof EE_Cron_Tasks) {
33 33
             self::$_instance = new self();
34 34
         }
35 35
         return self::$_instance;
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
              */
62 62
             add_action(
63 63
                 'AHEE__EE_System__load_core_configuration__complete',
64
-                function () {
64
+                function() {
65 65
                     EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request = true;
66 66
                     EE_Registry::instance()->NET_CFG->update_config(true, false);
67 67
                     add_option('ee_disabled_wp_cron_check', 1, '', false);
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
      */
121 121
     public static function reschedule_cron_for_transactions_if_maintenance_mode(string $cron_task, array $TXN_IDs): bool
122 122
     {
123
-        if (! method_exists('EE_Cron_Tasks', $cron_task)) {
123
+        if ( ! method_exists('EE_Cron_Tasks', $cron_task)) {
124 124
             throw new DomainException(
125 125
                 sprintf(
126 126
                     esc_html__('"%1$s" is not valid method on EE_Cron_Tasks.', 'event_espresso'),
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
     {
210 210
         do_action('AHEE_log', __CLASS__, __FUNCTION__, $TXN_ID, '$TXN_ID');
211 211
         if (absint($TXN_ID)) {
212
-            self::$_update_transactions_with_payment[ $TXN_ID ] = $PAY_ID;
212
+            self::$_update_transactions_with_payment[$TXN_ID] = $PAY_ID;
213 213
             add_action(
214 214
                 'shutdown',
215 215
                 ['EE_Cron_Tasks', 'update_transaction_with_payment'],
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
                 $payment_processor = LoaderFactory::getShared(PaymentProcessor::class);
275 275
                 $payment_processor->updateTransactionBasedOnPayment($transaction, $payment, true, true);
276 276
             }
277
-            unset(self::$_update_transactions_with_payment[ $TXN_ID ]);
277
+            unset(self::$_update_transactions_with_payment[$TXN_ID]);
278 278
         }
279 279
     }
280 280
 
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
     public static function expired_transaction_check(int $TXN_ID = 0): void
336 336
     {
337 337
         if (absint($TXN_ID)) {
338
-            self::$_expired_transactions[ $TXN_ID ] = $TXN_ID;
338
+            self::$_expired_transactions[$TXN_ID] = $TXN_ID;
339 339
             add_action(
340 340
                 'shutdown',
341 341
                 ['EE_Cron_Tasks', 'process_expired_transactions'],
@@ -463,7 +463,7 @@  discard block
 block discarded – undo
463 463
                         break;
464 464
                 }
465 465
             }
466
-            unset(self::$_expired_transactions[ $TXN_ID ]);
466
+            unset(self::$_expired_transactions[$TXN_ID]);
467 467
         }
468 468
     }
469 469
 
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
             $reg_config               = LoaderFactory::getLoader()->load('EE_Registration_Config');
514 514
             $time_diff_for_comparison = apply_filters(
515 515
                 'FHEE__EE_Cron_Tasks__clean_out_old_gateway_logs__time_diff_for_comparison',
516
-                '-' . $reg_config->gateway_log_lifespan
516
+                '-'.$reg_config->gateway_log_lifespan
517 517
             );
518 518
             EEM_Change_Log::instance()->delete_gateway_logs_older_than(new DateTime($time_diff_for_comparison));
519 519
         }
Please login to merge, or discard this patch.