Completed
Branch FET/add-copy-attendee-at-admin (b30562)
by
unknown
36:10 queued 27:01
created
attendee_information/EE_SPCO_Reg_Step_Attendee_Information.class.php 1 patch
Indentation   +1418 added lines, -1418 removed lines patch added patch discarded remove patch
@@ -18,1426 +18,1426 @@
 block discarded – undo
18 18
 class EE_SPCO_Reg_Step_Attendee_Information extends EE_SPCO_Reg_Step
19 19
 {
20 20
 
21
-    /**
22
-     * @type bool $_print_copy_info
23
-     */
24
-    private $_print_copy_info = false;
25
-
26
-    /**
27
-     * @type array $_attendee_data
28
-     */
29
-    private $_attendee_data = array();
30
-
31
-    /**
32
-     * @type array $_required_questions
33
-     */
34
-    private $_required_questions = array();
35
-
36
-    /**
37
-     * @type array $_registration_answers
38
-     */
39
-    private $_registration_answers = array();
40
-
41
-
42
-    /**
43
-     *    class constructor
44
-     *
45
-     * @access    public
46
-     * @param    EE_Checkout $checkout
47
-     */
48
-    public function __construct(EE_Checkout $checkout)
49
-    {
50
-        $this->_slug = 'attendee_information';
51
-        $this->_name = esc_html__('Attendee Information', 'event_espresso');
52
-        $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . '/attendee_info_main.template.php';
53
-        $this->checkout = $checkout;
54
-        $this->_reset_success_message();
55
-        $this->set_instructions(
56
-            esc_html__('Please answer the following registration questions before proceeding.', 'event_espresso')
57
-        );
58
-    }
59
-
60
-
61
-    public function translate_js_strings()
62
-    {
63
-        EE_Registry::$i18n_js_strings['required_field'] = esc_html__(
64
-            ' is a required question.',
65
-            'event_espresso'
66
-        );
67
-        EE_Registry::$i18n_js_strings['required_multi_field'] = esc_html__(
68
-            ' is a required question. Please enter a value for at least one of the options.',
69
-            'event_espresso'
70
-        );
71
-        EE_Registry::$i18n_js_strings['answer_required_questions'] = esc_html__(
72
-            'Please answer all required questions correctly before proceeding.',
73
-            'event_espresso'
74
-        );
75
-        EE_Registry::$i18n_js_strings['attendee_info_copied'] = sprintf(
76
-            esc_html_x(
77
-                'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.',
78
-                'The attendee information was successfully copied.(line break)Please ensure the rest of the registration form is completed before proceeding.',
79
-                'event_espresso'
80
-            ),
81
-            '<br/>'
82
-        );
83
-        EE_Registry::$i18n_js_strings['attendee_info_copy_error'] = esc_html__(
84
-            'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.',
85
-            'event_espresso'
86
-        );
87
-        EE_Registry::$i18n_js_strings['enter_valid_email'] = esc_html__(
88
-            'You must enter a valid email address.',
89
-            'event_espresso'
90
-        );
91
-        EE_Registry::$i18n_js_strings['valid_email_and_questions'] = esc_html__(
92
-            'You must enter a valid email address and answer all other required questions before you can proceed.',
93
-            'event_espresso'
94
-        );
95
-    }
96
-
97
-
98
-    public function enqueue_styles_and_scripts()
99
-    {
100
-    }
101
-
102
-
103
-    /**
104
-     * @return boolean
105
-     */
106
-    public function initialize_reg_step()
107
-    {
108
-        return true;
109
-    }
110
-
111
-
112
-    /**
113
-     * @return EE_Form_Section_Proper
114
-     * @throws DomainException
115
-     * @throws EE_Error
116
-     * @throws InvalidArgumentException
117
-     * @throws ReflectionException
118
-     * @throws EntityNotFoundException
119
-     * @throws InvalidDataTypeException
120
-     * @throws InvalidInterfaceException
121
-     */
122
-    public function generate_reg_form()
123
-    {
124
-        /**
125
-         * @var $reg_config EE_Registration_Config
126
-         */
127
-        $reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config');
21
+	/**
22
+	 * @type bool $_print_copy_info
23
+	 */
24
+	private $_print_copy_info = false;
25
+
26
+	/**
27
+	 * @type array $_attendee_data
28
+	 */
29
+	private $_attendee_data = array();
30
+
31
+	/**
32
+	 * @type array $_required_questions
33
+	 */
34
+	private $_required_questions = array();
35
+
36
+	/**
37
+	 * @type array $_registration_answers
38
+	 */
39
+	private $_registration_answers = array();
40
+
41
+
42
+	/**
43
+	 *    class constructor
44
+	 *
45
+	 * @access    public
46
+	 * @param    EE_Checkout $checkout
47
+	 */
48
+	public function __construct(EE_Checkout $checkout)
49
+	{
50
+		$this->_slug = 'attendee_information';
51
+		$this->_name = esc_html__('Attendee Information', 'event_espresso');
52
+		$this->_template = SPCO_REG_STEPS_PATH . $this->_slug . '/attendee_info_main.template.php';
53
+		$this->checkout = $checkout;
54
+		$this->_reset_success_message();
55
+		$this->set_instructions(
56
+			esc_html__('Please answer the following registration questions before proceeding.', 'event_espresso')
57
+		);
58
+	}
59
+
60
+
61
+	public function translate_js_strings()
62
+	{
63
+		EE_Registry::$i18n_js_strings['required_field'] = esc_html__(
64
+			' is a required question.',
65
+			'event_espresso'
66
+		);
67
+		EE_Registry::$i18n_js_strings['required_multi_field'] = esc_html__(
68
+			' is a required question. Please enter a value for at least one of the options.',
69
+			'event_espresso'
70
+		);
71
+		EE_Registry::$i18n_js_strings['answer_required_questions'] = esc_html__(
72
+			'Please answer all required questions correctly before proceeding.',
73
+			'event_espresso'
74
+		);
75
+		EE_Registry::$i18n_js_strings['attendee_info_copied'] = sprintf(
76
+			esc_html_x(
77
+				'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.',
78
+				'The attendee information was successfully copied.(line break)Please ensure the rest of the registration form is completed before proceeding.',
79
+				'event_espresso'
80
+			),
81
+			'<br/>'
82
+		);
83
+		EE_Registry::$i18n_js_strings['attendee_info_copy_error'] = esc_html__(
84
+			'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.',
85
+			'event_espresso'
86
+		);
87
+		EE_Registry::$i18n_js_strings['enter_valid_email'] = esc_html__(
88
+			'You must enter a valid email address.',
89
+			'event_espresso'
90
+		);
91
+		EE_Registry::$i18n_js_strings['valid_email_and_questions'] = esc_html__(
92
+			'You must enter a valid email address and answer all other required questions before you can proceed.',
93
+			'event_espresso'
94
+		);
95
+	}
96
+
97
+
98
+	public function enqueue_styles_and_scripts()
99
+	{
100
+	}
101
+
102
+
103
+	/**
104
+	 * @return boolean
105
+	 */
106
+	public function initialize_reg_step()
107
+	{
108
+		return true;
109
+	}
110
+
111
+
112
+	/**
113
+	 * @return EE_Form_Section_Proper
114
+	 * @throws DomainException
115
+	 * @throws EE_Error
116
+	 * @throws InvalidArgumentException
117
+	 * @throws ReflectionException
118
+	 * @throws EntityNotFoundException
119
+	 * @throws InvalidDataTypeException
120
+	 * @throws InvalidInterfaceException
121
+	 */
122
+	public function generate_reg_form()
123
+	{
124
+		/**
125
+		 * @var $reg_config EE_Registration_Config
126
+		 */
127
+		$reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config');
128 128
     
129
-        $this->_print_copy_info = $reg_config->copyAttendeeInfo();
130
-        $primary_registrant = null;
131
-        // autoload Line_Item_Display classes
132
-        EEH_Autoloader::register_line_item_display_autoloaders();
133
-        $Line_Item_Display = new EE_Line_Item_Display();
134
-        // calculate taxes
135
-        $Line_Item_Display->display_line_item(
136
-            $this->checkout->cart->get_grand_total(),
137
-            array('set_tax_rate' => true)
138
-        );
139
-        /** @var $subsections EE_Form_Section_Proper[] */
140
-        $extra_inputs_section = $this->reg_step_hidden_inputs();
141
-        $subsections = array(
142
-            'default_hidden_inputs' => $extra_inputs_section,
143
-        );
144
-
145
-        // if this isn't a revisit, and they have the privacy consent box enalbed, add it
146
-        if (! $this->checkout->revisit && $reg_config->isConsentCheckboxEnabled()) {
147
-            $extra_inputs_section->add_subsections(
148
-                array(
149
-                    'consent_box' => new EE_Form_Section_Proper(
150
-                        array(
151
-                            'layout_strategy' =>
152
-                                new EE_Template_Layout(
153
-                                    array(
154
-                                        'input_template_file' => SPCO_REG_STEPS_PATH . $this->_slug . '/privacy_consent.template.php',
155
-                                    )
156
-                                ),
157
-                            'subsections'     => array(
158
-                                'consent' => new EE_Checkbox_Multi_Input(
159
-                                    array(
160
-                                        'consent' => $reg_config->getConsentCheckboxLabelText(),
161
-                                    ),
162
-                                    array(
163
-                                        'required'                          => true,
164
-                                        'required_validation_error_message' => esc_html__(
165
-                                            'You must consent to these terms in order to register.',
166
-                                            'event_espresso'
167
-                                        ),
168
-                                        'html_label_text'                   => '',
169
-                                    )
170
-                                ),
171
-                            ),
172
-                        )
173
-                    ),
174
-                ),
175
-                null,
176
-                false
177
-            );
178
-        }
179
-        $template_args = array(
180
-            'revisit'       => $this->checkout->revisit,
181
-            'registrations' => array(),
182
-            'ticket_count'  => array(),
183
-        );
184
-        // grab the saved registrations from the transaction
185
-        $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
186
-        if ($registrations) {
187
-            foreach ($registrations as $registration) {
188
-                // can this registration be processed during this visit ?
189
-                if ($registration instanceof EE_Registration
190
-                    && $this->checkout->visit_allows_processing_of_this_registration($registration)
191
-                ) {
192
-                    $subsections[ $registration->reg_url_link() ] = $this->_registrations_reg_form($registration);
193
-                    $template_args['registrations'][ $registration->reg_url_link() ] = $registration;
194
-                    $template_args['ticket_count'][ $registration->ticket()->ID() ] = isset(
195
-                        $template_args['ticket_count'][ $registration->ticket()->ID() ]
196
-                    )
197
-                        ? $template_args['ticket_count'][ $registration->ticket()->ID() ] + 1
198
-                        : 1;
199
-                    $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs(
200
-                        $this->checkout->cart->get_grand_total(),
201
-                        'Ticket',
202
-                        array($registration->ticket()->ID())
203
-                    );
204
-                    $ticket_line_item = is_array($ticket_line_item)
205
-                        ? reset($ticket_line_item)
206
-                        : $ticket_line_item;
207
-                    $template_args['ticket_line_item'][ $registration->ticket()->ID() ] =
208
-                        $Line_Item_Display->display_line_item($ticket_line_item);
209
-                    if ($registration->is_primary_registrant()) {
210
-                        $primary_registrant = $registration->reg_url_link();
211
-                    }
212
-                }
213
-            }
214
-            if ($primary_registrant && count($registrations) > 1) {
215
-                $copy_options['spco_copy_attendee_chk'] = $this->_print_copy_info
216
-                    ? $this->_copy_attendee_info_form()
217
-                    : $this->_auto_copy_attendee_info();
218
-                // generate hidden input
219
-                if (isset($subsections[ $primary_registrant ])
220
-                    && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper
221
-                ) {
222
-                    $subsections[ $primary_registrant ]->add_subsections(
223
-                        $copy_options,
224
-                        'primary_registrant',
225
-                        false
226
-                    );
227
-                }
228
-            }
229
-        }
230
-        return new EE_Form_Section_Proper(
231
-            array(
232
-                'name'            => $this->reg_form_name(),
233
-                'html_id'         => $this->reg_form_name(),
234
-                'subsections'     => $subsections,
235
-                'layout_strategy' => new EE_Template_Layout(
236
-                    array(
237
-                        'layout_template_file' => $this->_template, // layout_template
238
-                        'template_args'        => $template_args,
239
-                    )
240
-                ),
241
-            )
242
-        );
243
-    }
244
-
245
-
246
-    /**
247
-     * @param EE_Registration $registration
248
-     * @return EE_Form_Section_Base
249
-     * @throws EE_Error
250
-     * @throws InvalidArgumentException
251
-     * @throws EntityNotFoundException
252
-     * @throws InvalidDataTypeException
253
-     * @throws InvalidInterfaceException
254
-     * @throws ReflectionException
255
-     */
256
-    private function _registrations_reg_form(EE_Registration $registration)
257
-    {
258
-        static $attendee_nmbr = 1;
259
-        $form_args = array();
260
-        // verify that registration has valid event
261
-        if ($registration->event() instanceof EE_Event) {
262
-            $field_name = 'Event_Question_Group.'
263
-                . EEM_Event_Question_Group::instance()->fieldNameForContext(
264
-                    $registration->is_primary_registrant()
265
-                );
266
-            $question_groups = $registration->event()->question_groups(
267
-                apply_filters(
268
-                    // @codingStandardsIgnoreStart
269
-                    'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters',
270
-                    // @codingStandardsIgnoreEnd
271
-                    [
272
-                        [
273
-                            'Event.EVT_ID'                     => $registration->event()->ID(),
274
-                            $field_name => true,
275
-                        ],
276
-                        'order_by' => ['QSG_order' => 'ASC'],
277
-                    ],
278
-                    $registration,
279
-                    $this
280
-                )
281
-            );
282
-            if ($question_groups) {
283
-                // array of params to pass to parent constructor
284
-                $form_args = array(
285
-                    'html_id'         => 'ee-registration-' . $registration->reg_url_link(),
286
-                    'html_class'      => 'ee-reg-form-attendee-dv',
287
-                    'html_style'      => $this->checkout->admin_request
288
-                        ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;'
289
-                        : '',
290
-                    'subsections'     => array(),
291
-                    'layout_strategy' => new EE_Fieldset_Section_Layout(
292
-                        array(
293
-                            'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text',
294
-                            'legend_text'  => sprintf(
295
-                                esc_html_x(
296
-                                    'Attendee %d',
297
-                                    'Attendee 123',
298
-                                    'event_espresso'
299
-                                ),
300
-                                $attendee_nmbr
301
-                            ),
302
-                        )
303
-                    ),
304
-                );
305
-                foreach ($question_groups as $question_group) {
306
-                    if ($question_group instanceof EE_Question_Group) {
307
-                        $form_args['subsections'][ $question_group->identifier() ] = $this->_question_group_reg_form(
308
-                            $registration,
309
-                            $question_group
310
-                        );
311
-                    }
312
-                }
313
-                // add hidden input
314
-                $form_args['subsections']['additional_attendee_reg_info'] = $this->_additional_attendee_reg_info_input(
315
-                    $registration
316
-                );
317
-
318
-                /**
319
-                 * @var $reg_config EE_Registration_Config
320
-                 */
321
-                $reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config');
322
-
323
-                // if we have question groups for additional attendees, then display the copy options
324
-                $this->_print_copy_info = $attendee_nmbr > 1 ? $reg_config->copyAttendeeInfo() : false;
325
-                if ($registration->is_primary_registrant()) {
326
-                    // generate hidden input
327
-                    $form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs(
328
-                        $registration
329
-                    );
330
-                }
331
-            }
332
-        }
333
-        $attendee_nmbr++;
334
-        return ! empty($form_args)
335
-            ? new EE_Form_Section_Proper($form_args)
336
-            : new EE_Form_Section_HTML();
337
-    }
338
-
339
-
340
-    /**
341
-     * @param EE_Registration $registration
342
-     * @param bool            $additional_attendee_reg_info
343
-     * @return EE_Form_Input_Base
344
-     * @throws EE_Error
345
-     */
346
-    private function _additional_attendee_reg_info_input(
347
-        EE_Registration $registration,
348
-        $additional_attendee_reg_info = true
349
-    ) {
350
-        // generate hidden input
351
-        return new EE_Hidden_Input(
352
-            array(
353
-                'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(),
354
-                'default' => $additional_attendee_reg_info,
355
-            )
356
-        );
357
-    }
358
-
359
-
360
-    /**
361
-     * @param EE_Registration   $registration
362
-     * @param EE_Question_Group $question_group
363
-     * @return EE_Form_Section_Proper
364
-     * @throws EE_Error
365
-     * @throws InvalidArgumentException
366
-     * @throws InvalidDataTypeException
367
-     * @throws InvalidInterfaceException
368
-     * @throws ReflectionException
369
-     */
370
-    private function _question_group_reg_form(EE_Registration $registration, EE_Question_Group $question_group)
371
-    {
372
-        // array of params to pass to parent constructor
373
-        $form_args = array(
374
-            'html_id'         => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID(),
375
-            'html_class'      => $this->checkout->admin_request
376
-                ? 'form-table ee-reg-form-qstn-grp-dv'
377
-                : 'ee-reg-form-qstn-grp-dv',
378
-            'html_label_id'   => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-'
379
-                                 . $registration->ID() . '-lbl',
380
-            'subsections'     => array(
381
-                'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group),
382
-            ),
383
-            'layout_strategy' => $this->checkout->admin_request
384
-                ? new EE_Admin_Two_Column_Layout()
385
-                : new EE_Div_Per_Section_Layout(),
386
-        );
387
-        // where params
388
-        $query_params = array('QST_deleted' => 0);
389
-        // don't load admin only questions on the frontend
390
-        if (! $this->checkout->admin_request) {
391
-            $query_params['QST_admin_only'] = array('!=', true);
392
-        }
393
-        $questions = $question_group->get_many_related(
394
-            'Question',
395
-            apply_filters(
396
-                'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__related_questions_query_params',
397
-                array(
398
-                    $query_params,
399
-                    'order_by' => array(
400
-                        'Question_Group_Question.QGQ_order' => 'ASC',
401
-                    ),
402
-                ),
403
-                $question_group,
404
-                $registration,
405
-                $this
406
-            )
407
-        );
408
-        // filter for additional content before questions
409
-        $form_args['subsections']['reg_form_questions_before'] = new EE_Form_Section_HTML(
410
-            apply_filters(
411
-                'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions',
412
-                '',
413
-                $registration,
414
-                $question_group,
415
-                $this
416
-            )
417
-        );
418
-        // loop thru questions
419
-        foreach ($questions as $question) {
420
-            if ($question instanceof EE_Question) {
421
-                $identifier = $question->is_system_question()
422
-                    ? $question->system_ID()
423
-                    : $question->ID();
424
-                $form_args['subsections'][ $identifier ] = $this->reg_form_question($registration, $question);
425
-            }
426
-        }
427
-        $form_args['subsections'] = apply_filters(
428
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information__question_group_reg_form__subsections_array',
429
-            $form_args['subsections'],
430
-            $registration,
431
-            $question_group,
432
-            $this
433
-        );
434
-        // filter for additional content after questions
435
-        $form_args['subsections']['reg_form_questions_after'] = new EE_Form_Section_HTML(
436
-            apply_filters(
437
-                'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions',
438
-                '',
439
-                $registration,
440
-                $question_group,
441
-                $this
442
-            )
443
-        );
444
-        // d($form_args);
445
-        $question_group_reg_form = new EE_Form_Section_Proper($form_args);
446
-        return apply_filters(
447
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
448
-            $question_group_reg_form,
449
-            $registration,
450
-            $question_group,
451
-            $this
452
-        );
453
-    }
454
-
455
-
456
-    /**
457
-     * @param EE_Question_Group $question_group
458
-     * @return    EE_Form_Section_HTML
459
-     */
460
-    private function _question_group_header(EE_Question_Group $question_group)
461
-    {
462
-        $html = '';
463
-        // group_name
464
-        if ($question_group->show_group_name() && $question_group->name() !== '') {
465
-            if ($this->checkout->admin_request) {
466
-                $html .= EEH_HTML::br();
467
-                $html .= EEH_HTML::h3(
468
-                    $question_group->name(),
469
-                    '',
470
-                    'ee-reg-form-qstn-grp-title title',
471
-                    'font-size: 1.3em; padding-left:0;'
472
-                );
473
-            } else {
474
-                $html .= EEH_HTML::h4(
475
-                    $question_group->name(),
476
-                    '',
477
-                    'ee-reg-form-qstn-grp-title section-title'
478
-                );
479
-            }
480
-        }
481
-        // group_desc
482
-        if ($question_group->show_group_desc() && $question_group->desc() !== '') {
483
-            $html .= EEH_HTML::p(
484
-                $question_group->desc(),
485
-                '',
486
-                $this->checkout->admin_request
487
-                    ? 'ee-reg-form-qstn-grp-desc-pg'
488
-                    : 'ee-reg-form-qstn-grp-desc-pg small-text lt-grey-text'
489
-            );
490
-        }
491
-        return new EE_Form_Section_HTML($html);
492
-    }
493
-
494
-
495
-    /**
496
-     * @return    EE_Form_Section_Proper
497
-     * @throws EE_Error
498
-     * @throws InvalidArgumentException
499
-     * @throws ReflectionException
500
-     * @throws InvalidDataTypeException
501
-     * @throws InvalidInterfaceException
502
-     */
503
-    private function _copy_attendee_info_form()
504
-    {
505
-        // array of params to pass to parent constructor
506
-        return new EE_Form_Section_Proper(
507
-            array(
508
-                'subsections'     => $this->_copy_attendee_info_inputs(),
509
-                'layout_strategy' => new EE_Template_Layout(
510
-                    array(
511
-                        'layout_template_file'     => SPCO_REG_STEPS_PATH
512
-                                                      . $this->_slug
513
-                                                      . '/copy_attendee_info.template.php',
514
-                        'begin_template_file'      => null,
515
-                        'input_template_file'      => null,
516
-                        'subsection_template_file' => null,
517
-                        'end_template_file'        => null,
518
-                    )
519
-                ),
520
-            )
521
-        );
522
-    }
523
-
524
-
525
-    /**
526
-     * @return EE_Form_Section_HTML
527
-     * @throws DomainException
528
-     * @throws InvalidArgumentException
529
-     * @throws InvalidDataTypeException
530
-     * @throws InvalidInterfaceException
531
-     */
532
-    private function _auto_copy_attendee_info()
533
-    {
534
-        return new EE_Form_Section_HTML(
535
-            EEH_Template::locate_template(
536
-                SPCO_REG_STEPS_PATH . $this->_slug . '/_auto_copy_attendee_info.template.php',
537
-                apply_filters(
538
-                    'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args',
539
-                    array()
540
-                ),
541
-                true,
542
-                true
543
-            )
544
-        );
545
-    }
546
-
547
-
548
-    /**
549
-     * @return array
550
-     * @throws EE_Error
551
-     * @throws InvalidArgumentException
552
-     * @throws ReflectionException
553
-     * @throws InvalidDataTypeException
554
-     * @throws InvalidInterfaceException
555
-     */
556
-    private function _copy_attendee_info_inputs()
557
-    {
558
-        $copy_attendee_info_inputs = array();
559
-        $prev_ticket = null;
560
-        // grab the saved registrations from the transaction
561
-        $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
562
-        foreach ($registrations as $registration) {
563
-            // for all  attendees other than the primary attendee
564
-            if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) {
565
-                // if this is a new ticket OR if this is the very first additional attendee after the primary attendee
566
-                if ($registration->ticket()->ID() !== $prev_ticket) {
567
-                    $item_name = $registration->ticket()->name();
568
-                    $item_name .= $registration->ticket()->description() !== ''
569
-                        ? ' - ' . $registration->ticket()->description()
570
-                        : '';
571
-                    $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID(
572
-                    ) . ']' ] =
573
-                        new EE_Form_Section_HTML(
574
-                            '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>'
575
-                        );
576
-                    $prev_ticket = $registration->ticket()->ID();
577
-                }
578
-
579
-                $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[' . $registration->ID() . ']' ] =
580
-                    new EE_Checkbox_Multi_Input(
581
-                        array(
582
-                            $registration->ID() => sprintf(
583
-                                esc_html_x('Attendee #%s', 'Attendee #123', 'event_espresso'),
584
-                                $registration->count()
585
-                            ),
586
-                        ),
587
-                        array(
588
-                            'html_id'                 => 'spco-copy-attendee-chk-' . $registration->reg_url_link(),
589
-                            'html_class'              => 'spco-copy-attendee-chk ee-do-not-validate',
590
-                            'display_html_label_text' => false,
591
-                        )
592
-                    );
593
-            }
594
-        }
595
-        return $copy_attendee_info_inputs;
596
-    }
597
-
598
-
599
-    /**
600
-     * @param EE_Registration $registration
601
-     * @return    EE_Form_Input_Base
602
-     * @throws EE_Error
603
-     */
604
-    private function _additional_primary_registrant_inputs(EE_Registration $registration)
605
-    {
606
-        // generate hidden input
607
-        return new EE_Hidden_Input(
608
-            array(
609
-                'html_id' => 'primary_registrant',
610
-                'default' => $registration->reg_url_link(),
611
-            )
612
-        );
613
-    }
614
-
615
-
616
-    /**
617
-     * @param EE_Registration $registration
618
-     * @param EE_Question     $question
619
-     * @return EE_Form_Input_Base
620
-     * @throws EE_Error
621
-     * @throws InvalidArgumentException
622
-     * @throws InvalidDataTypeException
623
-     * @throws InvalidInterfaceException
624
-     * @throws ReflectionException
625
-     */
626
-    public function reg_form_question(EE_Registration $registration, EE_Question $question)
627
-    {
628
-
629
-        // if this question was for an attendee detail, then check for that answer
630
-        $answer_value = EEM_Answer::instance()->get_attendee_property_answer_value(
631
-            $registration,
632
-            $question->system_ID()
633
-        );
634
-        $answer = $answer_value === null
635
-            ? EEM_Answer::instance()->get_one(
636
-                array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()))
637
-            )
638
-            : null;
639
-        // if NOT returning to edit an existing registration
640
-        // OR if this question is for an attendee property
641
-        // OR we still don't have an EE_Answer object
642
-        if ($answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link()) {
643
-            // create an EE_Answer object for storing everything in
644
-            $answer = EE_Answer::new_instance(
645
-                array(
646
-                    'QST_ID' => $question->ID(),
647
-                    'REG_ID' => $registration->ID(),
648
-                )
649
-            );
650
-        }
651
-        // verify instance
652
-        if ($answer instanceof EE_Answer) {
653
-            if (! empty($answer_value)) {
654
-                $answer->set('ANS_value', $answer_value);
655
-            }
656
-            $answer->cache('Question', $question);
657
-            // remember system ID had a bug where sometimes it could be null
658
-            $answer_cache_id = $question->is_system_question()
659
-                ? $question->system_ID() . '-' . $registration->reg_url_link()
660
-                : $question->ID() . '-' . $registration->reg_url_link();
661
-            $registration->cache('Answer', $answer, $answer_cache_id);
662
-        }
663
-        return $this->_generate_question_input($registration, $question, $answer);
664
-    }
665
-
666
-
667
-    /**
668
-     * @param EE_Registration $registration
669
-     * @param EE_Question     $question
670
-     * @param                 $answer
671
-     * @return EE_Form_Input_Base
672
-     * @throws EE_Error
673
-     * @throws InvalidArgumentException
674
-     * @throws ReflectionException
675
-     * @throws InvalidDataTypeException
676
-     * @throws InvalidInterfaceException
677
-     */
678
-    private function _generate_question_input(EE_Registration $registration, EE_Question $question, $answer)
679
-    {
680
-        $identifier = $question->is_system_question()
681
-            ? $question->system_ID()
682
-            : $question->ID();
683
-        $this->_required_questions[ $identifier ] = $question->required() ? true : false;
684
-        add_filter(
685
-            'FHEE__EE_Question__generate_form_input__country_options',
686
-            array($this, 'use_cached_countries_for_form_input'),
687
-            10,
688
-            4
689
-        );
690
-        add_filter(
691
-            'FHEE__EE_Question__generate_form_input__state_options',
692
-            array($this, 'use_cached_states_for_form_input'),
693
-            10,
694
-            4
695
-        );
696
-        $input_constructor_args = array(
697
-            'html_name'        => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']',
698
-            'html_id'          => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
699
-            'html_class'       => 'ee-reg-qstn ee-reg-qstn-' . $identifier,
700
-            'html_label_id'    => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
701
-            'html_label_class' => 'ee-reg-qstn',
702
-        );
703
-        $input_constructor_args['html_label_id'] .= '-lbl';
704
-        if ($answer instanceof EE_Answer && $answer->ID()) {
705
-            $input_constructor_args['html_name'] .= '[' . $answer->ID() . ']';
706
-            $input_constructor_args['html_id'] .= '-' . $answer->ID();
707
-            $input_constructor_args['html_label_id'] .= '-' . $answer->ID();
708
-        }
709
-        $form_input = $question->generate_form_input(
710
-            $registration,
711
-            $answer,
712
-            $input_constructor_args
713
-        );
714
-        remove_filter(
715
-            'FHEE__EE_Question__generate_form_input__country_options',
716
-            array($this, 'use_cached_countries_for_form_input')
717
-        );
718
-        remove_filter(
719
-            'FHEE__EE_Question__generate_form_input__state_options',
720
-            array($this, 'use_cached_states_for_form_input')
721
-        );
722
-        return $form_input;
723
-    }
724
-
725
-
726
-    /**
727
-     * Gets the list of countries for the form input
728
-     *
729
-     * @param array|null      $countries_list
730
-     * @param EE_Question     $question
731
-     * @param EE_Registration $registration
732
-     * @param EE_Answer       $answer
733
-     * @return array 2d keys are country IDs, values are their names
734
-     * @throws EE_Error
735
-     * @throws InvalidArgumentException
736
-     * @throws InvalidDataTypeException
737
-     * @throws InvalidInterfaceException
738
-     * @throws ReflectionException
739
-     */
740
-    public function use_cached_countries_for_form_input(
741
-        $countries_list,
742
-        EE_Question $question = null,
743
-        EE_Registration $registration = null,
744
-        EE_Answer $answer = null
745
-    ) {
746
-        $country_options = array('' => '');
747
-        // get possibly cached list of countries
748
-        $countries = $this->checkout->action === 'process_reg_step'
749
-            ? EEM_Country::instance()->get_all_countries()
750
-            : EEM_Country::instance()->get_all_active_countries();
751
-        if (! empty($countries)) {
752
-            foreach ($countries as $country) {
753
-                if ($country instanceof EE_Country) {
754
-                    $country_options[ $country->ID() ] = $country->name();
755
-                }
756
-            }
757
-        }
758
-        if ($question instanceof EE_Question && $registration instanceof EE_Registration) {
759
-            $answer = EEM_Answer::instance()->get_one(
760
-                array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()))
761
-            );
762
-        } else {
763
-            $answer = EE_Answer::new_instance();
764
-        }
765
-        $country_options = apply_filters(
766
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
767
-            $country_options,
768
-            $this,
769
-            $registration,
770
-            $question,
771
-            $answer
772
-        );
773
-        return $country_options;
774
-    }
775
-
776
-
777
-    /**
778
-     * Gets the list of states for the form input
779
-     *
780
-     * @param array|null      $states_list
781
-     * @param EE_Question     $question
782
-     * @param EE_Registration $registration
783
-     * @param EE_Answer       $answer
784
-     * @return array 2d keys are state IDs, values are their names
785
-     * @throws EE_Error
786
-     * @throws InvalidArgumentException
787
-     * @throws InvalidDataTypeException
788
-     * @throws InvalidInterfaceException
789
-     * @throws ReflectionException
790
-     */
791
-    public function use_cached_states_for_form_input(
792
-        $states_list,
793
-        EE_Question $question = null,
794
-        EE_Registration $registration = null,
795
-        EE_Answer $answer = null
796
-    ) {
797
-        $state_options = array('' => array('' => ''));
798
-        $states = $this->checkout->action === 'process_reg_step'
799
-            ? EEM_State::instance()->get_all_states()
800
-            : EEM_State::instance()->get_all_active_states();
801
-        if (! empty($states)) {
802
-            foreach ($states as $state) {
803
-                if ($state instanceof EE_State) {
804
-                    $state_options[ $state->country()->name() ][ $state->ID() ] = $state->name();
805
-                }
806
-            }
807
-        }
808
-        $state_options = apply_filters(
809
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
810
-            $state_options,
811
-            $this,
812
-            $registration,
813
-            $question,
814
-            $answer
815
-        );
816
-        return $state_options;
817
-    }
818
-
819
-
820
-    /********************************************************************************************************/
821
-    /****************************************  PROCESS REG STEP  ****************************************/
822
-    /********************************************************************************************************/
823
-
824
-
825
-    /**
826
-     * @return bool
827
-     * @throws EE_Error
828
-     * @throws InvalidArgumentException
829
-     * @throws ReflectionException
830
-     * @throws RuntimeException
831
-     * @throws InvalidDataTypeException
832
-     * @throws InvalidInterfaceException
833
-     */
834
-    public function process_reg_step()
835
-    {
836
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
837
-        // grab validated data from form
838
-        $valid_data = $this->checkout->current_step->valid_data();
839
-        // EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ );
840
-        // EEH_Debug_Tools::printr( $valid_data, '$valid_data', __FILE__, __LINE__ );
841
-        // if we don't have any $valid_data then something went TERRIBLY WRONG !!!
842
-        if (empty($valid_data)) {
843
-            EE_Error::add_error(
844
-                esc_html__('No valid question responses were received.', 'event_espresso'),
845
-                __FILE__,
846
-                __FUNCTION__,
847
-                __LINE__
848
-            );
849
-            return false;
850
-        }
851
-        if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) {
852
-            EE_Error::add_error(
853
-                esc_html__(
854
-                    'A valid transaction could not be initiated for processing your registrations.',
855
-                    'event_espresso'
856
-                ),
857
-                __FILE__,
858
-                __FUNCTION__,
859
-                __LINE__
860
-            );
861
-            return false;
862
-        }
863
-        // get cached registrations
864
-        $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
865
-        // verify we got the goods
866
-        if (empty($registrations)) {
867
-            // combine the old translated string with a new one, in order to not break translations
868
-            $error_message = esc_html__(
869
-                'Your form data could not be applied to any valid registrations.',
870
-                'event_espresso'
871
-            )
872
-            . sprintf(
873
-                esc_html_x(
874
-                    '%3$sThis can sometimes happen if too much time has been taken to complete the registration process.%3$sPlease return to the %1$sEvent List%2$s and reselect your tickets. If the problem continues, please contact the site administrator.',
875
-                    '(line break)This can sometimes happen if too much time has been taken to complete the registration process.(line break)Please return to the (link)Event List(end link) and reselect your tickets. If the problem continues, please contact the site administrator.',
876
-                    'event_espresso'
877
-                ),
878
-                '<a href="' . get_post_type_archive_link('espresso_events') . '" >',
879
-                '</a>',
880
-                '<br />'
881
-            );
882
-            EE_Error::add_error(
883
-                $error_message,
884
-                __FILE__,
885
-                __FUNCTION__,
886
-                __LINE__
887
-            );
888
-            return false;
889
-        }
890
-        // extract attendee info from form data and save to model objects
891
-        $registrations_processed = $this->_process_registrations($registrations, $valid_data);
892
-        // if first pass thru SPCO,
893
-        // then let's check processed registrations against the total number of tickets in the cart
894
-        if ($registrations_processed === false) {
895
-            // but return immediately if the previous step exited early due to errors
896
-            return false;
897
-        }
898
-        if (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) {
899
-            // generate a correctly translated string for all possible singular/plural combinations
900
-            if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) {
901
-                $error_msg = sprintf(
902
-                    esc_html_x(
903
-                        'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed',
904
-                        'There was 1 ticket in the Event Queue, but 2 registrations were processed',
905
-                        'event_espresso'
906
-                    ),
907
-                    $this->checkout->total_ticket_count,
908
-                    $registrations_processed
909
-                );
910
-            } elseif ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) {
911
-                $error_msg = sprintf(
912
-                    esc_html_x(
913
-                        'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed',
914
-                        'There was a total of 2 tickets in the Event Queue, but only 1 registration was processed',
915
-                        'event_espresso'
916
-                    ),
917
-                    $this->checkout->total_ticket_count,
918
-                    $registrations_processed
919
-                );
920
-            } else {
921
-                $error_msg = sprintf(
922
-                    esc_html__(
923
-                        'There was a total of 2 tickets in the Event Queue, but 2 registrations were processed',
924
-                        'event_espresso'
925
-                    ),
926
-                    $this->checkout->total_ticket_count,
927
-                    $registrations_processed
928
-                );
929
-            }
930
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
931
-            return false;
932
-        }
933
-        // mark this reg step as completed
934
-        $this->set_completed();
935
-        $this->_set_success_message(
936
-            esc_html__('The Attendee Information Step has been successfully completed.', 'event_espresso')
937
-        );
938
-        // do action in case a plugin wants to do something with the data submitted in step 1.
939
-        // passes EE_Single_Page_Checkout, and it's posted data
940
-        do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data);
941
-        return true;
942
-    }
943
-
944
-
945
-    /**
946
-     *    _process_registrations
947
-     *
948
-     * @param EE_Registration[] $registrations
949
-     * @param array[][]         $valid_data
950
-     * @return bool|int
951
-     * @throws EntityNotFoundException
952
-     * @throws EE_Error
953
-     * @throws InvalidArgumentException
954
-     * @throws ReflectionException
955
-     * @throws RuntimeException
956
-     * @throws InvalidDataTypeException
957
-     * @throws InvalidInterfaceException
958
-     */
959
-    private function _process_registrations($registrations = array(), $valid_data = array())
960
-    {
961
-        // load resources and set some defaults
962
-        EE_Registry::instance()->load_model('Attendee');
963
-        // holder for primary registrant attendee object
964
-        $this->checkout->primary_attendee_obj = null;
965
-        // array for tracking reg form data for the primary registrant
966
-        $primary_registrant = array(
967
-            'line_item_id' => null,
968
-        );
969
-        $copy_primary = false;
970
-        // reg form sections that do not contain inputs
971
-        $non_input_form_sections = array(
972
-            'primary_registrant',
973
-            'additional_attendee_reg_info',
974
-            'spco_copy_attendee_chk',
975
-        );
976
-        // attendee counter
977
-        $att_nmbr = 0;
978
-        // grab the saved registrations from the transaction
979
-        foreach ($registrations as $registration) {
980
-            // verify EE_Registration object
981
-            if (! $registration instanceof EE_Registration) {
982
-                EE_Error::add_error(
983
-                    esc_html__(
984
-                        'An invalid Registration object was discovered when attempting to process your registration information.',
985
-                        'event_espresso'
986
-                    ),
987
-                    __FILE__,
988
-                    __FUNCTION__,
989
-                    __LINE__
990
-                );
991
-                return false;
992
-            }
993
-            /** @var string $reg_url_link */
994
-            $reg_url_link = $registration->reg_url_link();
995
-            // reg_url_link exists ?
996
-            if (! empty($reg_url_link)) {
997
-                // should this registration be processed during this visit ?
998
-                if ($this->checkout->visit_allows_processing_of_this_registration($registration)) {
999
-                    // if NOT revisiting, then let's save the registration now,
1000
-                    // so that we have a REG_ID to use when generating other objects
1001
-                    if (! $this->checkout->revisit) {
1002
-                        $registration->save();
1003
-                    }
1004
-                    /**
1005
-                     * This allows plugins to trigger a fail on processing of a
1006
-                     * registration for any conditions they may have for it to pass.
1007
-                     *
1008
-                     * @var bool   if true is returned by the plugin then the
1009
-                     *            registration processing is halted.
1010
-                     */
1011
-                    if (apply_filters(
1012
-                        'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process',
1013
-                        false,
1014
-                        $att_nmbr,
1015
-                        $registration,
1016
-                        $registrations,
1017
-                        $valid_data,
1018
-                        $this
1019
-                    )) {
1020
-                        return false;
1021
-                    }
1022
-
1023
-                    // Houston, we have a registration!
1024
-                    $att_nmbr++;
1025
-                    $this->_attendee_data[ $reg_url_link ] = array();
1026
-                    // grab any existing related answer objects
1027
-                    $this->_registration_answers = $registration->answers();
1028
-                    // unset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] );
1029
-                    if (isset($valid_data[ $reg_url_link ])) {
1030
-                        // do we need to copy basic info from primary attendee ?
1031
-                        $copy_primary = isset($valid_data[ $reg_url_link ]['additional_attendee_reg_info'])
1032
-                                        && absint($valid_data[ $reg_url_link ]['additional_attendee_reg_info']) === 0;
1033
-                        // filter form input data for this registration
1034
-                        $valid_data[ $reg_url_link ] = (array) apply_filters(
1035
-                            'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
1036
-                            $valid_data[ $reg_url_link ]
1037
-                        );
1038
-                        if (isset($valid_data['primary_attendee'])) {
1039
-                            $primary_registrant['line_item_id'] = ! empty($valid_data['primary_attendee'])
1040
-                                ? $valid_data['primary_attendee']
1041
-                                : false;
1042
-                            unset($valid_data['primary_attendee']);
1043
-                        }
1044
-                        // now loop through our array of valid post data && process attendee reg forms
1045
-                        foreach ($valid_data[ $reg_url_link ] as $form_section => $form_inputs) {
1046
-                            if (! in_array($form_section, $non_input_form_sections, true)) {
1047
-                                foreach ($form_inputs as $form_input => $input_value) {
1048
-                                    // \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ );
1049
-                                    // check for critical inputs
1050
-                                    if (! $this->_verify_critical_attendee_details_are_set_and_validate_email(
1051
-                                        $form_input,
1052
-                                        $input_value
1053
-                                    )
1054
-                                    ) {
1055
-                                        return false;
1056
-                                    }
1057
-                                    // store a bit of data about the primary attendee
1058
-                                    if ($att_nmbr === 1
1059
-                                        && ! empty($input_value)
1060
-                                        && $reg_url_link === $primary_registrant['line_item_id']
1061
-                                    ) {
1062
-                                        $primary_registrant[ $form_input ] = $input_value;
1063
-                                    } elseif ($copy_primary
1064
-                                              && $input_value === null
1065
-                                              && isset($primary_registrant[ $form_input ])
1066
-                                    ) {
1067
-                                        $input_value = $primary_registrant[ $form_input ];
1068
-                                    }
1069
-                                    // now attempt to save the input data
1070
-                                    if (! $this->_save_registration_form_input(
1071
-                                        $registration,
1072
-                                        $form_input,
1073
-                                        $input_value
1074
-                                    )
1075
-                                    ) {
1076
-                                        EE_Error::add_error(
1077
-                                            sprintf(
1078
-                                                esc_html_x(
1079
-                                                    'Unable to save registration form data for the form input: "%1$s" with the submitted value: "%2$s"',
1080
-                                                    'Unable to save registration form data for the form input: "form input name" with the submitted value: "form input value"',
1081
-                                                    'event_espresso'
1082
-                                                ),
1083
-                                                $form_input,
1084
-                                                $input_value
1085
-                                            ),
1086
-                                            __FILE__,
1087
-                                            __FUNCTION__,
1088
-                                            __LINE__
1089
-                                        );
1090
-                                        return false;
1091
-                                    }
1092
-                                }
1093
-                            }
1094
-                        }  // end of foreach ( $valid_data[ $reg_url_link ] as $form_section => $form_inputs )
1095
-                    }
1096
-                    // EEH_Debug_Tools::printr( $this->_attendee_data, '$this->_attendee_data', __FILE__, __LINE__ );
1097
-                    // this registration does not require additional attendee information ?
1098
-                    if ($copy_primary
1099
-                        && $att_nmbr > 1
1100
-                        && $this->checkout->primary_attendee_obj instanceof EE_Attendee
1101
-                    ) {
1102
-                        // just copy the primary registrant
1103
-                        $attendee = $this->checkout->primary_attendee_obj;
1104
-                    } else {
1105
-                        // ensure critical details are set for additional attendees
1106
-                        $this->_attendee_data[ $reg_url_link ] = $att_nmbr > 1
1107
-                            ? $this->_copy_critical_attendee_details_from_primary_registrant(
1108
-                                $this->_attendee_data[ $reg_url_link ]
1109
-                            )
1110
-                            : $this->_attendee_data[ $reg_url_link ];
1111
-                        // execute create attendee command (which may return an existing attendee)
1112
-                        $attendee = EE_Registry::instance()->BUS->execute(
1113
-                            new CreateAttendeeCommand(
1114
-                                $this->_attendee_data[ $reg_url_link ],
1115
-                                $registration
1116
-                            )
1117
-                        );
1118
-                        // who's #1 ?
1119
-                        if ($att_nmbr === 1) {
1120
-                            $this->checkout->primary_attendee_obj = $attendee;
1121
-                        }
1122
-                    }
1123
-                    // EEH_Debug_Tools::printr( $attendee, '$attendee', __FILE__, __LINE__ );
1124
-                    // add relation to registration, set attendee ID, and cache attendee
1125
-                    $this->_associate_attendee_with_registration($registration, $attendee);
1126
-                    // \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ );
1127
-                    if (! $registration->attendee() instanceof EE_Attendee) {
1128
-                        EE_Error::add_error(
1129
-                            sprintf(
1130
-                                esc_html_x(
1131
-                                    'Registration %s has an invalid or missing Attendee object.',
1132
-                                    'Registration 123-456-789 has an invalid or missing Attendee object.',
1133
-                                    'event_espresso'
1134
-                                ),
1135
-                                $reg_url_link
1136
-                            ),
1137
-                            __FILE__,
1138
-                            __FUNCTION__,
1139
-                            __LINE__
1140
-                        );
1141
-                        return false;
1142
-                    }
1143
-                    /** @type EE_Registration_Processor $registration_processor */
1144
-                    $registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1145
-                    // at this point, we should have enough details about the registrant to consider the registration
1146
-                    // NOT incomplete
1147
-                    $registration_processor->toggle_incomplete_registration_status_to_default(
1148
-                        $registration,
1149
-                        false,
1150
-                        new Context(
1151
-                            'spco_reg_step_attendee_information_process_registrations',
1152
-                            esc_html__(
1153
-                                'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.',
1154
-                                'event_espresso'
1155
-                            )
1156
-                        )
1157
-                    );
1158
-                    // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to
1159
-                    // abandoned
1160
-                    $this->checkout->transaction->toggle_failed_transaction_status();
1161
-                    // if we've gotten this far, then let's save what we have
1162
-                    $registration->save();
1163
-                    // add relation between TXN and registration
1164
-                    $this->_associate_registration_with_transaction($registration);
1165
-                }
1166
-            } else {
1167
-                EE_Error::add_error(
1168
-                    esc_html__(
1169
-                        'An invalid or missing line item ID was encountered while attempting to process the registration form.',
1170
-                        'event_espresso'
1171
-                    ),
1172
-                    __FILE__,
1173
-                    __FUNCTION__,
1174
-                    __LINE__
1175
-                );
1176
-                // remove malformed data
1177
-                unset($valid_data[ $reg_url_link ]);
1178
-                return false;
1179
-            }
1180
-        } // end of foreach ( $this->checkout->transaction->registrations()  as $registration )
1181
-        return $att_nmbr;
1182
-    }
1183
-
1184
-
1185
-    /**
1186
-     *    _save_registration_form_input
1187
-     *
1188
-     * @param EE_Registration $registration
1189
-     * @param string          $form_input
1190
-     * @param string          $input_value
1191
-     * @return bool
1192
-     * @throws EE_Error
1193
-     * @throws InvalidArgumentException
1194
-     * @throws InvalidDataTypeException
1195
-     * @throws InvalidInterfaceException
1196
-     * @throws ReflectionException
1197
-     */
1198
-    private function _save_registration_form_input(
1199
-        EE_Registration $registration,
1200
-        $form_input = '',
1201
-        $input_value = ''
1202
-    ) {
1203
-        // \EEH_Debug_Tools::printr( __FUNCTION__, __CLASS__, __FILE__, __LINE__, 2 );
1204
-        // \EEH_Debug_Tools::printr( $form_input, '$form_input', __FILE__, __LINE__ );
1205
-        // \EEH_Debug_Tools::printr( $input_value, '$input_value', __FILE__, __LINE__ );
1206
-        // allow for plugins to hook in and do their own processing of the form input.
1207
-        // For plugins to bypass normal processing here, they just need to return a boolean value.
1208
-        if (apply_filters(
1209
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information___save_registration_form_input',
1210
-            false,
1211
-            $registration,
1212
-            $form_input,
1213
-            $input_value,
1214
-            $this
1215
-        )) {
1216
-            return true;
1217
-        }
1218
-        /*
129
+		$this->_print_copy_info = $reg_config->copyAttendeeInfo();
130
+		$primary_registrant = null;
131
+		// autoload Line_Item_Display classes
132
+		EEH_Autoloader::register_line_item_display_autoloaders();
133
+		$Line_Item_Display = new EE_Line_Item_Display();
134
+		// calculate taxes
135
+		$Line_Item_Display->display_line_item(
136
+			$this->checkout->cart->get_grand_total(),
137
+			array('set_tax_rate' => true)
138
+		);
139
+		/** @var $subsections EE_Form_Section_Proper[] */
140
+		$extra_inputs_section = $this->reg_step_hidden_inputs();
141
+		$subsections = array(
142
+			'default_hidden_inputs' => $extra_inputs_section,
143
+		);
144
+
145
+		// if this isn't a revisit, and they have the privacy consent box enalbed, add it
146
+		if (! $this->checkout->revisit && $reg_config->isConsentCheckboxEnabled()) {
147
+			$extra_inputs_section->add_subsections(
148
+				array(
149
+					'consent_box' => new EE_Form_Section_Proper(
150
+						array(
151
+							'layout_strategy' =>
152
+								new EE_Template_Layout(
153
+									array(
154
+										'input_template_file' => SPCO_REG_STEPS_PATH . $this->_slug . '/privacy_consent.template.php',
155
+									)
156
+								),
157
+							'subsections'     => array(
158
+								'consent' => new EE_Checkbox_Multi_Input(
159
+									array(
160
+										'consent' => $reg_config->getConsentCheckboxLabelText(),
161
+									),
162
+									array(
163
+										'required'                          => true,
164
+										'required_validation_error_message' => esc_html__(
165
+											'You must consent to these terms in order to register.',
166
+											'event_espresso'
167
+										),
168
+										'html_label_text'                   => '',
169
+									)
170
+								),
171
+							),
172
+						)
173
+					),
174
+				),
175
+				null,
176
+				false
177
+			);
178
+		}
179
+		$template_args = array(
180
+			'revisit'       => $this->checkout->revisit,
181
+			'registrations' => array(),
182
+			'ticket_count'  => array(),
183
+		);
184
+		// grab the saved registrations from the transaction
185
+		$registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
186
+		if ($registrations) {
187
+			foreach ($registrations as $registration) {
188
+				// can this registration be processed during this visit ?
189
+				if ($registration instanceof EE_Registration
190
+					&& $this->checkout->visit_allows_processing_of_this_registration($registration)
191
+				) {
192
+					$subsections[ $registration->reg_url_link() ] = $this->_registrations_reg_form($registration);
193
+					$template_args['registrations'][ $registration->reg_url_link() ] = $registration;
194
+					$template_args['ticket_count'][ $registration->ticket()->ID() ] = isset(
195
+						$template_args['ticket_count'][ $registration->ticket()->ID() ]
196
+					)
197
+						? $template_args['ticket_count'][ $registration->ticket()->ID() ] + 1
198
+						: 1;
199
+					$ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs(
200
+						$this->checkout->cart->get_grand_total(),
201
+						'Ticket',
202
+						array($registration->ticket()->ID())
203
+					);
204
+					$ticket_line_item = is_array($ticket_line_item)
205
+						? reset($ticket_line_item)
206
+						: $ticket_line_item;
207
+					$template_args['ticket_line_item'][ $registration->ticket()->ID() ] =
208
+						$Line_Item_Display->display_line_item($ticket_line_item);
209
+					if ($registration->is_primary_registrant()) {
210
+						$primary_registrant = $registration->reg_url_link();
211
+					}
212
+				}
213
+			}
214
+			if ($primary_registrant && count($registrations) > 1) {
215
+				$copy_options['spco_copy_attendee_chk'] = $this->_print_copy_info
216
+					? $this->_copy_attendee_info_form()
217
+					: $this->_auto_copy_attendee_info();
218
+				// generate hidden input
219
+				if (isset($subsections[ $primary_registrant ])
220
+					&& $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper
221
+				) {
222
+					$subsections[ $primary_registrant ]->add_subsections(
223
+						$copy_options,
224
+						'primary_registrant',
225
+						false
226
+					);
227
+				}
228
+			}
229
+		}
230
+		return new EE_Form_Section_Proper(
231
+			array(
232
+				'name'            => $this->reg_form_name(),
233
+				'html_id'         => $this->reg_form_name(),
234
+				'subsections'     => $subsections,
235
+				'layout_strategy' => new EE_Template_Layout(
236
+					array(
237
+						'layout_template_file' => $this->_template, // layout_template
238
+						'template_args'        => $template_args,
239
+					)
240
+				),
241
+			)
242
+		);
243
+	}
244
+
245
+
246
+	/**
247
+	 * @param EE_Registration $registration
248
+	 * @return EE_Form_Section_Base
249
+	 * @throws EE_Error
250
+	 * @throws InvalidArgumentException
251
+	 * @throws EntityNotFoundException
252
+	 * @throws InvalidDataTypeException
253
+	 * @throws InvalidInterfaceException
254
+	 * @throws ReflectionException
255
+	 */
256
+	private function _registrations_reg_form(EE_Registration $registration)
257
+	{
258
+		static $attendee_nmbr = 1;
259
+		$form_args = array();
260
+		// verify that registration has valid event
261
+		if ($registration->event() instanceof EE_Event) {
262
+			$field_name = 'Event_Question_Group.'
263
+				. EEM_Event_Question_Group::instance()->fieldNameForContext(
264
+					$registration->is_primary_registrant()
265
+				);
266
+			$question_groups = $registration->event()->question_groups(
267
+				apply_filters(
268
+					// @codingStandardsIgnoreStart
269
+					'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters',
270
+					// @codingStandardsIgnoreEnd
271
+					[
272
+						[
273
+							'Event.EVT_ID'                     => $registration->event()->ID(),
274
+							$field_name => true,
275
+						],
276
+						'order_by' => ['QSG_order' => 'ASC'],
277
+					],
278
+					$registration,
279
+					$this
280
+				)
281
+			);
282
+			if ($question_groups) {
283
+				// array of params to pass to parent constructor
284
+				$form_args = array(
285
+					'html_id'         => 'ee-registration-' . $registration->reg_url_link(),
286
+					'html_class'      => 'ee-reg-form-attendee-dv',
287
+					'html_style'      => $this->checkout->admin_request
288
+						? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;'
289
+						: '',
290
+					'subsections'     => array(),
291
+					'layout_strategy' => new EE_Fieldset_Section_Layout(
292
+						array(
293
+							'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text',
294
+							'legend_text'  => sprintf(
295
+								esc_html_x(
296
+									'Attendee %d',
297
+									'Attendee 123',
298
+									'event_espresso'
299
+								),
300
+								$attendee_nmbr
301
+							),
302
+						)
303
+					),
304
+				);
305
+				foreach ($question_groups as $question_group) {
306
+					if ($question_group instanceof EE_Question_Group) {
307
+						$form_args['subsections'][ $question_group->identifier() ] = $this->_question_group_reg_form(
308
+							$registration,
309
+							$question_group
310
+						);
311
+					}
312
+				}
313
+				// add hidden input
314
+				$form_args['subsections']['additional_attendee_reg_info'] = $this->_additional_attendee_reg_info_input(
315
+					$registration
316
+				);
317
+
318
+				/**
319
+				 * @var $reg_config EE_Registration_Config
320
+				 */
321
+				$reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config');
322
+
323
+				// if we have question groups for additional attendees, then display the copy options
324
+				$this->_print_copy_info = $attendee_nmbr > 1 ? $reg_config->copyAttendeeInfo() : false;
325
+				if ($registration->is_primary_registrant()) {
326
+					// generate hidden input
327
+					$form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs(
328
+						$registration
329
+					);
330
+				}
331
+			}
332
+		}
333
+		$attendee_nmbr++;
334
+		return ! empty($form_args)
335
+			? new EE_Form_Section_Proper($form_args)
336
+			: new EE_Form_Section_HTML();
337
+	}
338
+
339
+
340
+	/**
341
+	 * @param EE_Registration $registration
342
+	 * @param bool            $additional_attendee_reg_info
343
+	 * @return EE_Form_Input_Base
344
+	 * @throws EE_Error
345
+	 */
346
+	private function _additional_attendee_reg_info_input(
347
+		EE_Registration $registration,
348
+		$additional_attendee_reg_info = true
349
+	) {
350
+		// generate hidden input
351
+		return new EE_Hidden_Input(
352
+			array(
353
+				'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(),
354
+				'default' => $additional_attendee_reg_info,
355
+			)
356
+		);
357
+	}
358
+
359
+
360
+	/**
361
+	 * @param EE_Registration   $registration
362
+	 * @param EE_Question_Group $question_group
363
+	 * @return EE_Form_Section_Proper
364
+	 * @throws EE_Error
365
+	 * @throws InvalidArgumentException
366
+	 * @throws InvalidDataTypeException
367
+	 * @throws InvalidInterfaceException
368
+	 * @throws ReflectionException
369
+	 */
370
+	private function _question_group_reg_form(EE_Registration $registration, EE_Question_Group $question_group)
371
+	{
372
+		// array of params to pass to parent constructor
373
+		$form_args = array(
374
+			'html_id'         => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID(),
375
+			'html_class'      => $this->checkout->admin_request
376
+				? 'form-table ee-reg-form-qstn-grp-dv'
377
+				: 'ee-reg-form-qstn-grp-dv',
378
+			'html_label_id'   => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-'
379
+								 . $registration->ID() . '-lbl',
380
+			'subsections'     => array(
381
+				'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group),
382
+			),
383
+			'layout_strategy' => $this->checkout->admin_request
384
+				? new EE_Admin_Two_Column_Layout()
385
+				: new EE_Div_Per_Section_Layout(),
386
+		);
387
+		// where params
388
+		$query_params = array('QST_deleted' => 0);
389
+		// don't load admin only questions on the frontend
390
+		if (! $this->checkout->admin_request) {
391
+			$query_params['QST_admin_only'] = array('!=', true);
392
+		}
393
+		$questions = $question_group->get_many_related(
394
+			'Question',
395
+			apply_filters(
396
+				'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__related_questions_query_params',
397
+				array(
398
+					$query_params,
399
+					'order_by' => array(
400
+						'Question_Group_Question.QGQ_order' => 'ASC',
401
+					),
402
+				),
403
+				$question_group,
404
+				$registration,
405
+				$this
406
+			)
407
+		);
408
+		// filter for additional content before questions
409
+		$form_args['subsections']['reg_form_questions_before'] = new EE_Form_Section_HTML(
410
+			apply_filters(
411
+				'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions',
412
+				'',
413
+				$registration,
414
+				$question_group,
415
+				$this
416
+			)
417
+		);
418
+		// loop thru questions
419
+		foreach ($questions as $question) {
420
+			if ($question instanceof EE_Question) {
421
+				$identifier = $question->is_system_question()
422
+					? $question->system_ID()
423
+					: $question->ID();
424
+				$form_args['subsections'][ $identifier ] = $this->reg_form_question($registration, $question);
425
+			}
426
+		}
427
+		$form_args['subsections'] = apply_filters(
428
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information__question_group_reg_form__subsections_array',
429
+			$form_args['subsections'],
430
+			$registration,
431
+			$question_group,
432
+			$this
433
+		);
434
+		// filter for additional content after questions
435
+		$form_args['subsections']['reg_form_questions_after'] = new EE_Form_Section_HTML(
436
+			apply_filters(
437
+				'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions',
438
+				'',
439
+				$registration,
440
+				$question_group,
441
+				$this
442
+			)
443
+		);
444
+		// d($form_args);
445
+		$question_group_reg_form = new EE_Form_Section_Proper($form_args);
446
+		return apply_filters(
447
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form',
448
+			$question_group_reg_form,
449
+			$registration,
450
+			$question_group,
451
+			$this
452
+		);
453
+	}
454
+
455
+
456
+	/**
457
+	 * @param EE_Question_Group $question_group
458
+	 * @return    EE_Form_Section_HTML
459
+	 */
460
+	private function _question_group_header(EE_Question_Group $question_group)
461
+	{
462
+		$html = '';
463
+		// group_name
464
+		if ($question_group->show_group_name() && $question_group->name() !== '') {
465
+			if ($this->checkout->admin_request) {
466
+				$html .= EEH_HTML::br();
467
+				$html .= EEH_HTML::h3(
468
+					$question_group->name(),
469
+					'',
470
+					'ee-reg-form-qstn-grp-title title',
471
+					'font-size: 1.3em; padding-left:0;'
472
+				);
473
+			} else {
474
+				$html .= EEH_HTML::h4(
475
+					$question_group->name(),
476
+					'',
477
+					'ee-reg-form-qstn-grp-title section-title'
478
+				);
479
+			}
480
+		}
481
+		// group_desc
482
+		if ($question_group->show_group_desc() && $question_group->desc() !== '') {
483
+			$html .= EEH_HTML::p(
484
+				$question_group->desc(),
485
+				'',
486
+				$this->checkout->admin_request
487
+					? 'ee-reg-form-qstn-grp-desc-pg'
488
+					: 'ee-reg-form-qstn-grp-desc-pg small-text lt-grey-text'
489
+			);
490
+		}
491
+		return new EE_Form_Section_HTML($html);
492
+	}
493
+
494
+
495
+	/**
496
+	 * @return    EE_Form_Section_Proper
497
+	 * @throws EE_Error
498
+	 * @throws InvalidArgumentException
499
+	 * @throws ReflectionException
500
+	 * @throws InvalidDataTypeException
501
+	 * @throws InvalidInterfaceException
502
+	 */
503
+	private function _copy_attendee_info_form()
504
+	{
505
+		// array of params to pass to parent constructor
506
+		return new EE_Form_Section_Proper(
507
+			array(
508
+				'subsections'     => $this->_copy_attendee_info_inputs(),
509
+				'layout_strategy' => new EE_Template_Layout(
510
+					array(
511
+						'layout_template_file'     => SPCO_REG_STEPS_PATH
512
+													  . $this->_slug
513
+													  . '/copy_attendee_info.template.php',
514
+						'begin_template_file'      => null,
515
+						'input_template_file'      => null,
516
+						'subsection_template_file' => null,
517
+						'end_template_file'        => null,
518
+					)
519
+				),
520
+			)
521
+		);
522
+	}
523
+
524
+
525
+	/**
526
+	 * @return EE_Form_Section_HTML
527
+	 * @throws DomainException
528
+	 * @throws InvalidArgumentException
529
+	 * @throws InvalidDataTypeException
530
+	 * @throws InvalidInterfaceException
531
+	 */
532
+	private function _auto_copy_attendee_info()
533
+	{
534
+		return new EE_Form_Section_HTML(
535
+			EEH_Template::locate_template(
536
+				SPCO_REG_STEPS_PATH . $this->_slug . '/_auto_copy_attendee_info.template.php',
537
+				apply_filters(
538
+					'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args',
539
+					array()
540
+				),
541
+				true,
542
+				true
543
+			)
544
+		);
545
+	}
546
+
547
+
548
+	/**
549
+	 * @return array
550
+	 * @throws EE_Error
551
+	 * @throws InvalidArgumentException
552
+	 * @throws ReflectionException
553
+	 * @throws InvalidDataTypeException
554
+	 * @throws InvalidInterfaceException
555
+	 */
556
+	private function _copy_attendee_info_inputs()
557
+	{
558
+		$copy_attendee_info_inputs = array();
559
+		$prev_ticket = null;
560
+		// grab the saved registrations from the transaction
561
+		$registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
562
+		foreach ($registrations as $registration) {
563
+			// for all  attendees other than the primary attendee
564
+			if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) {
565
+				// if this is a new ticket OR if this is the very first additional attendee after the primary attendee
566
+				if ($registration->ticket()->ID() !== $prev_ticket) {
567
+					$item_name = $registration->ticket()->name();
568
+					$item_name .= $registration->ticket()->description() !== ''
569
+						? ' - ' . $registration->ticket()->description()
570
+						: '';
571
+					$copy_attendee_info_inputs[ 'spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID(
572
+					) . ']' ] =
573
+						new EE_Form_Section_HTML(
574
+							'<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>'
575
+						);
576
+					$prev_ticket = $registration->ticket()->ID();
577
+				}
578
+
579
+				$copy_attendee_info_inputs[ 'spco_copy_attendee_chk[' . $registration->ID() . ']' ] =
580
+					new EE_Checkbox_Multi_Input(
581
+						array(
582
+							$registration->ID() => sprintf(
583
+								esc_html_x('Attendee #%s', 'Attendee #123', 'event_espresso'),
584
+								$registration->count()
585
+							),
586
+						),
587
+						array(
588
+							'html_id'                 => 'spco-copy-attendee-chk-' . $registration->reg_url_link(),
589
+							'html_class'              => 'spco-copy-attendee-chk ee-do-not-validate',
590
+							'display_html_label_text' => false,
591
+						)
592
+					);
593
+			}
594
+		}
595
+		return $copy_attendee_info_inputs;
596
+	}
597
+
598
+
599
+	/**
600
+	 * @param EE_Registration $registration
601
+	 * @return    EE_Form_Input_Base
602
+	 * @throws EE_Error
603
+	 */
604
+	private function _additional_primary_registrant_inputs(EE_Registration $registration)
605
+	{
606
+		// generate hidden input
607
+		return new EE_Hidden_Input(
608
+			array(
609
+				'html_id' => 'primary_registrant',
610
+				'default' => $registration->reg_url_link(),
611
+			)
612
+		);
613
+	}
614
+
615
+
616
+	/**
617
+	 * @param EE_Registration $registration
618
+	 * @param EE_Question     $question
619
+	 * @return EE_Form_Input_Base
620
+	 * @throws EE_Error
621
+	 * @throws InvalidArgumentException
622
+	 * @throws InvalidDataTypeException
623
+	 * @throws InvalidInterfaceException
624
+	 * @throws ReflectionException
625
+	 */
626
+	public function reg_form_question(EE_Registration $registration, EE_Question $question)
627
+	{
628
+
629
+		// if this question was for an attendee detail, then check for that answer
630
+		$answer_value = EEM_Answer::instance()->get_attendee_property_answer_value(
631
+			$registration,
632
+			$question->system_ID()
633
+		);
634
+		$answer = $answer_value === null
635
+			? EEM_Answer::instance()->get_one(
636
+				array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()))
637
+			)
638
+			: null;
639
+		// if NOT returning to edit an existing registration
640
+		// OR if this question is for an attendee property
641
+		// OR we still don't have an EE_Answer object
642
+		if ($answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link()) {
643
+			// create an EE_Answer object for storing everything in
644
+			$answer = EE_Answer::new_instance(
645
+				array(
646
+					'QST_ID' => $question->ID(),
647
+					'REG_ID' => $registration->ID(),
648
+				)
649
+			);
650
+		}
651
+		// verify instance
652
+		if ($answer instanceof EE_Answer) {
653
+			if (! empty($answer_value)) {
654
+				$answer->set('ANS_value', $answer_value);
655
+			}
656
+			$answer->cache('Question', $question);
657
+			// remember system ID had a bug where sometimes it could be null
658
+			$answer_cache_id = $question->is_system_question()
659
+				? $question->system_ID() . '-' . $registration->reg_url_link()
660
+				: $question->ID() . '-' . $registration->reg_url_link();
661
+			$registration->cache('Answer', $answer, $answer_cache_id);
662
+		}
663
+		return $this->_generate_question_input($registration, $question, $answer);
664
+	}
665
+
666
+
667
+	/**
668
+	 * @param EE_Registration $registration
669
+	 * @param EE_Question     $question
670
+	 * @param                 $answer
671
+	 * @return EE_Form_Input_Base
672
+	 * @throws EE_Error
673
+	 * @throws InvalidArgumentException
674
+	 * @throws ReflectionException
675
+	 * @throws InvalidDataTypeException
676
+	 * @throws InvalidInterfaceException
677
+	 */
678
+	private function _generate_question_input(EE_Registration $registration, EE_Question $question, $answer)
679
+	{
680
+		$identifier = $question->is_system_question()
681
+			? $question->system_ID()
682
+			: $question->ID();
683
+		$this->_required_questions[ $identifier ] = $question->required() ? true : false;
684
+		add_filter(
685
+			'FHEE__EE_Question__generate_form_input__country_options',
686
+			array($this, 'use_cached_countries_for_form_input'),
687
+			10,
688
+			4
689
+		);
690
+		add_filter(
691
+			'FHEE__EE_Question__generate_form_input__state_options',
692
+			array($this, 'use_cached_states_for_form_input'),
693
+			10,
694
+			4
695
+		);
696
+		$input_constructor_args = array(
697
+			'html_name'        => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']',
698
+			'html_id'          => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
699
+			'html_class'       => 'ee-reg-qstn ee-reg-qstn-' . $identifier,
700
+			'html_label_id'    => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier,
701
+			'html_label_class' => 'ee-reg-qstn',
702
+		);
703
+		$input_constructor_args['html_label_id'] .= '-lbl';
704
+		if ($answer instanceof EE_Answer && $answer->ID()) {
705
+			$input_constructor_args['html_name'] .= '[' . $answer->ID() . ']';
706
+			$input_constructor_args['html_id'] .= '-' . $answer->ID();
707
+			$input_constructor_args['html_label_id'] .= '-' . $answer->ID();
708
+		}
709
+		$form_input = $question->generate_form_input(
710
+			$registration,
711
+			$answer,
712
+			$input_constructor_args
713
+		);
714
+		remove_filter(
715
+			'FHEE__EE_Question__generate_form_input__country_options',
716
+			array($this, 'use_cached_countries_for_form_input')
717
+		);
718
+		remove_filter(
719
+			'FHEE__EE_Question__generate_form_input__state_options',
720
+			array($this, 'use_cached_states_for_form_input')
721
+		);
722
+		return $form_input;
723
+	}
724
+
725
+
726
+	/**
727
+	 * Gets the list of countries for the form input
728
+	 *
729
+	 * @param array|null      $countries_list
730
+	 * @param EE_Question     $question
731
+	 * @param EE_Registration $registration
732
+	 * @param EE_Answer       $answer
733
+	 * @return array 2d keys are country IDs, values are their names
734
+	 * @throws EE_Error
735
+	 * @throws InvalidArgumentException
736
+	 * @throws InvalidDataTypeException
737
+	 * @throws InvalidInterfaceException
738
+	 * @throws ReflectionException
739
+	 */
740
+	public function use_cached_countries_for_form_input(
741
+		$countries_list,
742
+		EE_Question $question = null,
743
+		EE_Registration $registration = null,
744
+		EE_Answer $answer = null
745
+	) {
746
+		$country_options = array('' => '');
747
+		// get possibly cached list of countries
748
+		$countries = $this->checkout->action === 'process_reg_step'
749
+			? EEM_Country::instance()->get_all_countries()
750
+			: EEM_Country::instance()->get_all_active_countries();
751
+		if (! empty($countries)) {
752
+			foreach ($countries as $country) {
753
+				if ($country instanceof EE_Country) {
754
+					$country_options[ $country->ID() ] = $country->name();
755
+				}
756
+			}
757
+		}
758
+		if ($question instanceof EE_Question && $registration instanceof EE_Registration) {
759
+			$answer = EEM_Answer::instance()->get_one(
760
+				array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID()))
761
+			);
762
+		} else {
763
+			$answer = EE_Answer::new_instance();
764
+		}
765
+		$country_options = apply_filters(
766
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options',
767
+			$country_options,
768
+			$this,
769
+			$registration,
770
+			$question,
771
+			$answer
772
+		);
773
+		return $country_options;
774
+	}
775
+
776
+
777
+	/**
778
+	 * Gets the list of states for the form input
779
+	 *
780
+	 * @param array|null      $states_list
781
+	 * @param EE_Question     $question
782
+	 * @param EE_Registration $registration
783
+	 * @param EE_Answer       $answer
784
+	 * @return array 2d keys are state IDs, values are their names
785
+	 * @throws EE_Error
786
+	 * @throws InvalidArgumentException
787
+	 * @throws InvalidDataTypeException
788
+	 * @throws InvalidInterfaceException
789
+	 * @throws ReflectionException
790
+	 */
791
+	public function use_cached_states_for_form_input(
792
+		$states_list,
793
+		EE_Question $question = null,
794
+		EE_Registration $registration = null,
795
+		EE_Answer $answer = null
796
+	) {
797
+		$state_options = array('' => array('' => ''));
798
+		$states = $this->checkout->action === 'process_reg_step'
799
+			? EEM_State::instance()->get_all_states()
800
+			: EEM_State::instance()->get_all_active_states();
801
+		if (! empty($states)) {
802
+			foreach ($states as $state) {
803
+				if ($state instanceof EE_State) {
804
+					$state_options[ $state->country()->name() ][ $state->ID() ] = $state->name();
805
+				}
806
+			}
807
+		}
808
+		$state_options = apply_filters(
809
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options',
810
+			$state_options,
811
+			$this,
812
+			$registration,
813
+			$question,
814
+			$answer
815
+		);
816
+		return $state_options;
817
+	}
818
+
819
+
820
+	/********************************************************************************************************/
821
+	/****************************************  PROCESS REG STEP  ****************************************/
822
+	/********************************************************************************************************/
823
+
824
+
825
+	/**
826
+	 * @return bool
827
+	 * @throws EE_Error
828
+	 * @throws InvalidArgumentException
829
+	 * @throws ReflectionException
830
+	 * @throws RuntimeException
831
+	 * @throws InvalidDataTypeException
832
+	 * @throws InvalidInterfaceException
833
+	 */
834
+	public function process_reg_step()
835
+	{
836
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
837
+		// grab validated data from form
838
+		$valid_data = $this->checkout->current_step->valid_data();
839
+		// EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ );
840
+		// EEH_Debug_Tools::printr( $valid_data, '$valid_data', __FILE__, __LINE__ );
841
+		// if we don't have any $valid_data then something went TERRIBLY WRONG !!!
842
+		if (empty($valid_data)) {
843
+			EE_Error::add_error(
844
+				esc_html__('No valid question responses were received.', 'event_espresso'),
845
+				__FILE__,
846
+				__FUNCTION__,
847
+				__LINE__
848
+			);
849
+			return false;
850
+		}
851
+		if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) {
852
+			EE_Error::add_error(
853
+				esc_html__(
854
+					'A valid transaction could not be initiated for processing your registrations.',
855
+					'event_espresso'
856
+				),
857
+				__FILE__,
858
+				__FUNCTION__,
859
+				__LINE__
860
+			);
861
+			return false;
862
+		}
863
+		// get cached registrations
864
+		$registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params);
865
+		// verify we got the goods
866
+		if (empty($registrations)) {
867
+			// combine the old translated string with a new one, in order to not break translations
868
+			$error_message = esc_html__(
869
+				'Your form data could not be applied to any valid registrations.',
870
+				'event_espresso'
871
+			)
872
+			. sprintf(
873
+				esc_html_x(
874
+					'%3$sThis can sometimes happen if too much time has been taken to complete the registration process.%3$sPlease return to the %1$sEvent List%2$s and reselect your tickets. If the problem continues, please contact the site administrator.',
875
+					'(line break)This can sometimes happen if too much time has been taken to complete the registration process.(line break)Please return to the (link)Event List(end link) and reselect your tickets. If the problem continues, please contact the site administrator.',
876
+					'event_espresso'
877
+				),
878
+				'<a href="' . get_post_type_archive_link('espresso_events') . '" >',
879
+				'</a>',
880
+				'<br />'
881
+			);
882
+			EE_Error::add_error(
883
+				$error_message,
884
+				__FILE__,
885
+				__FUNCTION__,
886
+				__LINE__
887
+			);
888
+			return false;
889
+		}
890
+		// extract attendee info from form data and save to model objects
891
+		$registrations_processed = $this->_process_registrations($registrations, $valid_data);
892
+		// if first pass thru SPCO,
893
+		// then let's check processed registrations against the total number of tickets in the cart
894
+		if ($registrations_processed === false) {
895
+			// but return immediately if the previous step exited early due to errors
896
+			return false;
897
+		}
898
+		if (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) {
899
+			// generate a correctly translated string for all possible singular/plural combinations
900
+			if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) {
901
+				$error_msg = sprintf(
902
+					esc_html_x(
903
+						'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed',
904
+						'There was 1 ticket in the Event Queue, but 2 registrations were processed',
905
+						'event_espresso'
906
+					),
907
+					$this->checkout->total_ticket_count,
908
+					$registrations_processed
909
+				);
910
+			} elseif ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) {
911
+				$error_msg = sprintf(
912
+					esc_html_x(
913
+						'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed',
914
+						'There was a total of 2 tickets in the Event Queue, but only 1 registration was processed',
915
+						'event_espresso'
916
+					),
917
+					$this->checkout->total_ticket_count,
918
+					$registrations_processed
919
+				);
920
+			} else {
921
+				$error_msg = sprintf(
922
+					esc_html__(
923
+						'There was a total of 2 tickets in the Event Queue, but 2 registrations were processed',
924
+						'event_espresso'
925
+					),
926
+					$this->checkout->total_ticket_count,
927
+					$registrations_processed
928
+				);
929
+			}
930
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
931
+			return false;
932
+		}
933
+		// mark this reg step as completed
934
+		$this->set_completed();
935
+		$this->_set_success_message(
936
+			esc_html__('The Attendee Information Step has been successfully completed.', 'event_espresso')
937
+		);
938
+		// do action in case a plugin wants to do something with the data submitted in step 1.
939
+		// passes EE_Single_Page_Checkout, and it's posted data
940
+		do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data);
941
+		return true;
942
+	}
943
+
944
+
945
+	/**
946
+	 *    _process_registrations
947
+	 *
948
+	 * @param EE_Registration[] $registrations
949
+	 * @param array[][]         $valid_data
950
+	 * @return bool|int
951
+	 * @throws EntityNotFoundException
952
+	 * @throws EE_Error
953
+	 * @throws InvalidArgumentException
954
+	 * @throws ReflectionException
955
+	 * @throws RuntimeException
956
+	 * @throws InvalidDataTypeException
957
+	 * @throws InvalidInterfaceException
958
+	 */
959
+	private function _process_registrations($registrations = array(), $valid_data = array())
960
+	{
961
+		// load resources and set some defaults
962
+		EE_Registry::instance()->load_model('Attendee');
963
+		// holder for primary registrant attendee object
964
+		$this->checkout->primary_attendee_obj = null;
965
+		// array for tracking reg form data for the primary registrant
966
+		$primary_registrant = array(
967
+			'line_item_id' => null,
968
+		);
969
+		$copy_primary = false;
970
+		// reg form sections that do not contain inputs
971
+		$non_input_form_sections = array(
972
+			'primary_registrant',
973
+			'additional_attendee_reg_info',
974
+			'spco_copy_attendee_chk',
975
+		);
976
+		// attendee counter
977
+		$att_nmbr = 0;
978
+		// grab the saved registrations from the transaction
979
+		foreach ($registrations as $registration) {
980
+			// verify EE_Registration object
981
+			if (! $registration instanceof EE_Registration) {
982
+				EE_Error::add_error(
983
+					esc_html__(
984
+						'An invalid Registration object was discovered when attempting to process your registration information.',
985
+						'event_espresso'
986
+					),
987
+					__FILE__,
988
+					__FUNCTION__,
989
+					__LINE__
990
+				);
991
+				return false;
992
+			}
993
+			/** @var string $reg_url_link */
994
+			$reg_url_link = $registration->reg_url_link();
995
+			// reg_url_link exists ?
996
+			if (! empty($reg_url_link)) {
997
+				// should this registration be processed during this visit ?
998
+				if ($this->checkout->visit_allows_processing_of_this_registration($registration)) {
999
+					// if NOT revisiting, then let's save the registration now,
1000
+					// so that we have a REG_ID to use when generating other objects
1001
+					if (! $this->checkout->revisit) {
1002
+						$registration->save();
1003
+					}
1004
+					/**
1005
+					 * This allows plugins to trigger a fail on processing of a
1006
+					 * registration for any conditions they may have for it to pass.
1007
+					 *
1008
+					 * @var bool   if true is returned by the plugin then the
1009
+					 *            registration processing is halted.
1010
+					 */
1011
+					if (apply_filters(
1012
+						'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process',
1013
+						false,
1014
+						$att_nmbr,
1015
+						$registration,
1016
+						$registrations,
1017
+						$valid_data,
1018
+						$this
1019
+					)) {
1020
+						return false;
1021
+					}
1022
+
1023
+					// Houston, we have a registration!
1024
+					$att_nmbr++;
1025
+					$this->_attendee_data[ $reg_url_link ] = array();
1026
+					// grab any existing related answer objects
1027
+					$this->_registration_answers = $registration->answers();
1028
+					// unset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] );
1029
+					if (isset($valid_data[ $reg_url_link ])) {
1030
+						// do we need to copy basic info from primary attendee ?
1031
+						$copy_primary = isset($valid_data[ $reg_url_link ]['additional_attendee_reg_info'])
1032
+										&& absint($valid_data[ $reg_url_link ]['additional_attendee_reg_info']) === 0;
1033
+						// filter form input data for this registration
1034
+						$valid_data[ $reg_url_link ] = (array) apply_filters(
1035
+							'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item',
1036
+							$valid_data[ $reg_url_link ]
1037
+						);
1038
+						if (isset($valid_data['primary_attendee'])) {
1039
+							$primary_registrant['line_item_id'] = ! empty($valid_data['primary_attendee'])
1040
+								? $valid_data['primary_attendee']
1041
+								: false;
1042
+							unset($valid_data['primary_attendee']);
1043
+						}
1044
+						// now loop through our array of valid post data && process attendee reg forms
1045
+						foreach ($valid_data[ $reg_url_link ] as $form_section => $form_inputs) {
1046
+							if (! in_array($form_section, $non_input_form_sections, true)) {
1047
+								foreach ($form_inputs as $form_input => $input_value) {
1048
+									// \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ );
1049
+									// check for critical inputs
1050
+									if (! $this->_verify_critical_attendee_details_are_set_and_validate_email(
1051
+										$form_input,
1052
+										$input_value
1053
+									)
1054
+									) {
1055
+										return false;
1056
+									}
1057
+									// store a bit of data about the primary attendee
1058
+									if ($att_nmbr === 1
1059
+										&& ! empty($input_value)
1060
+										&& $reg_url_link === $primary_registrant['line_item_id']
1061
+									) {
1062
+										$primary_registrant[ $form_input ] = $input_value;
1063
+									} elseif ($copy_primary
1064
+											  && $input_value === null
1065
+											  && isset($primary_registrant[ $form_input ])
1066
+									) {
1067
+										$input_value = $primary_registrant[ $form_input ];
1068
+									}
1069
+									// now attempt to save the input data
1070
+									if (! $this->_save_registration_form_input(
1071
+										$registration,
1072
+										$form_input,
1073
+										$input_value
1074
+									)
1075
+									) {
1076
+										EE_Error::add_error(
1077
+											sprintf(
1078
+												esc_html_x(
1079
+													'Unable to save registration form data for the form input: "%1$s" with the submitted value: "%2$s"',
1080
+													'Unable to save registration form data for the form input: "form input name" with the submitted value: "form input value"',
1081
+													'event_espresso'
1082
+												),
1083
+												$form_input,
1084
+												$input_value
1085
+											),
1086
+											__FILE__,
1087
+											__FUNCTION__,
1088
+											__LINE__
1089
+										);
1090
+										return false;
1091
+									}
1092
+								}
1093
+							}
1094
+						}  // end of foreach ( $valid_data[ $reg_url_link ] as $form_section => $form_inputs )
1095
+					}
1096
+					// EEH_Debug_Tools::printr( $this->_attendee_data, '$this->_attendee_data', __FILE__, __LINE__ );
1097
+					// this registration does not require additional attendee information ?
1098
+					if ($copy_primary
1099
+						&& $att_nmbr > 1
1100
+						&& $this->checkout->primary_attendee_obj instanceof EE_Attendee
1101
+					) {
1102
+						// just copy the primary registrant
1103
+						$attendee = $this->checkout->primary_attendee_obj;
1104
+					} else {
1105
+						// ensure critical details are set for additional attendees
1106
+						$this->_attendee_data[ $reg_url_link ] = $att_nmbr > 1
1107
+							? $this->_copy_critical_attendee_details_from_primary_registrant(
1108
+								$this->_attendee_data[ $reg_url_link ]
1109
+							)
1110
+							: $this->_attendee_data[ $reg_url_link ];
1111
+						// execute create attendee command (which may return an existing attendee)
1112
+						$attendee = EE_Registry::instance()->BUS->execute(
1113
+							new CreateAttendeeCommand(
1114
+								$this->_attendee_data[ $reg_url_link ],
1115
+								$registration
1116
+							)
1117
+						);
1118
+						// who's #1 ?
1119
+						if ($att_nmbr === 1) {
1120
+							$this->checkout->primary_attendee_obj = $attendee;
1121
+						}
1122
+					}
1123
+					// EEH_Debug_Tools::printr( $attendee, '$attendee', __FILE__, __LINE__ );
1124
+					// add relation to registration, set attendee ID, and cache attendee
1125
+					$this->_associate_attendee_with_registration($registration, $attendee);
1126
+					// \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ );
1127
+					if (! $registration->attendee() instanceof EE_Attendee) {
1128
+						EE_Error::add_error(
1129
+							sprintf(
1130
+								esc_html_x(
1131
+									'Registration %s has an invalid or missing Attendee object.',
1132
+									'Registration 123-456-789 has an invalid or missing Attendee object.',
1133
+									'event_espresso'
1134
+								),
1135
+								$reg_url_link
1136
+							),
1137
+							__FILE__,
1138
+							__FUNCTION__,
1139
+							__LINE__
1140
+						);
1141
+						return false;
1142
+					}
1143
+					/** @type EE_Registration_Processor $registration_processor */
1144
+					$registration_processor = EE_Registry::instance()->load_class('Registration_Processor');
1145
+					// at this point, we should have enough details about the registrant to consider the registration
1146
+					// NOT incomplete
1147
+					$registration_processor->toggle_incomplete_registration_status_to_default(
1148
+						$registration,
1149
+						false,
1150
+						new Context(
1151
+							'spco_reg_step_attendee_information_process_registrations',
1152
+							esc_html__(
1153
+								'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.',
1154
+								'event_espresso'
1155
+							)
1156
+						)
1157
+					);
1158
+					// we can also consider the TXN to not have been failed, so temporarily upgrade it's status to
1159
+					// abandoned
1160
+					$this->checkout->transaction->toggle_failed_transaction_status();
1161
+					// if we've gotten this far, then let's save what we have
1162
+					$registration->save();
1163
+					// add relation between TXN and registration
1164
+					$this->_associate_registration_with_transaction($registration);
1165
+				}
1166
+			} else {
1167
+				EE_Error::add_error(
1168
+					esc_html__(
1169
+						'An invalid or missing line item ID was encountered while attempting to process the registration form.',
1170
+						'event_espresso'
1171
+					),
1172
+					__FILE__,
1173
+					__FUNCTION__,
1174
+					__LINE__
1175
+				);
1176
+				// remove malformed data
1177
+				unset($valid_data[ $reg_url_link ]);
1178
+				return false;
1179
+			}
1180
+		} // end of foreach ( $this->checkout->transaction->registrations()  as $registration )
1181
+		return $att_nmbr;
1182
+	}
1183
+
1184
+
1185
+	/**
1186
+	 *    _save_registration_form_input
1187
+	 *
1188
+	 * @param EE_Registration $registration
1189
+	 * @param string          $form_input
1190
+	 * @param string          $input_value
1191
+	 * @return bool
1192
+	 * @throws EE_Error
1193
+	 * @throws InvalidArgumentException
1194
+	 * @throws InvalidDataTypeException
1195
+	 * @throws InvalidInterfaceException
1196
+	 * @throws ReflectionException
1197
+	 */
1198
+	private function _save_registration_form_input(
1199
+		EE_Registration $registration,
1200
+		$form_input = '',
1201
+		$input_value = ''
1202
+	) {
1203
+		// \EEH_Debug_Tools::printr( __FUNCTION__, __CLASS__, __FILE__, __LINE__, 2 );
1204
+		// \EEH_Debug_Tools::printr( $form_input, '$form_input', __FILE__, __LINE__ );
1205
+		// \EEH_Debug_Tools::printr( $input_value, '$input_value', __FILE__, __LINE__ );
1206
+		// allow for plugins to hook in and do their own processing of the form input.
1207
+		// For plugins to bypass normal processing here, they just need to return a boolean value.
1208
+		if (apply_filters(
1209
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information___save_registration_form_input',
1210
+			false,
1211
+			$registration,
1212
+			$form_input,
1213
+			$input_value,
1214
+			$this
1215
+		)) {
1216
+			return true;
1217
+		}
1218
+		/*
1219 1219
          * $answer_cache_id is the key used to find the EE_Answer we want
1220 1220
          * @see https://events.codebasehq.com/projects/event-espresso/tickets/10477
1221 1221
          */
1222
-        $answer_cache_id = $this->checkout->reg_url_link
1223
-            ? $form_input . '-' . $registration->reg_url_link()
1224
-            : $form_input;
1225
-        $answer_is_obj = isset($this->_registration_answers[ $answer_cache_id ])
1226
-                         && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer;
1227
-        // rename form_inputs if they are EE_Attendee properties
1228
-        switch ((string) $form_input) {
1229
-            case 'state':
1230
-            case 'STA_ID':
1231
-                $attendee_property = true;
1232
-                $form_input = 'STA_ID';
1233
-                break;
1234
-
1235
-            case 'country':
1236
-            case 'CNT_ISO':
1237
-                $attendee_property = true;
1238
-                $form_input = 'CNT_ISO';
1239
-                break;
1240
-
1241
-            default:
1242
-                $ATT_input = 'ATT_' . $form_input;
1243
-                // EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ );
1244
-                $attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false;
1245
-                $form_input = $attendee_property ? 'ATT_' . $form_input : $form_input;
1246
-        }
1247
-        // EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ );
1248
-        // EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ );
1249
-        // EEH_Debug_Tools::printr( $answer_is_obj, '$answer_is_obj', __FILE__, __LINE__ );
1250
-        // if this form input has a corresponding attendee property
1251
-        if ($attendee_property) {
1252
-            $this->_attendee_data[ $registration->reg_url_link() ][ $form_input ] = $input_value;
1253
-            if ($answer_is_obj) {
1254
-                // and delete the corresponding answer since we won't be storing this data in that object
1255
-                $registration->_remove_relation_to($this->_registration_answers[ $answer_cache_id ], 'Answer');
1256
-                $this->_registration_answers[ $answer_cache_id ]->delete_permanently();
1257
-            }
1258
-            return true;
1259
-        }
1260
-        if ($answer_is_obj) {
1261
-            // save this data to the answer object
1262
-            $this->_registration_answers[ $answer_cache_id ]->set_value($input_value);
1263
-            $result = $this->_registration_answers[ $answer_cache_id ]->save();
1264
-            return $result !== false;
1265
-        }
1266
-        foreach ($this->_registration_answers as $answer) {
1267
-            if ($answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id) {
1268
-                $answer->set_value($input_value);
1269
-                $result = $answer->save();
1270
-                return $result !== false;
1271
-            }
1272
-        }
1273
-        return false;
1274
-    }
1275
-
1276
-
1277
-    /**
1278
-     *    _verify_critical_attendee_details_are_set
1279
-     *
1280
-     * @param string $form_input
1281
-     * @param string $input_value
1282
-     * @return boolean
1283
-     */
1284
-    private function _verify_critical_attendee_details_are_set_and_validate_email(
1285
-        $form_input = '',
1286
-        $input_value = ''
1287
-    ) {
1288
-        if (empty($input_value)) {
1289
-            // if the form input isn't marked as being required, then just return
1290
-            if (! isset($this->_required_questions[ $form_input ]) || ! $this->_required_questions[ $form_input ]) {
1291
-                return true;
1292
-            }
1293
-            switch ($form_input) {
1294
-                case 'fname':
1295
-                    EE_Error::add_error(
1296
-                        esc_html__('First Name is a required value.', 'event_espresso'),
1297
-                        __FILE__,
1298
-                        __FUNCTION__,
1299
-                        __LINE__
1300
-                    );
1301
-                    return false;
1302
-                    break;
1303
-                case 'lname':
1304
-                    EE_Error::add_error(
1305
-                        esc_html__('Last Name is a required value.', 'event_espresso'),
1306
-                        __FILE__,
1307
-                        __FUNCTION__,
1308
-                        __LINE__
1309
-                    );
1310
-                    return false;
1311
-                    break;
1312
-                case 'email':
1313
-                    EE_Error::add_error(
1314
-                        esc_html__('Please enter a valid email address.', 'event_espresso'),
1315
-                        __FILE__,
1316
-                        __FUNCTION__,
1317
-                        __LINE__
1318
-                    );
1319
-                    return false;
1320
-                    break;
1321
-            }
1322
-        }
1323
-        return true;
1324
-    }
1325
-
1326
-
1327
-    /**
1328
-     *    _associate_attendee_with_registration
1329
-     *
1330
-     * @param EE_Registration $registration
1331
-     * @param EE_Attendee     $attendee
1332
-     * @return void
1333
-     * @throws EE_Error
1334
-     * @throws InvalidArgumentException
1335
-     * @throws ReflectionException
1336
-     * @throws RuntimeException
1337
-     * @throws InvalidDataTypeException
1338
-     * @throws InvalidInterfaceException
1339
-     */
1340
-    private function _associate_attendee_with_registration(EE_Registration $registration, EE_Attendee $attendee)
1341
-    {
1342
-        // add relation to attendee
1343
-        $registration->_add_relation_to($attendee, 'Attendee');
1344
-        $registration->set_attendee_id($attendee->ID());
1345
-        $registration->update_cache_after_object_save('Attendee', $attendee);
1346
-    }
1347
-
1348
-
1349
-    /**
1350
-     *    _associate_registration_with_transaction
1351
-     *
1352
-     * @param EE_Registration $registration
1353
-     * @return void
1354
-     * @throws EE_Error
1355
-     * @throws InvalidArgumentException
1356
-     * @throws ReflectionException
1357
-     * @throws InvalidDataTypeException
1358
-     * @throws InvalidInterfaceException
1359
-     */
1360
-    private function _associate_registration_with_transaction(EE_Registration $registration)
1361
-    {
1362
-        // add relation to registration
1363
-        $this->checkout->transaction->_add_relation_to($registration, 'Registration');
1364
-        $this->checkout->transaction->update_cache_after_object_save('Registration', $registration);
1365
-    }
1366
-
1367
-
1368
-    /**
1369
-     *    _copy_critical_attendee_details_from_primary_registrant
1370
-     *    ensures that all attendees at least have data for first name, last name, and email address
1371
-     *
1372
-     * @param array $attendee_data
1373
-     * @return array
1374
-     * @throws EE_Error
1375
-     * @throws InvalidArgumentException
1376
-     * @throws ReflectionException
1377
-     * @throws InvalidDataTypeException
1378
-     * @throws InvalidInterfaceException
1379
-     */
1380
-    private function _copy_critical_attendee_details_from_primary_registrant($attendee_data = array())
1381
-    {
1382
-        // bare minimum critical details include first name, last name, email address
1383
-        $critical_attendee_details = array('ATT_fname', 'ATT_lname', 'ATT_email');
1384
-        // add address info to critical details?
1385
-        if (apply_filters(
1386
-            'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details',
1387
-            false
1388
-        )) {
1389
-            $address_details = array(
1390
-                'ATT_address',
1391
-                'ATT_address2',
1392
-                'ATT_city',
1393
-                'STA_ID',
1394
-                'CNT_ISO',
1395
-                'ATT_zip',
1396
-                'ATT_phone',
1397
-            );
1398
-            $critical_attendee_details = array_merge($critical_attendee_details, $address_details);
1399
-        }
1400
-        foreach ($critical_attendee_details as $critical_attendee_detail) {
1401
-            if (! isset($attendee_data[ $critical_attendee_detail ])
1402
-                || empty($attendee_data[ $critical_attendee_detail ])
1403
-            ) {
1404
-                $attendee_data[ $critical_attendee_detail ] = $this->checkout->primary_attendee_obj->get(
1405
-                    $critical_attendee_detail
1406
-                );
1407
-            }
1408
-        }
1409
-        return $attendee_data;
1410
-    }
1411
-
1412
-
1413
-    /**
1414
-     *    update_reg_step
1415
-     *    this is the final step after a user  revisits the site to edit their attendee information
1416
-     *    this gets called AFTER the process_reg_step() method above
1417
-     *
1418
-     * @return bool
1419
-     * @throws EE_Error
1420
-     * @throws InvalidArgumentException
1421
-     * @throws ReflectionException
1422
-     * @throws RuntimeException
1423
-     * @throws InvalidDataTypeException
1424
-     * @throws InvalidInterfaceException
1425
-     */
1426
-    public function update_reg_step()
1427
-    {
1428
-        // save everything
1429
-        if ($this->process_reg_step()) {
1430
-            $this->checkout->redirect = true;
1431
-            $this->checkout->redirect_url = add_query_arg(
1432
-                array(
1433
-                    'e_reg_url_link' => $this->checkout->reg_url_link,
1434
-                    'revisit'        => true,
1435
-                ),
1436
-                $this->checkout->thank_you_page_url
1437
-            );
1438
-            $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
1439
-            return true;
1440
-        }
1441
-        return false;
1442
-    }
1222
+		$answer_cache_id = $this->checkout->reg_url_link
1223
+			? $form_input . '-' . $registration->reg_url_link()
1224
+			: $form_input;
1225
+		$answer_is_obj = isset($this->_registration_answers[ $answer_cache_id ])
1226
+						 && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer;
1227
+		// rename form_inputs if they are EE_Attendee properties
1228
+		switch ((string) $form_input) {
1229
+			case 'state':
1230
+			case 'STA_ID':
1231
+				$attendee_property = true;
1232
+				$form_input = 'STA_ID';
1233
+				break;
1234
+
1235
+			case 'country':
1236
+			case 'CNT_ISO':
1237
+				$attendee_property = true;
1238
+				$form_input = 'CNT_ISO';
1239
+				break;
1240
+
1241
+			default:
1242
+				$ATT_input = 'ATT_' . $form_input;
1243
+				// EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ );
1244
+				$attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false;
1245
+				$form_input = $attendee_property ? 'ATT_' . $form_input : $form_input;
1246
+		}
1247
+		// EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ );
1248
+		// EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ );
1249
+		// EEH_Debug_Tools::printr( $answer_is_obj, '$answer_is_obj', __FILE__, __LINE__ );
1250
+		// if this form input has a corresponding attendee property
1251
+		if ($attendee_property) {
1252
+			$this->_attendee_data[ $registration->reg_url_link() ][ $form_input ] = $input_value;
1253
+			if ($answer_is_obj) {
1254
+				// and delete the corresponding answer since we won't be storing this data in that object
1255
+				$registration->_remove_relation_to($this->_registration_answers[ $answer_cache_id ], 'Answer');
1256
+				$this->_registration_answers[ $answer_cache_id ]->delete_permanently();
1257
+			}
1258
+			return true;
1259
+		}
1260
+		if ($answer_is_obj) {
1261
+			// save this data to the answer object
1262
+			$this->_registration_answers[ $answer_cache_id ]->set_value($input_value);
1263
+			$result = $this->_registration_answers[ $answer_cache_id ]->save();
1264
+			return $result !== false;
1265
+		}
1266
+		foreach ($this->_registration_answers as $answer) {
1267
+			if ($answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id) {
1268
+				$answer->set_value($input_value);
1269
+				$result = $answer->save();
1270
+				return $result !== false;
1271
+			}
1272
+		}
1273
+		return false;
1274
+	}
1275
+
1276
+
1277
+	/**
1278
+	 *    _verify_critical_attendee_details_are_set
1279
+	 *
1280
+	 * @param string $form_input
1281
+	 * @param string $input_value
1282
+	 * @return boolean
1283
+	 */
1284
+	private function _verify_critical_attendee_details_are_set_and_validate_email(
1285
+		$form_input = '',
1286
+		$input_value = ''
1287
+	) {
1288
+		if (empty($input_value)) {
1289
+			// if the form input isn't marked as being required, then just return
1290
+			if (! isset($this->_required_questions[ $form_input ]) || ! $this->_required_questions[ $form_input ]) {
1291
+				return true;
1292
+			}
1293
+			switch ($form_input) {
1294
+				case 'fname':
1295
+					EE_Error::add_error(
1296
+						esc_html__('First Name is a required value.', 'event_espresso'),
1297
+						__FILE__,
1298
+						__FUNCTION__,
1299
+						__LINE__
1300
+					);
1301
+					return false;
1302
+					break;
1303
+				case 'lname':
1304
+					EE_Error::add_error(
1305
+						esc_html__('Last Name is a required value.', 'event_espresso'),
1306
+						__FILE__,
1307
+						__FUNCTION__,
1308
+						__LINE__
1309
+					);
1310
+					return false;
1311
+					break;
1312
+				case 'email':
1313
+					EE_Error::add_error(
1314
+						esc_html__('Please enter a valid email address.', 'event_espresso'),
1315
+						__FILE__,
1316
+						__FUNCTION__,
1317
+						__LINE__
1318
+					);
1319
+					return false;
1320
+					break;
1321
+			}
1322
+		}
1323
+		return true;
1324
+	}
1325
+
1326
+
1327
+	/**
1328
+	 *    _associate_attendee_with_registration
1329
+	 *
1330
+	 * @param EE_Registration $registration
1331
+	 * @param EE_Attendee     $attendee
1332
+	 * @return void
1333
+	 * @throws EE_Error
1334
+	 * @throws InvalidArgumentException
1335
+	 * @throws ReflectionException
1336
+	 * @throws RuntimeException
1337
+	 * @throws InvalidDataTypeException
1338
+	 * @throws InvalidInterfaceException
1339
+	 */
1340
+	private function _associate_attendee_with_registration(EE_Registration $registration, EE_Attendee $attendee)
1341
+	{
1342
+		// add relation to attendee
1343
+		$registration->_add_relation_to($attendee, 'Attendee');
1344
+		$registration->set_attendee_id($attendee->ID());
1345
+		$registration->update_cache_after_object_save('Attendee', $attendee);
1346
+	}
1347
+
1348
+
1349
+	/**
1350
+	 *    _associate_registration_with_transaction
1351
+	 *
1352
+	 * @param EE_Registration $registration
1353
+	 * @return void
1354
+	 * @throws EE_Error
1355
+	 * @throws InvalidArgumentException
1356
+	 * @throws ReflectionException
1357
+	 * @throws InvalidDataTypeException
1358
+	 * @throws InvalidInterfaceException
1359
+	 */
1360
+	private function _associate_registration_with_transaction(EE_Registration $registration)
1361
+	{
1362
+		// add relation to registration
1363
+		$this->checkout->transaction->_add_relation_to($registration, 'Registration');
1364
+		$this->checkout->transaction->update_cache_after_object_save('Registration', $registration);
1365
+	}
1366
+
1367
+
1368
+	/**
1369
+	 *    _copy_critical_attendee_details_from_primary_registrant
1370
+	 *    ensures that all attendees at least have data for first name, last name, and email address
1371
+	 *
1372
+	 * @param array $attendee_data
1373
+	 * @return array
1374
+	 * @throws EE_Error
1375
+	 * @throws InvalidArgumentException
1376
+	 * @throws ReflectionException
1377
+	 * @throws InvalidDataTypeException
1378
+	 * @throws InvalidInterfaceException
1379
+	 */
1380
+	private function _copy_critical_attendee_details_from_primary_registrant($attendee_data = array())
1381
+	{
1382
+		// bare minimum critical details include first name, last name, email address
1383
+		$critical_attendee_details = array('ATT_fname', 'ATT_lname', 'ATT_email');
1384
+		// add address info to critical details?
1385
+		if (apply_filters(
1386
+			'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details',
1387
+			false
1388
+		)) {
1389
+			$address_details = array(
1390
+				'ATT_address',
1391
+				'ATT_address2',
1392
+				'ATT_city',
1393
+				'STA_ID',
1394
+				'CNT_ISO',
1395
+				'ATT_zip',
1396
+				'ATT_phone',
1397
+			);
1398
+			$critical_attendee_details = array_merge($critical_attendee_details, $address_details);
1399
+		}
1400
+		foreach ($critical_attendee_details as $critical_attendee_detail) {
1401
+			if (! isset($attendee_data[ $critical_attendee_detail ])
1402
+				|| empty($attendee_data[ $critical_attendee_detail ])
1403
+			) {
1404
+				$attendee_data[ $critical_attendee_detail ] = $this->checkout->primary_attendee_obj->get(
1405
+					$critical_attendee_detail
1406
+				);
1407
+			}
1408
+		}
1409
+		return $attendee_data;
1410
+	}
1411
+
1412
+
1413
+	/**
1414
+	 *    update_reg_step
1415
+	 *    this is the final step after a user  revisits the site to edit their attendee information
1416
+	 *    this gets called AFTER the process_reg_step() method above
1417
+	 *
1418
+	 * @return bool
1419
+	 * @throws EE_Error
1420
+	 * @throws InvalidArgumentException
1421
+	 * @throws ReflectionException
1422
+	 * @throws RuntimeException
1423
+	 * @throws InvalidDataTypeException
1424
+	 * @throws InvalidInterfaceException
1425
+	 */
1426
+	public function update_reg_step()
1427
+	{
1428
+		// save everything
1429
+		if ($this->process_reg_step()) {
1430
+			$this->checkout->redirect = true;
1431
+			$this->checkout->redirect_url = add_query_arg(
1432
+				array(
1433
+					'e_reg_url_link' => $this->checkout->reg_url_link,
1434
+					'revisit'        => true,
1435
+				),
1436
+				$this->checkout->thank_you_page_url
1437
+			);
1438
+			$this->checkout->json_response->set_redirect_url($this->checkout->redirect_url);
1439
+			return true;
1440
+		}
1441
+		return false;
1442
+	}
1443 1443
 }
Please login to merge, or discard this patch.
core/services/assets/AssetManager.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -270,7 +270,7 @@
 block discarded – undo
270 270
      * @param string $asset_type
271 271
      * @param string $handle
272 272
      * @param array  $extra_dependencies
273
-     * @return array
273
+     * @return string
274 274
      * @since $VID:$
275 275
      */
276 276
     private function getAssetDetails($asset_type, $handle, $extra_dependencies = [])
Please login to merge, or discard this patch.
Indentation   +255 added lines, -255 removed lines patch added patch discarded remove patch
@@ -23,284 +23,284 @@
 block discarded – undo
23 23
 abstract class AssetManager implements AssetManagerInterface
24 24
 {
25 25
 
26
-    /**
27
-     * @var AssetCollection $assets
28
-     */
29
-    protected $assets;
26
+	/**
27
+	 * @var AssetCollection $assets
28
+	 */
29
+	protected $assets;
30 30
 
31
-    /**
32
-     * @var DomainInterface
33
-     */
34
-    protected $domain;
31
+	/**
32
+	 * @var DomainInterface
33
+	 */
34
+	protected $domain;
35 35
 
36
-    /**
37
-     * @var Registry $registry
38
-     */
39
-    protected $registry;
36
+	/**
37
+	 * @var Registry $registry
38
+	 */
39
+	protected $registry;
40 40
 
41 41
 
42
-    /**
43
-     * AssetRegister constructor.
44
-     *
45
-     * @param DomainInterface $domain
46
-     * @param AssetCollection $assets
47
-     * @param Registry        $registry
48
-     */
49
-    public function __construct(DomainInterface $domain, AssetCollection $assets, Registry $registry)
50
-    {
51
-        $this->domain = $domain;
52
-        $this->assets = $assets;
53
-        $this->registry = $registry;
54
-        add_action('wp_enqueue_scripts', array($this, 'addManifestFile'), 0);
55
-        add_action('admin_enqueue_scripts', array($this, 'addManifestFile'), 0);
56
-        add_action('wp_enqueue_scripts', array($this, 'addAssets'), 2);
57
-        add_action('admin_enqueue_scripts', array($this, 'addAssets'), 2);
58
-    }
42
+	/**
43
+	 * AssetRegister constructor.
44
+	 *
45
+	 * @param DomainInterface $domain
46
+	 * @param AssetCollection $assets
47
+	 * @param Registry        $registry
48
+	 */
49
+	public function __construct(DomainInterface $domain, AssetCollection $assets, Registry $registry)
50
+	{
51
+		$this->domain = $domain;
52
+		$this->assets = $assets;
53
+		$this->registry = $registry;
54
+		add_action('wp_enqueue_scripts', array($this, 'addManifestFile'), 0);
55
+		add_action('admin_enqueue_scripts', array($this, 'addManifestFile'), 0);
56
+		add_action('wp_enqueue_scripts', array($this, 'addAssets'), 2);
57
+		add_action('admin_enqueue_scripts', array($this, 'addAssets'), 2);
58
+	}
59 59
 
60 60
 
61
-    /**
62
-     * @since 4.9.71.p
63
-     * @return string
64
-     */
65
-    public function assetNamespace()
66
-    {
67
-        return $this->domain->assetNamespace();
68
-    }
61
+	/**
62
+	 * @since 4.9.71.p
63
+	 * @return string
64
+	 */
65
+	public function assetNamespace()
66
+	{
67
+		return $this->domain->assetNamespace();
68
+	}
69 69
 
70 70
 
71
-    /**
72
-     * @return void
73
-     * @throws DuplicateCollectionIdentifierException
74
-     * @throws InvalidDataTypeException
75
-     * @throws InvalidEntityException
76
-     * @since 4.9.62.p
77
-     */
78
-    public function addManifestFile()
79
-    {
80
-        // if a manifest file has already been added for this domain, then just return
81
-        if ($this->assets->has($this->domain->assetNamespace())) {
82
-            return;
83
-        }
84
-        $asset = new ManifestFile($this->domain);
85
-        $this->assets->add($asset, $this->domain->assetNamespace());
86
-    }
71
+	/**
72
+	 * @return void
73
+	 * @throws DuplicateCollectionIdentifierException
74
+	 * @throws InvalidDataTypeException
75
+	 * @throws InvalidEntityException
76
+	 * @since 4.9.62.p
77
+	 */
78
+	public function addManifestFile()
79
+	{
80
+		// if a manifest file has already been added for this domain, then just return
81
+		if ($this->assets->has($this->domain->assetNamespace())) {
82
+			return;
83
+		}
84
+		$asset = new ManifestFile($this->domain);
85
+		$this->assets->add($asset, $this->domain->assetNamespace());
86
+	}
87 87
 
88 88
 
89
-    /**
90
-     * @return ManifestFile[]
91
-     * @since 4.9.62.p
92
-     */
93
-    public function getManifestFile()
94
-    {
95
-        return $this->assets->getManifestFiles();
96
-    }
89
+	/**
90
+	 * @return ManifestFile[]
91
+	 * @since 4.9.62.p
92
+	 */
93
+	public function getManifestFile()
94
+	{
95
+		return $this->assets->getManifestFiles();
96
+	}
97 97
 
98 98
 
99
-    /**
100
-     * @param string $handle
101
-     * @param string $source
102
-     * @param array  $dependencies
103
-     * @param bool   $load_in_footer
104
-     * @param string $version
105
-     * @return JavascriptAsset
106
-     * @throws DuplicateCollectionIdentifierException
107
-     * @throws InvalidDataTypeException
108
-     * @throws InvalidEntityException
109
-     * @throws DomainException
110
-     * @since 4.9.62.p
111
-     */
112
-    public function addJavascript(
113
-        $handle,
114
-        $source,
115
-        array $dependencies = array(),
116
-        $load_in_footer = true,
117
-        $version = ''
118
-    ) {
119
-        $asset = new JavascriptAsset(
120
-            $handle,
121
-            $source,
122
-            array_unique($dependencies),
123
-            $load_in_footer,
124
-            $this->domain,
125
-            $version
126
-        );
127
-        $this->assets->add($asset, $handle);
128
-        return $asset;
129
-    }
99
+	/**
100
+	 * @param string $handle
101
+	 * @param string $source
102
+	 * @param array  $dependencies
103
+	 * @param bool   $load_in_footer
104
+	 * @param string $version
105
+	 * @return JavascriptAsset
106
+	 * @throws DuplicateCollectionIdentifierException
107
+	 * @throws InvalidDataTypeException
108
+	 * @throws InvalidEntityException
109
+	 * @throws DomainException
110
+	 * @since 4.9.62.p
111
+	 */
112
+	public function addJavascript(
113
+		$handle,
114
+		$source,
115
+		array $dependencies = array(),
116
+		$load_in_footer = true,
117
+		$version = ''
118
+	) {
119
+		$asset = new JavascriptAsset(
120
+			$handle,
121
+			$source,
122
+			array_unique($dependencies),
123
+			$load_in_footer,
124
+			$this->domain,
125
+			$version
126
+		);
127
+		$this->assets->add($asset, $handle);
128
+		return $asset;
129
+	}
130 130
 
131 131
 
132
-    /**
133
-     * Used to register a javascript asset where everything is dynamically derived from the given handle.
134
-     *
135
-     * @param string       $handle
136
-     * @param string|array $extra_dependencies
137
-     * @return JavascriptAsset
138
-     * @throws DuplicateCollectionIdentifierException
139
-     * @throws InvalidDataTypeException
140
-     * @throws InvalidEntityException
141
-     * @throws DomainException
142
-     */
143
-    public function addJs($handle, $extra_dependencies = [])
144
-    {
145
-        $details = $this->getAssetDetails(
146
-            Asset::TYPE_JS,
147
-            $handle,
148
-            $extra_dependencies
149
-        );
150
-        return $this->addJavascript(
151
-            $handle,
152
-            $this->registry->getJsUrl($this->domain->assetNamespace(), $handle),
153
-            $details['dependencies'],
154
-            true,
155
-            $details['version']
156
-        );
157
-    }
132
+	/**
133
+	 * Used to register a javascript asset where everything is dynamically derived from the given handle.
134
+	 *
135
+	 * @param string       $handle
136
+	 * @param string|array $extra_dependencies
137
+	 * @return JavascriptAsset
138
+	 * @throws DuplicateCollectionIdentifierException
139
+	 * @throws InvalidDataTypeException
140
+	 * @throws InvalidEntityException
141
+	 * @throws DomainException
142
+	 */
143
+	public function addJs($handle, $extra_dependencies = [])
144
+	{
145
+		$details = $this->getAssetDetails(
146
+			Asset::TYPE_JS,
147
+			$handle,
148
+			$extra_dependencies
149
+		);
150
+		return $this->addJavascript(
151
+			$handle,
152
+			$this->registry->getJsUrl($this->domain->assetNamespace(), $handle),
153
+			$details['dependencies'],
154
+			true,
155
+			$details['version']
156
+		);
157
+	}
158 158
 
159 159
 
160
-    /**
161
-     * @param string $handle
162
-     * @param array  $dependencies
163
-     * @param bool   $load_in_footer
164
-     * @param string $version
165
-     * @return JavascriptAsset
166
-     * @throws DomainException
167
-     * @throws DuplicateCollectionIdentifierException
168
-     * @throws InvalidDataTypeException
169
-     * @throws InvalidEntityException
170
-     * @since 4.9.71.p
171
-     */
172
-    public function addVendorJavascript(
173
-        $handle,
174
-        array $dependencies = array(),
175
-        $load_in_footer = true,
176
-        $version = ''
177
-    ) {
178
-        $dev_suffix = wp_scripts_get_suffix('dev');
179
-        $vendor_path = $this->domain->pluginUrl() . 'assets/vendor/';
180
-        return $this->addJavascript(
181
-            $handle,
182
-            "{$vendor_path}{$handle}{$dev_suffix}.js",
183
-            $dependencies,
184
-            $load_in_footer,
185
-            $version
186
-        );
187
-    }
160
+	/**
161
+	 * @param string $handle
162
+	 * @param array  $dependencies
163
+	 * @param bool   $load_in_footer
164
+	 * @param string $version
165
+	 * @return JavascriptAsset
166
+	 * @throws DomainException
167
+	 * @throws DuplicateCollectionIdentifierException
168
+	 * @throws InvalidDataTypeException
169
+	 * @throws InvalidEntityException
170
+	 * @since 4.9.71.p
171
+	 */
172
+	public function addVendorJavascript(
173
+		$handle,
174
+		array $dependencies = array(),
175
+		$load_in_footer = true,
176
+		$version = ''
177
+	) {
178
+		$dev_suffix = wp_scripts_get_suffix('dev');
179
+		$vendor_path = $this->domain->pluginUrl() . 'assets/vendor/';
180
+		return $this->addJavascript(
181
+			$handle,
182
+			"{$vendor_path}{$handle}{$dev_suffix}.js",
183
+			$dependencies,
184
+			$load_in_footer,
185
+			$version
186
+		);
187
+	}
188 188
 
189 189
 
190
-    /**
191
-     * @param string $handle
192
-     * @param string $source
193
-     * @param array  $dependencies
194
-     * @param string $media
195
-     * @param string $version
196
-     * @return StylesheetAsset
197
-     * @throws DomainException
198
-     * @throws DuplicateCollectionIdentifierException
199
-     * @throws InvalidDataTypeException
200
-     * @throws InvalidEntityException
201
-     * @since 4.9.62.p
202
-     */
203
-    public function addStylesheet(
204
-        $handle,
205
-        $source,
206
-        array $dependencies = array(),
207
-        $media = 'all',
208
-        $version = ''
209
-    ) {
210
-        $asset = new StylesheetAsset(
211
-            $handle,
212
-            $source,
213
-            array_unique($dependencies),
214
-            $this->domain,
215
-            $media,
216
-            $version
217
-        );
218
-        $this->assets->add($asset, $handle);
219
-        return $asset;
220
-    }
190
+	/**
191
+	 * @param string $handle
192
+	 * @param string $source
193
+	 * @param array  $dependencies
194
+	 * @param string $media
195
+	 * @param string $version
196
+	 * @return StylesheetAsset
197
+	 * @throws DomainException
198
+	 * @throws DuplicateCollectionIdentifierException
199
+	 * @throws InvalidDataTypeException
200
+	 * @throws InvalidEntityException
201
+	 * @since 4.9.62.p
202
+	 */
203
+	public function addStylesheet(
204
+		$handle,
205
+		$source,
206
+		array $dependencies = array(),
207
+		$media = 'all',
208
+		$version = ''
209
+	) {
210
+		$asset = new StylesheetAsset(
211
+			$handle,
212
+			$source,
213
+			array_unique($dependencies),
214
+			$this->domain,
215
+			$media,
216
+			$version
217
+		);
218
+		$this->assets->add($asset, $handle);
219
+		return $asset;
220
+	}
221 221
 
222 222
 
223
-    /**
224
-     * Used to register a css asset where everything is dynamically derived from the given handle.
225
-     *
226
-     * @param string       $handle
227
-     * @param string|array $extra_dependencies
228
-     * @return StylesheetAsset
229
-     * @throws DuplicateCollectionIdentifierException
230
-     * @throws InvalidDataTypeException
231
-     * @throws InvalidEntityException
232
-     * @throws DomainException
233
-     */
234
-    public function addCss($handle, $extra_dependencies = [])
235
-    {
236
-        $details = $this->getAssetDetails(
237
-            Asset::TYPE_CSS,
238
-            $handle,
239
-            $extra_dependencies
240
-        );
241
-        return $this->addStylesheet(
242
-            $handle,
243
-            $this->registry->getCssUrl($this->domain->assetNamespace(), $handle),
244
-            $details['dependencies'],
245
-            'all',
246
-            $details['version']
247
-        );
248
-    }
223
+	/**
224
+	 * Used to register a css asset where everything is dynamically derived from the given handle.
225
+	 *
226
+	 * @param string       $handle
227
+	 * @param string|array $extra_dependencies
228
+	 * @return StylesheetAsset
229
+	 * @throws DuplicateCollectionIdentifierException
230
+	 * @throws InvalidDataTypeException
231
+	 * @throws InvalidEntityException
232
+	 * @throws DomainException
233
+	 */
234
+	public function addCss($handle, $extra_dependencies = [])
235
+	{
236
+		$details = $this->getAssetDetails(
237
+			Asset::TYPE_CSS,
238
+			$handle,
239
+			$extra_dependencies
240
+		);
241
+		return $this->addStylesheet(
242
+			$handle,
243
+			$this->registry->getCssUrl($this->domain->assetNamespace(), $handle),
244
+			$details['dependencies'],
245
+			'all',
246
+			$details['version']
247
+		);
248
+	}
249 249
 
250 250
 
251
-    /**
252
-     * @param string $handle
253
-     * @return bool
254
-     * @since 4.9.62.p
255
-     */
256
-    public function enqueueAsset($handle)
257
-    {
258
-        if ($this->assets->has($handle)) {
259
-            $asset = $this->assets->get($handle);
260
-            if ($asset->isRegistered()) {
261
-                $asset->enqueueAsset();
262
-                return true;
263
-            }
264
-        }
265
-        return false;
266
-    }
251
+	/**
252
+	 * @param string $handle
253
+	 * @return bool
254
+	 * @since 4.9.62.p
255
+	 */
256
+	public function enqueueAsset($handle)
257
+	{
258
+		if ($this->assets->has($handle)) {
259
+			$asset = $this->assets->get($handle);
260
+			if ($asset->isRegistered()) {
261
+				$asset->enqueueAsset();
262
+				return true;
263
+			}
264
+		}
265
+		return false;
266
+	}
267 267
 
268 268
 
269
-    /**
270
-     * @param string $asset_type
271
-     * @param string $handle
272
-     * @param array  $extra_dependencies
273
-     * @return array
274
-     * @since $VID:$
275
-     */
276
-    private function getAssetDetails($asset_type, $handle, $extra_dependencies = [])
277
-    {
278
-        $getAssetDetails = '';
279
-        switch ($asset_type) {
280
-            case Asset::TYPE_JS :
281
-                $getAssetDetails = 'getJsAssetDetails';
282
-                break;
283
-            case Asset::TYPE_CSS :
284
-                $getAssetDetails = 'getCssAssetDetails';
285
-                break;
286
-        }
287
-        if ($getAssetDetails === '') {
288
-            return ['dependencies' => [], 'version' => ''];
289
-        }
290
-        $details = $this->registry->$getAssetDetails(
291
-            $this->domain->assetNamespace(),
292
-            $handle
293
-        );
294
-        $details['dependencies'] = isset($details['dependencies'])
295
-            ? $details['dependencies']
296
-            : [];
297
-        $details['version'] = isset($details['version'])
298
-            ? $details['version']
299
-            : '';
300
-        $details['dependencies'] = ! empty($extra_dependencies)
301
-            ? array_merge($details['dependencies'], (array) $extra_dependencies)
302
-            : $details['dependencies'];
303
-        return $details;
269
+	/**
270
+	 * @param string $asset_type
271
+	 * @param string $handle
272
+	 * @param array  $extra_dependencies
273
+	 * @return array
274
+	 * @since $VID:$
275
+	 */
276
+	private function getAssetDetails($asset_type, $handle, $extra_dependencies = [])
277
+	{
278
+		$getAssetDetails = '';
279
+		switch ($asset_type) {
280
+			case Asset::TYPE_JS :
281
+				$getAssetDetails = 'getJsAssetDetails';
282
+				break;
283
+			case Asset::TYPE_CSS :
284
+				$getAssetDetails = 'getCssAssetDetails';
285
+				break;
286
+		}
287
+		if ($getAssetDetails === '') {
288
+			return ['dependencies' => [], 'version' => ''];
289
+		}
290
+		$details = $this->registry->$getAssetDetails(
291
+			$this->domain->assetNamespace(),
292
+			$handle
293
+		);
294
+		$details['dependencies'] = isset($details['dependencies'])
295
+			? $details['dependencies']
296
+			: [];
297
+		$details['version'] = isset($details['version'])
298
+			? $details['version']
299
+			: '';
300
+		$details['dependencies'] = ! empty($extra_dependencies)
301
+			? array_merge($details['dependencies'], (array) $extra_dependencies)
302
+			: $details['dependencies'];
303
+		return $details;
304 304
 
305
-    }
305
+	}
306 306
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -176,7 +176,7 @@
 block discarded – undo
176 176
         $version = ''
177 177
     ) {
178 178
         $dev_suffix = wp_scripts_get_suffix('dev');
179
-        $vendor_path = $this->domain->pluginUrl() . 'assets/vendor/';
179
+        $vendor_path = $this->domain->pluginUrl().'assets/vendor/';
180 180
         return $this->addJavascript(
181 181
             $handle,
182 182
             "{$vendor_path}{$handle}{$dev_suffix}.js",
Please login to merge, or discard this patch.
core/services/assets/Registry.php 2 patches
Indentation   +773 added lines, -773 removed lines patch added patch discarded remove patch
@@ -26,784 +26,784 @@
 block discarded – undo
26 26
 class Registry
27 27
 {
28 28
 
29
-    const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json';
30
-
31
-    /**
32
-     * @var AssetCollection $assets
33
-     */
34
-    protected $assets;
35
-
36
-    /**
37
-     * @var I18nRegistry
38
-     */
39
-    private $i18n_registry;
40
-
41
-    /**
42
-     * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
43
-     *
44
-     * @var array
45
-     */
46
-    protected $jsdata = array();
47
-
48
-    /**
49
-     * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
50
-     * page source.
51
-     *
52
-     * @var array
53
-     */
54
-    private $script_handles_with_data = array();
55
-
56
-
57
-    /**
58
-     * Holds the manifest data obtained from registered manifest files.
59
-     * Manifests are maps of asset chunk name to actual built asset file names.
60
-     * Shape of this array is:
61
-     * array(
62
-     *  'some_namespace_slug' => array(
63
-     *      'some_chunk_name' => array(
64
-     *          'js' => 'filename.js'
65
-     *          'css' => 'filename.js'
66
-     *      ),
67
-     *      'url_base' => 'https://baseurl.com/to/assets
68
-     *  )
69
-     * )
70
-     *
71
-     * @var array
72
-     */
73
-    private $manifest_data = array();
74
-
75
-
76
-    /**
77
-     * Holds any dependency data obtained from registered dependency map json.
78
-     * Dependency map json is generated via the @wordpress/dependency-extraction-webpack-plugin via the webpack config.
79
-     * @see https://github.com/WordPress/gutenberg/tree/master/packages/dependency-extraction-webpack-plugin
80
-     *
81
-     * @var array
82
-     */
83
-    private $dependencies_data = [];
84
-
85
-
86
-    /**
87
-     * This is a known array of possible wp css handles that correspond to what may be exposed as dependencies in our
88
-     * build process.  Currently the dependency export process in webpack does not consider css imports, so we derive
89
-     * them via the js dependencies (WP uses the same handle for both js and css). This is a list of known handles that
90
-     * are used for both js and css.
91
-     * @var array
92
-     */
93
-    private $wp_css_handle_dependencies = [
94
-        'wp-components',
95
-        'wp-block-editor',
96
-        'wp-block-library',
97
-        'wp-edit-post',
98
-        'wp-edit-widgets',
99
-        'wp-editor',
100
-        'wp-format-library',
101
-        'wp-list-reusable-blocks',
102
-        'wp-nux',
103
-    ];
104
-
105
-
106
-    /**
107
-     * Registry constructor.
108
-     * Hooking into WP actions for script registry.
109
-     *
110
-     * @param AssetCollection      $assets
111
-     * @param I18nRegistry         $i18n_registry
112
-     * @throws InvalidArgumentException
113
-     * @throws InvalidDataTypeException
114
-     * @throws InvalidInterfaceException
115
-     */
116
-    public function __construct(AssetCollection $assets, I18nRegistry $i18n_registry)
117
-    {
118
-        $this->assets = $assets;
119
-        $this->i18n_registry = $i18n_registry;
120
-        add_action('wp_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
121
-        add_action('admin_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
122
-        add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
123
-        add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
124
-        add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 4);
125
-        add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 4);
126
-        add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
127
-        add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
128
-    }
129
-
130
-
131
-    /**
132
-     * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n
133
-     * translation handling.
134
-     *
135
-     * @return I18nRegistry
136
-     */
137
-    public function getI18nRegistry()
138
-    {
139
-        return $this->i18n_registry;
140
-    }
141
-
142
-
143
-    /**
144
-     * Callback for the wp_enqueue_scripts actions used to register assets.
145
-     *
146
-     * @since 4.9.62.p
147
-     * @throws Exception
148
-     */
149
-    public function registerScriptsAndStyles()
150
-    {
151
-        try {
152
-            $this->registerScripts($this->assets->getJavascriptAssets());
153
-            $this->registerStyles($this->assets->getStylesheetAssets());
154
-        } catch (Exception $exception) {
155
-            new ExceptionStackTraceDisplay($exception);
156
-        }
157
-    }
158
-
159
-
160
-    /**
161
-     * Registers JS assets with WP core
162
-     *
163
-     * @param JavascriptAsset[] $scripts
164
-     * @throws AssetRegistrationException
165
-     * @throws InvalidDataTypeException
166
-     * @throws DomainException
167
-     * @since 4.9.62.p
168
-     */
169
-    public function registerScripts(array $scripts)
170
-    {
171
-        foreach ($scripts as $script) {
172
-            // skip to next script if this has already been done
173
-            if ($script->isRegistered()) {
174
-                continue;
175
-            }
176
-            do_action(
177
-                'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
178
-                $script
179
-            );
180
-            $registered = wp_register_script(
181
-                $script->handle(),
182
-                $script->source(),
183
-                $script->dependencies(),
184
-                $script->version(),
185
-                $script->loadInFooter()
186
-            );
187
-            if (! $registered && $this->debug()) {
188
-                throw new AssetRegistrationException($script->handle());
189
-            }
190
-            $script->setRegistered($registered);
191
-            if ($script->requiresTranslation()) {
192
-                $this->registerTranslation($script->handle());
193
-            }
194
-            do_action(
195
-                'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script',
196
-                $script
197
-            );
198
-        }
199
-    }
200
-
201
-
202
-    /**
203
-     * Registers CSS assets with WP core
204
-     *
205
-     * @param StylesheetAsset[] $styles
206
-     * @throws InvalidDataTypeException
207
-     * @throws DomainException
208
-     * @since 4.9.62.p
209
-     */
210
-    public function registerStyles(array $styles)
211
-    {
212
-        foreach ($styles as $style) {
213
-            // skip to next style if this has already been done
214
-            if ($style->isRegistered()) {
215
-                continue;
216
-            }
217
-            do_action(
218
-                'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style',
219
-                $style
220
-            );
221
-            wp_register_style(
222
-                $style->handle(),
223
-                $style->source(),
224
-                $style->dependencies(),
225
-                $style->version(),
226
-                $style->media()
227
-            );
228
-            $style->setRegistered();
229
-            do_action(
230
-                'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style',
231
-                $style
232
-            );
233
-        }
234
-    }
235
-
236
-
237
-    /**
238
-     * Call back for the script print in frontend and backend.
239
-     * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
240
-     *
241
-     * @since 4.9.31.rc.015
242
-     */
243
-    public function enqueueData()
244
-    {
245
-        $this->removeAlreadyRegisteredDataForScriptHandles();
246
-        wp_add_inline_script(
247
-            'eejs-core',
248
-            'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)),
249
-            'before'
250
-        );
251
-        $scripts = $this->assets->getJavascriptAssetsWithData();
252
-        foreach ($scripts as $script) {
253
-            $this->addRegisteredScriptHandlesWithData($script->handle());
254
-            if ($script->hasInlineDataCallback()) {
255
-                $localize = $script->inlineDataCallback();
256
-                $localize();
257
-            }
258
-        }
259
-    }
260
-
261
-
262
-    /**
263
-     * Used to add data to eejs.data object.
264
-     * Note:  Overriding existing data is not allowed.
265
-     * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
266
-     * If the data you add is something like this:
267
-     *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
268
-     * It will be exposed in the page source as:
269
-     *  eejs.data.my_plugin_data.foo == gar
270
-     *
271
-     * @param string       $key   Key used to access your data
272
-     * @param string|array $value Value to attach to key
273
-     * @throws InvalidArgumentException
274
-     */
275
-    public function addData($key, $value)
276
-    {
277
-        if ($this->verifyDataNotExisting($key)) {
278
-            $this->jsdata[ $key ] = $value;
279
-        }
280
-    }
281
-
282
-
283
-    /**
284
-     * Similar to addData except this allows for users to push values to an existing key where the values on key are
285
-     * elements in an array.
286
-     *
287
-     * When you use this method, the value you include will be merged with the array on $key.
288
-     * So if the $key was 'test' and you added a value of ['my_data'] then it would be represented in the javascript
289
-     * object like this, eejs.data.test = [ my_data,
290
-     * ]
291
-     * If there has already been a scalar value attached to the data object given key (via addData for instance), then
292
-     * this will throw an exception.
293
-     *
294
-     * Caution: Only add data using this method if you are okay with the potential for additional data added on the same
295
-     * key potentially overriding the existing data on merge (specifically with associative arrays).
296
-     *
297
-     * @param string       $key   Key to attach data to.
298
-     * @param string|array $value Value being registered.
299
-     * @throws InvalidArgumentException
300
-     */
301
-    public function pushData($key, $value)
302
-    {
303
-        if (isset($this->jsdata[ $key ])
304
-            && ! is_array($this->jsdata[ $key ])
305
-        ) {
306
-            if (! $this->debug()) {
307
-                return;
308
-            }
309
-            throw new InvalidArgumentException(
310
-                sprintf(
311
-                    __(
312
-                        'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
29
+	const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json';
30
+
31
+	/**
32
+	 * @var AssetCollection $assets
33
+	 */
34
+	protected $assets;
35
+
36
+	/**
37
+	 * @var I18nRegistry
38
+	 */
39
+	private $i18n_registry;
40
+
41
+	/**
42
+	 * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
43
+	 *
44
+	 * @var array
45
+	 */
46
+	protected $jsdata = array();
47
+
48
+	/**
49
+	 * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
50
+	 * page source.
51
+	 *
52
+	 * @var array
53
+	 */
54
+	private $script_handles_with_data = array();
55
+
56
+
57
+	/**
58
+	 * Holds the manifest data obtained from registered manifest files.
59
+	 * Manifests are maps of asset chunk name to actual built asset file names.
60
+	 * Shape of this array is:
61
+	 * array(
62
+	 *  'some_namespace_slug' => array(
63
+	 *      'some_chunk_name' => array(
64
+	 *          'js' => 'filename.js'
65
+	 *          'css' => 'filename.js'
66
+	 *      ),
67
+	 *      'url_base' => 'https://baseurl.com/to/assets
68
+	 *  )
69
+	 * )
70
+	 *
71
+	 * @var array
72
+	 */
73
+	private $manifest_data = array();
74
+
75
+
76
+	/**
77
+	 * Holds any dependency data obtained from registered dependency map json.
78
+	 * Dependency map json is generated via the @wordpress/dependency-extraction-webpack-plugin via the webpack config.
79
+	 * @see https://github.com/WordPress/gutenberg/tree/master/packages/dependency-extraction-webpack-plugin
80
+	 *
81
+	 * @var array
82
+	 */
83
+	private $dependencies_data = [];
84
+
85
+
86
+	/**
87
+	 * This is a known array of possible wp css handles that correspond to what may be exposed as dependencies in our
88
+	 * build process.  Currently the dependency export process in webpack does not consider css imports, so we derive
89
+	 * them via the js dependencies (WP uses the same handle for both js and css). This is a list of known handles that
90
+	 * are used for both js and css.
91
+	 * @var array
92
+	 */
93
+	private $wp_css_handle_dependencies = [
94
+		'wp-components',
95
+		'wp-block-editor',
96
+		'wp-block-library',
97
+		'wp-edit-post',
98
+		'wp-edit-widgets',
99
+		'wp-editor',
100
+		'wp-format-library',
101
+		'wp-list-reusable-blocks',
102
+		'wp-nux',
103
+	];
104
+
105
+
106
+	/**
107
+	 * Registry constructor.
108
+	 * Hooking into WP actions for script registry.
109
+	 *
110
+	 * @param AssetCollection      $assets
111
+	 * @param I18nRegistry         $i18n_registry
112
+	 * @throws InvalidArgumentException
113
+	 * @throws InvalidDataTypeException
114
+	 * @throws InvalidInterfaceException
115
+	 */
116
+	public function __construct(AssetCollection $assets, I18nRegistry $i18n_registry)
117
+	{
118
+		$this->assets = $assets;
119
+		$this->i18n_registry = $i18n_registry;
120
+		add_action('wp_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
121
+		add_action('admin_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
122
+		add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
123
+		add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
124
+		add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 4);
125
+		add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 4);
126
+		add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
127
+		add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
128
+	}
129
+
130
+
131
+	/**
132
+	 * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n
133
+	 * translation handling.
134
+	 *
135
+	 * @return I18nRegistry
136
+	 */
137
+	public function getI18nRegistry()
138
+	{
139
+		return $this->i18n_registry;
140
+	}
141
+
142
+
143
+	/**
144
+	 * Callback for the wp_enqueue_scripts actions used to register assets.
145
+	 *
146
+	 * @since 4.9.62.p
147
+	 * @throws Exception
148
+	 */
149
+	public function registerScriptsAndStyles()
150
+	{
151
+		try {
152
+			$this->registerScripts($this->assets->getJavascriptAssets());
153
+			$this->registerStyles($this->assets->getStylesheetAssets());
154
+		} catch (Exception $exception) {
155
+			new ExceptionStackTraceDisplay($exception);
156
+		}
157
+	}
158
+
159
+
160
+	/**
161
+	 * Registers JS assets with WP core
162
+	 *
163
+	 * @param JavascriptAsset[] $scripts
164
+	 * @throws AssetRegistrationException
165
+	 * @throws InvalidDataTypeException
166
+	 * @throws DomainException
167
+	 * @since 4.9.62.p
168
+	 */
169
+	public function registerScripts(array $scripts)
170
+	{
171
+		foreach ($scripts as $script) {
172
+			// skip to next script if this has already been done
173
+			if ($script->isRegistered()) {
174
+				continue;
175
+			}
176
+			do_action(
177
+				'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
178
+				$script
179
+			);
180
+			$registered = wp_register_script(
181
+				$script->handle(),
182
+				$script->source(),
183
+				$script->dependencies(),
184
+				$script->version(),
185
+				$script->loadInFooter()
186
+			);
187
+			if (! $registered && $this->debug()) {
188
+				throw new AssetRegistrationException($script->handle());
189
+			}
190
+			$script->setRegistered($registered);
191
+			if ($script->requiresTranslation()) {
192
+				$this->registerTranslation($script->handle());
193
+			}
194
+			do_action(
195
+				'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script',
196
+				$script
197
+			);
198
+		}
199
+	}
200
+
201
+
202
+	/**
203
+	 * Registers CSS assets with WP core
204
+	 *
205
+	 * @param StylesheetAsset[] $styles
206
+	 * @throws InvalidDataTypeException
207
+	 * @throws DomainException
208
+	 * @since 4.9.62.p
209
+	 */
210
+	public function registerStyles(array $styles)
211
+	{
212
+		foreach ($styles as $style) {
213
+			// skip to next style if this has already been done
214
+			if ($style->isRegistered()) {
215
+				continue;
216
+			}
217
+			do_action(
218
+				'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style',
219
+				$style
220
+			);
221
+			wp_register_style(
222
+				$style->handle(),
223
+				$style->source(),
224
+				$style->dependencies(),
225
+				$style->version(),
226
+				$style->media()
227
+			);
228
+			$style->setRegistered();
229
+			do_action(
230
+				'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style',
231
+				$style
232
+			);
233
+		}
234
+	}
235
+
236
+
237
+	/**
238
+	 * Call back for the script print in frontend and backend.
239
+	 * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
240
+	 *
241
+	 * @since 4.9.31.rc.015
242
+	 */
243
+	public function enqueueData()
244
+	{
245
+		$this->removeAlreadyRegisteredDataForScriptHandles();
246
+		wp_add_inline_script(
247
+			'eejs-core',
248
+			'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)),
249
+			'before'
250
+		);
251
+		$scripts = $this->assets->getJavascriptAssetsWithData();
252
+		foreach ($scripts as $script) {
253
+			$this->addRegisteredScriptHandlesWithData($script->handle());
254
+			if ($script->hasInlineDataCallback()) {
255
+				$localize = $script->inlineDataCallback();
256
+				$localize();
257
+			}
258
+		}
259
+	}
260
+
261
+
262
+	/**
263
+	 * Used to add data to eejs.data object.
264
+	 * Note:  Overriding existing data is not allowed.
265
+	 * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
266
+	 * If the data you add is something like this:
267
+	 *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
268
+	 * It will be exposed in the page source as:
269
+	 *  eejs.data.my_plugin_data.foo == gar
270
+	 *
271
+	 * @param string       $key   Key used to access your data
272
+	 * @param string|array $value Value to attach to key
273
+	 * @throws InvalidArgumentException
274
+	 */
275
+	public function addData($key, $value)
276
+	{
277
+		if ($this->verifyDataNotExisting($key)) {
278
+			$this->jsdata[ $key ] = $value;
279
+		}
280
+	}
281
+
282
+
283
+	/**
284
+	 * Similar to addData except this allows for users to push values to an existing key where the values on key are
285
+	 * elements in an array.
286
+	 *
287
+	 * When you use this method, the value you include will be merged with the array on $key.
288
+	 * So if the $key was 'test' and you added a value of ['my_data'] then it would be represented in the javascript
289
+	 * object like this, eejs.data.test = [ my_data,
290
+	 * ]
291
+	 * If there has already been a scalar value attached to the data object given key (via addData for instance), then
292
+	 * this will throw an exception.
293
+	 *
294
+	 * Caution: Only add data using this method if you are okay with the potential for additional data added on the same
295
+	 * key potentially overriding the existing data on merge (specifically with associative arrays).
296
+	 *
297
+	 * @param string       $key   Key to attach data to.
298
+	 * @param string|array $value Value being registered.
299
+	 * @throws InvalidArgumentException
300
+	 */
301
+	public function pushData($key, $value)
302
+	{
303
+		if (isset($this->jsdata[ $key ])
304
+			&& ! is_array($this->jsdata[ $key ])
305
+		) {
306
+			if (! $this->debug()) {
307
+				return;
308
+			}
309
+			throw new InvalidArgumentException(
310
+				sprintf(
311
+					__(
312
+						'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
313 313
                          push values to this data element when it is an array.',
314
-                        'event_espresso'
315
-                    ),
316
-                    $key,
317
-                    __METHOD__
318
-                )
319
-            );
320
-        }
321
-        if ( ! isset( $this->jsdata[ $key ] ) ) {
322
-            $this->jsdata[ $key ] = is_array($value) ? $value : [$value];
323
-        } else {
324
-            $this->jsdata[ $key ] = array_merge( $this->jsdata[$key], (array) $value);
325
-        }
326
-    }
327
-
328
-
329
-    /**
330
-     * Used to set content used by javascript for a template.
331
-     * Note: Overrides of existing registered templates are not allowed.
332
-     *
333
-     * @param string $template_reference
334
-     * @param string $template_content
335
-     * @throws InvalidArgumentException
336
-     */
337
-    public function addTemplate($template_reference, $template_content)
338
-    {
339
-        if (! isset($this->jsdata['templates'])) {
340
-            $this->jsdata['templates'] = array();
341
-        }
342
-        //no overrides allowed.
343
-        if (isset($this->jsdata['templates'][ $template_reference ])) {
344
-            if (! $this->debug()) {
345
-                return;
346
-            }
347
-            throw new InvalidArgumentException(
348
-                sprintf(
349
-                    __(
350
-                        'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
351
-                        'event_espresso'
352
-                    ),
353
-                    $template_reference
354
-                )
355
-            );
356
-        }
357
-        $this->jsdata['templates'][ $template_reference ] = $template_content;
358
-    }
359
-
360
-
361
-    /**
362
-     * Retrieve the template content already registered for the given reference.
363
-     *
364
-     * @param string $template_reference
365
-     * @return string
366
-     */
367
-    public function getTemplate($template_reference)
368
-    {
369
-        return isset($this->jsdata['templates'][ $template_reference ])
370
-            ? $this->jsdata['templates'][ $template_reference ]
371
-            : '';
372
-    }
373
-
374
-
375
-    /**
376
-     * Retrieve registered data.
377
-     *
378
-     * @param string $key Name of key to attach data to.
379
-     * @return mixed                If there is no for the given key, then false is returned.
380
-     */
381
-    public function getData($key)
382
-    {
383
-        return isset($this->jsdata[ $key ])
384
-            ? $this->jsdata[ $key ]
385
-            : false;
386
-    }
387
-
388
-
389
-    /**
390
-     * Verifies whether the given data exists already on the jsdata array.
391
-     * Overriding data is not allowed.
392
-     *
393
-     * @param string $key Index for data.
394
-     * @return bool        If valid then return true.
395
-     * @throws InvalidArgumentException if data already exists.
396
-     */
397
-    protected function verifyDataNotExisting($key)
398
-    {
399
-        if (isset($this->jsdata[ $key ])) {
400
-            if (! $this->debug()) {
401
-                return false;
402
-            }
403
-            if (is_array($this->jsdata[ $key ])) {
404
-                throw new InvalidArgumentException(
405
-                    sprintf(
406
-                        __(
407
-                            'The value for %1$s already exists in the Registry::eejs object.
314
+						'event_espresso'
315
+					),
316
+					$key,
317
+					__METHOD__
318
+				)
319
+			);
320
+		}
321
+		if ( ! isset( $this->jsdata[ $key ] ) ) {
322
+			$this->jsdata[ $key ] = is_array($value) ? $value : [$value];
323
+		} else {
324
+			$this->jsdata[ $key ] = array_merge( $this->jsdata[$key], (array) $value);
325
+		}
326
+	}
327
+
328
+
329
+	/**
330
+	 * Used to set content used by javascript for a template.
331
+	 * Note: Overrides of existing registered templates are not allowed.
332
+	 *
333
+	 * @param string $template_reference
334
+	 * @param string $template_content
335
+	 * @throws InvalidArgumentException
336
+	 */
337
+	public function addTemplate($template_reference, $template_content)
338
+	{
339
+		if (! isset($this->jsdata['templates'])) {
340
+			$this->jsdata['templates'] = array();
341
+		}
342
+		//no overrides allowed.
343
+		if (isset($this->jsdata['templates'][ $template_reference ])) {
344
+			if (! $this->debug()) {
345
+				return;
346
+			}
347
+			throw new InvalidArgumentException(
348
+				sprintf(
349
+					__(
350
+						'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
351
+						'event_espresso'
352
+					),
353
+					$template_reference
354
+				)
355
+			);
356
+		}
357
+		$this->jsdata['templates'][ $template_reference ] = $template_content;
358
+	}
359
+
360
+
361
+	/**
362
+	 * Retrieve the template content already registered for the given reference.
363
+	 *
364
+	 * @param string $template_reference
365
+	 * @return string
366
+	 */
367
+	public function getTemplate($template_reference)
368
+	{
369
+		return isset($this->jsdata['templates'][ $template_reference ])
370
+			? $this->jsdata['templates'][ $template_reference ]
371
+			: '';
372
+	}
373
+
374
+
375
+	/**
376
+	 * Retrieve registered data.
377
+	 *
378
+	 * @param string $key Name of key to attach data to.
379
+	 * @return mixed                If there is no for the given key, then false is returned.
380
+	 */
381
+	public function getData($key)
382
+	{
383
+		return isset($this->jsdata[ $key ])
384
+			? $this->jsdata[ $key ]
385
+			: false;
386
+	}
387
+
388
+
389
+	/**
390
+	 * Verifies whether the given data exists already on the jsdata array.
391
+	 * Overriding data is not allowed.
392
+	 *
393
+	 * @param string $key Index for data.
394
+	 * @return bool        If valid then return true.
395
+	 * @throws InvalidArgumentException if data already exists.
396
+	 */
397
+	protected function verifyDataNotExisting($key)
398
+	{
399
+		if (isset($this->jsdata[ $key ])) {
400
+			if (! $this->debug()) {
401
+				return false;
402
+			}
403
+			if (is_array($this->jsdata[ $key ])) {
404
+				throw new InvalidArgumentException(
405
+					sprintf(
406
+						__(
407
+							'The value for %1$s already exists in the Registry::eejs object.
408 408
                             Overrides are not allowed. Since the value of this data is an array, you may want to use the
409 409
                             %2$s method to push your value to the array.',
410
-                            'event_espresso'
411
-                        ),
412
-                        $key,
413
-                        'pushData()'
414
-                    )
415
-                );
416
-            }
417
-            throw new InvalidArgumentException(
418
-                sprintf(
419
-                    __(
420
-                        'The value for %1$s already exists in the Registry::eejs object. Overrides are not
410
+							'event_espresso'
411
+						),
412
+						$key,
413
+						'pushData()'
414
+					)
415
+				);
416
+			}
417
+			throw new InvalidArgumentException(
418
+				sprintf(
419
+					__(
420
+						'The value for %1$s already exists in the Registry::eejs object. Overrides are not
421 421
                         allowed.  Consider attaching your value to a different key',
422
-                        'event_espresso'
423
-                    ),
424
-                    $key
425
-                )
426
-            );
427
-        }
428
-        return true;
429
-    }
430
-
431
-
432
-    /**
433
-     * Get the actual asset path for asset manifests.
434
-     * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
435
-     *
436
-     * @param string $namespace  The namespace associated with the manifest file hosting the map of chunk_name to actual
437
-     *                           asset file location.
438
-     * @param string $chunk_name
439
-     * @param string $asset_type
440
-     * @return string
441
-     * @since 4.9.59.p
442
-     */
443
-    public function getAssetUrl($namespace, $chunk_name, $asset_type)
444
-    {
445
-        $url = isset(
446
-            $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ],
447
-            $this->manifest_data[ $namespace ]['url_base']
448
-        )
449
-            ? $this->manifest_data[ $namespace ]['url_base']
450
-              . $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ]
451
-            : $chunk_name;
452
-
453
-        return apply_filters(
454
-            'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl',
455
-            $url,
456
-            $namespace,
457
-            $chunk_name,
458
-            $asset_type
459
-        );
460
-    }
461
-
462
-
463
-
464
-    /**
465
-     * Return the url to a js file for the given namespace and chunk name.
466
-     *
467
-     * @param string $namespace
468
-     * @param string $chunk_name
469
-     * @return string
470
-     */
471
-    public function getJsUrl($namespace, $chunk_name)
472
-    {
473
-        return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS);
474
-    }
475
-
476
-
477
-    /**
478
-     * Return the url to a css file for the given namespace and chunk name.
479
-     *
480
-     * @param string $namespace
481
-     * @param string $chunk_name
482
-     * @return string
483
-     */
484
-    public function getCssUrl($namespace, $chunk_name)
485
-    {
486
-        return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS);
487
-    }
488
-
489
-
490
-    /**
491
-     * Return the dependencies array and version string for a given asset $chunk_name
492
-     *
493
-     * @param string $namespace
494
-     * @param string $chunk_name
495
-     * @param string $asset_type
496
-     * @return array
497
-     * @since 4.9.82.p
498
-     */
499
-    private function getDetailsForAsset($namespace, $chunk_name, $asset_type)
500
-    {
501
-        $asset_index = $chunk_name . '.' . $asset_type;
502
-        if (! isset( $this->dependencies_data[ $namespace ][ $asset_index ])) {
503
-            $path = isset($this->manifest_data[ $namespace ]['path'])
504
-                ? $this->manifest_data[ $namespace ]['path']
505
-                : '';
506
-            $dependencies_index = $chunk_name . '.' . Asset::TYPE_PHP;
507
-            $file_path = isset($this->manifest_data[ $namespace ][ $dependencies_index ])
508
-                ? $path . $this->manifest_data[ $namespace ][ $dependencies_index ]
509
-                :
510
-                '';
511
-            $this->dependencies_data[ $namespace ][ $asset_index ] = $file_path !== '' && file_exists($file_path)
512
-                ? $this->getDetailsForAssetType($namespace, $asset_type, $file_path, $chunk_name)
513
-                : [];
514
-        }
515
-        $details = $this->dependencies_data[ $namespace ][ $asset_index ];
516
-        return $details;
517
-    }
518
-
519
-
520
-    /**
521
-     * Return dependencies array and version string according to asset type.
522
-     * For css assets, this filters the auto generated dependencies by css type.
523
-     *
524
-     * @param string $namespace
525
-     * @param string $asset_type
526
-     * @param string $file_path
527
-     * @param string $chunk_name
528
-     * @return array
529
-     * @since 4.9.82.p
530
-     */
531
-    private function getDetailsForAssetType($namespace, $asset_type, $file_path, $chunk_name)
532
-    {
533
-        // $asset_dependencies = json_decode(file_get_contents($file_path), true);
534
-        $asset_details = require($file_path);
535
-        $asset_details['dependencies'] = isset($asset_details['dependencies'])
536
-            ? $asset_details['dependencies']
537
-            : [];
538
-        $asset_details['version'] = isset($asset_details['version'])
539
-            ? $asset_details['version']
540
-            : '';
541
-        if ($asset_type === Asset::TYPE_JS) {
542
-            $asset_details['dependencies'] =  $chunk_name === 'eejs-core'
543
-                ? $asset_details['dependencies']
544
-                : $asset_details['dependencies'] + [ CoreAssetManager::JS_HANDLE_JS_CORE ];
545
-            return $asset_details;
546
-        }
547
-        // for css we need to make sure there is actually a css file related to this chunk.
548
-        if (isset($this->manifest_data[ $namespace ])) {
549
-            // array of css chunk files for ee.
550
-            $css_chunks = array_map(
551
-                static function ($value) {
552
-                    return str_replace('.css', '', $value);
553
-                },
554
-                array_filter(
555
-                    array_keys($this->manifest_data[ $namespace ]),
556
-                    static function ($value) {
557
-                        return strpos($value, '.css') !== false;
558
-                    }
559
-                )
560
-            );
561
-            // add known wp chunks with css
562
-            $css_chunks = array_merge( $css_chunks, $this->wp_css_handle_dependencies);
563
-            // flip for easier search
564
-            $css_chunks = array_flip($css_chunks);
565
-            // now let's filter the dependencies for the incoming chunk to actual chunks that have styles
566
-            $asset_details['dependencies'] = array_filter(
567
-                $asset_details['dependencies'],
568
-                static function ($chunk_name) use ($css_chunks) {
569
-                    return isset($css_chunks[ $chunk_name ]);
570
-                }
571
-            );
572
-            return $asset_details;
573
-        }
574
-        return ['dependencies' => [], 'version' => ''];
575
-    }
576
-
577
-
578
-    /**
579
-     * Get the dependencies array and version string for the given js asset chunk name
580
-     *
581
-     * @param string $namespace
582
-     * @param string $chunk_name
583
-     * @return array
584
-     * @since $VID:$
585
-     */
586
-    public function getJsAssetDetails($namespace, $chunk_name)
587
-    {
588
-        return $this->getDetailsForAsset($namespace, $chunk_name, Asset::TYPE_JS);
589
-    }
590
-
591
-
592
-    /**
593
-     * Get the dependencies array and version string for the given css asset chunk name
594
-     *
595
-     * @param string $namespace
596
-     * @param string $chunk_name
597
-     * @return array
598
-     * @since $VID:$
599
-     */
600
-    public function getCssAssetDetails($namespace, $chunk_name)
601
-    {
602
-        return $this->getDetailsForAsset($namespace, $chunk_name, Asset::TYPE_CSS);
603
-    }
604
-
605
-
606
-    /**
607
-     * @since 4.9.62.p
608
-     * @throws InvalidArgumentException
609
-     * @throws InvalidFilePathException
610
-     */
611
-    public function registerManifestFiles()
612
-    {
613
-        $manifest_files = $this->assets->getManifestFiles();
614
-        foreach ($manifest_files as $manifest_file) {
615
-            $this->registerManifestFile(
616
-                $manifest_file->assetNamespace(),
617
-                $manifest_file->urlBase(),
618
-                $manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST,
619
-                $manifest_file->filepath()
620
-            );
621
-        }
622
-    }
623
-
624
-
625
-    /**
626
-     * Used to register a js/css manifest file with the registered_manifest_files property.
627
-     *
628
-     * @param string $namespace     Provided to associate the manifest file with a specific namespace.
629
-     * @param string $url_base      The url base for the manifest file location.
630
-     * @param string $manifest_file The absolute path to the manifest file.
631
-     * @param string $manifest_file_path  The path to the folder containing the manifest file. If not provided will be
632
-     *                                    default to `plugin_root/assets/dist`.
633
-     * @throws InvalidArgumentException
634
-     * @throws InvalidFilePathException
635
-     * @since 4.9.59.p
636
-     */
637
-    public function registerManifestFile($namespace, $url_base, $manifest_file, $manifest_file_path = '')
638
-    {
639
-        if (isset($this->manifest_data[ $namespace ])) {
640
-            if (! $this->debug()) {
641
-                return;
642
-            }
643
-            throw new InvalidArgumentException(
644
-                sprintf(
645
-                    esc_html__(
646
-                        'The namespace for this manifest file has already been registered, choose a namespace other than %s',
647
-                        'event_espresso'
648
-                    ),
649
-                    $namespace
650
-                )
651
-            );
652
-        }
653
-        if (filter_var($url_base, FILTER_VALIDATE_URL) === false) {
654
-            if (is_admin()) {
655
-                EE_Error::add_error(
656
-                    sprintf(
657
-                        esc_html__(
658
-                            'The url given for %1$s assets is invalid.  The url provided was: "%2$s". This usually happens when another plugin or theme on a site is using the "%3$s" filter or has an invalid url set for the "%4$s" constant',
659
-                            'event_espresso'
660
-                        ),
661
-                        'Event Espresso',
662
-                        $url_base,
663
-                        'plugins_url',
664
-                        'WP_PLUGIN_URL'
665
-                    ),
666
-                    __FILE__,
667
-                    __FUNCTION__,
668
-                    __LINE__
669
-                );
670
-            }
671
-            return;
672
-        }
673
-        $this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file);
674
-        if (! isset($this->manifest_data[ $namespace ]['url_base'])) {
675
-            $this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base);
676
-        }
677
-        if (! isset($this->manifest_data[ $namespace ]['path'])) {
678
-            $this->manifest_data[ $namespace ]['path'] = $manifest_file_path;
679
-        }
680
-    }
681
-
682
-
683
-    /**
684
-     * Decodes json from the provided manifest file.
685
-     *
686
-     * @since 4.9.59.p
687
-     * @param string $manifest_file Path to manifest file.
688
-     * @return array
689
-     * @throws InvalidFilePathException
690
-     */
691
-    private function decodeManifestFile($manifest_file)
692
-    {
693
-        if (! file_exists($manifest_file)) {
694
-            throw new InvalidFilePathException($manifest_file);
695
-        }
696
-        return json_decode(file_get_contents($manifest_file), true);
697
-    }
698
-
699
-
700
-    /**
701
-     * This is used to set registered script handles that have data.
702
-     *
703
-     * @param string $script_handle
704
-     */
705
-    private function addRegisteredScriptHandlesWithData($script_handle)
706
-    {
707
-        $this->script_handles_with_data[ $script_handle ] = $script_handle;
708
-    }
709
-
710
-
711
-    /**i
422
+						'event_espresso'
423
+					),
424
+					$key
425
+				)
426
+			);
427
+		}
428
+		return true;
429
+	}
430
+
431
+
432
+	/**
433
+	 * Get the actual asset path for asset manifests.
434
+	 * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
435
+	 *
436
+	 * @param string $namespace  The namespace associated with the manifest file hosting the map of chunk_name to actual
437
+	 *                           asset file location.
438
+	 * @param string $chunk_name
439
+	 * @param string $asset_type
440
+	 * @return string
441
+	 * @since 4.9.59.p
442
+	 */
443
+	public function getAssetUrl($namespace, $chunk_name, $asset_type)
444
+	{
445
+		$url = isset(
446
+			$this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ],
447
+			$this->manifest_data[ $namespace ]['url_base']
448
+		)
449
+			? $this->manifest_data[ $namespace ]['url_base']
450
+			  . $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ]
451
+			: $chunk_name;
452
+
453
+		return apply_filters(
454
+			'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl',
455
+			$url,
456
+			$namespace,
457
+			$chunk_name,
458
+			$asset_type
459
+		);
460
+	}
461
+
462
+
463
+
464
+	/**
465
+	 * Return the url to a js file for the given namespace and chunk name.
466
+	 *
467
+	 * @param string $namespace
468
+	 * @param string $chunk_name
469
+	 * @return string
470
+	 */
471
+	public function getJsUrl($namespace, $chunk_name)
472
+	{
473
+		return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS);
474
+	}
475
+
476
+
477
+	/**
478
+	 * Return the url to a css file for the given namespace and chunk name.
479
+	 *
480
+	 * @param string $namespace
481
+	 * @param string $chunk_name
482
+	 * @return string
483
+	 */
484
+	public function getCssUrl($namespace, $chunk_name)
485
+	{
486
+		return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS);
487
+	}
488
+
489
+
490
+	/**
491
+	 * Return the dependencies array and version string for a given asset $chunk_name
492
+	 *
493
+	 * @param string $namespace
494
+	 * @param string $chunk_name
495
+	 * @param string $asset_type
496
+	 * @return array
497
+	 * @since 4.9.82.p
498
+	 */
499
+	private function getDetailsForAsset($namespace, $chunk_name, $asset_type)
500
+	{
501
+		$asset_index = $chunk_name . '.' . $asset_type;
502
+		if (! isset( $this->dependencies_data[ $namespace ][ $asset_index ])) {
503
+			$path = isset($this->manifest_data[ $namespace ]['path'])
504
+				? $this->manifest_data[ $namespace ]['path']
505
+				: '';
506
+			$dependencies_index = $chunk_name . '.' . Asset::TYPE_PHP;
507
+			$file_path = isset($this->manifest_data[ $namespace ][ $dependencies_index ])
508
+				? $path . $this->manifest_data[ $namespace ][ $dependencies_index ]
509
+				:
510
+				'';
511
+			$this->dependencies_data[ $namespace ][ $asset_index ] = $file_path !== '' && file_exists($file_path)
512
+				? $this->getDetailsForAssetType($namespace, $asset_type, $file_path, $chunk_name)
513
+				: [];
514
+		}
515
+		$details = $this->dependencies_data[ $namespace ][ $asset_index ];
516
+		return $details;
517
+	}
518
+
519
+
520
+	/**
521
+	 * Return dependencies array and version string according to asset type.
522
+	 * For css assets, this filters the auto generated dependencies by css type.
523
+	 *
524
+	 * @param string $namespace
525
+	 * @param string $asset_type
526
+	 * @param string $file_path
527
+	 * @param string $chunk_name
528
+	 * @return array
529
+	 * @since 4.9.82.p
530
+	 */
531
+	private function getDetailsForAssetType($namespace, $asset_type, $file_path, $chunk_name)
532
+	{
533
+		// $asset_dependencies = json_decode(file_get_contents($file_path), true);
534
+		$asset_details = require($file_path);
535
+		$asset_details['dependencies'] = isset($asset_details['dependencies'])
536
+			? $asset_details['dependencies']
537
+			: [];
538
+		$asset_details['version'] = isset($asset_details['version'])
539
+			? $asset_details['version']
540
+			: '';
541
+		if ($asset_type === Asset::TYPE_JS) {
542
+			$asset_details['dependencies'] =  $chunk_name === 'eejs-core'
543
+				? $asset_details['dependencies']
544
+				: $asset_details['dependencies'] + [ CoreAssetManager::JS_HANDLE_JS_CORE ];
545
+			return $asset_details;
546
+		}
547
+		// for css we need to make sure there is actually a css file related to this chunk.
548
+		if (isset($this->manifest_data[ $namespace ])) {
549
+			// array of css chunk files for ee.
550
+			$css_chunks = array_map(
551
+				static function ($value) {
552
+					return str_replace('.css', '', $value);
553
+				},
554
+				array_filter(
555
+					array_keys($this->manifest_data[ $namespace ]),
556
+					static function ($value) {
557
+						return strpos($value, '.css') !== false;
558
+					}
559
+				)
560
+			);
561
+			// add known wp chunks with css
562
+			$css_chunks = array_merge( $css_chunks, $this->wp_css_handle_dependencies);
563
+			// flip for easier search
564
+			$css_chunks = array_flip($css_chunks);
565
+			// now let's filter the dependencies for the incoming chunk to actual chunks that have styles
566
+			$asset_details['dependencies'] = array_filter(
567
+				$asset_details['dependencies'],
568
+				static function ($chunk_name) use ($css_chunks) {
569
+					return isset($css_chunks[ $chunk_name ]);
570
+				}
571
+			);
572
+			return $asset_details;
573
+		}
574
+		return ['dependencies' => [], 'version' => ''];
575
+	}
576
+
577
+
578
+	/**
579
+	 * Get the dependencies array and version string for the given js asset chunk name
580
+	 *
581
+	 * @param string $namespace
582
+	 * @param string $chunk_name
583
+	 * @return array
584
+	 * @since $VID:$
585
+	 */
586
+	public function getJsAssetDetails($namespace, $chunk_name)
587
+	{
588
+		return $this->getDetailsForAsset($namespace, $chunk_name, Asset::TYPE_JS);
589
+	}
590
+
591
+
592
+	/**
593
+	 * Get the dependencies array and version string for the given css asset chunk name
594
+	 *
595
+	 * @param string $namespace
596
+	 * @param string $chunk_name
597
+	 * @return array
598
+	 * @since $VID:$
599
+	 */
600
+	public function getCssAssetDetails($namespace, $chunk_name)
601
+	{
602
+		return $this->getDetailsForAsset($namespace, $chunk_name, Asset::TYPE_CSS);
603
+	}
604
+
605
+
606
+	/**
607
+	 * @since 4.9.62.p
608
+	 * @throws InvalidArgumentException
609
+	 * @throws InvalidFilePathException
610
+	 */
611
+	public function registerManifestFiles()
612
+	{
613
+		$manifest_files = $this->assets->getManifestFiles();
614
+		foreach ($manifest_files as $manifest_file) {
615
+			$this->registerManifestFile(
616
+				$manifest_file->assetNamespace(),
617
+				$manifest_file->urlBase(),
618
+				$manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST,
619
+				$manifest_file->filepath()
620
+			);
621
+		}
622
+	}
623
+
624
+
625
+	/**
626
+	 * Used to register a js/css manifest file with the registered_manifest_files property.
627
+	 *
628
+	 * @param string $namespace     Provided to associate the manifest file with a specific namespace.
629
+	 * @param string $url_base      The url base for the manifest file location.
630
+	 * @param string $manifest_file The absolute path to the manifest file.
631
+	 * @param string $manifest_file_path  The path to the folder containing the manifest file. If not provided will be
632
+	 *                                    default to `plugin_root/assets/dist`.
633
+	 * @throws InvalidArgumentException
634
+	 * @throws InvalidFilePathException
635
+	 * @since 4.9.59.p
636
+	 */
637
+	public function registerManifestFile($namespace, $url_base, $manifest_file, $manifest_file_path = '')
638
+	{
639
+		if (isset($this->manifest_data[ $namespace ])) {
640
+			if (! $this->debug()) {
641
+				return;
642
+			}
643
+			throw new InvalidArgumentException(
644
+				sprintf(
645
+					esc_html__(
646
+						'The namespace for this manifest file has already been registered, choose a namespace other than %s',
647
+						'event_espresso'
648
+					),
649
+					$namespace
650
+				)
651
+			);
652
+		}
653
+		if (filter_var($url_base, FILTER_VALIDATE_URL) === false) {
654
+			if (is_admin()) {
655
+				EE_Error::add_error(
656
+					sprintf(
657
+						esc_html__(
658
+							'The url given for %1$s assets is invalid.  The url provided was: "%2$s". This usually happens when another plugin or theme on a site is using the "%3$s" filter or has an invalid url set for the "%4$s" constant',
659
+							'event_espresso'
660
+						),
661
+						'Event Espresso',
662
+						$url_base,
663
+						'plugins_url',
664
+						'WP_PLUGIN_URL'
665
+					),
666
+					__FILE__,
667
+					__FUNCTION__,
668
+					__LINE__
669
+				);
670
+			}
671
+			return;
672
+		}
673
+		$this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file);
674
+		if (! isset($this->manifest_data[ $namespace ]['url_base'])) {
675
+			$this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base);
676
+		}
677
+		if (! isset($this->manifest_data[ $namespace ]['path'])) {
678
+			$this->manifest_data[ $namespace ]['path'] = $manifest_file_path;
679
+		}
680
+	}
681
+
682
+
683
+	/**
684
+	 * Decodes json from the provided manifest file.
685
+	 *
686
+	 * @since 4.9.59.p
687
+	 * @param string $manifest_file Path to manifest file.
688
+	 * @return array
689
+	 * @throws InvalidFilePathException
690
+	 */
691
+	private function decodeManifestFile($manifest_file)
692
+	{
693
+		if (! file_exists($manifest_file)) {
694
+			throw new InvalidFilePathException($manifest_file);
695
+		}
696
+		return json_decode(file_get_contents($manifest_file), true);
697
+	}
698
+
699
+
700
+	/**
701
+	 * This is used to set registered script handles that have data.
702
+	 *
703
+	 * @param string $script_handle
704
+	 */
705
+	private function addRegisteredScriptHandlesWithData($script_handle)
706
+	{
707
+		$this->script_handles_with_data[ $script_handle ] = $script_handle;
708
+	}
709
+
710
+
711
+	/**i
712 712
      * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the
713 713
      * Dependency stored in WP_Scripts if its set.
714 714
      */
715
-    private function removeAlreadyRegisteredDataForScriptHandles()
716
-    {
717
-        if (empty($this->script_handles_with_data)) {
718
-            return;
719
-        }
720
-        foreach ($this->script_handles_with_data as $script_handle) {
721
-            $this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
722
-        }
723
-    }
724
-
725
-
726
-    /**
727
-     * Removes any data dependency registered in WP_Scripts if its set.
728
-     *
729
-     * @param string $script_handle
730
-     */
731
-    private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
732
-    {
733
-        if (isset($this->script_handles_with_data[ $script_handle ])) {
734
-            global $wp_scripts;
735
-            $unset_handle = false;
736
-            if ($wp_scripts->get_data($script_handle, 'data')) {
737
-                unset($wp_scripts->registered[ $script_handle ]->extra['data']);
738
-                $unset_handle = true;
739
-            }
740
-            //deal with inline_scripts
741
-            if ($wp_scripts->get_data($script_handle, 'before')) {
742
-                unset($wp_scripts->registered[ $script_handle ]->extra['before']);
743
-                $unset_handle = true;
744
-            }
745
-            if ($wp_scripts->get_data($script_handle, 'after')) {
746
-                unset($wp_scripts->registered[ $script_handle ]->extra['after']);
747
-            }
748
-            if ($unset_handle) {
749
-                unset($this->script_handles_with_data[ $script_handle ]);
750
-            }
751
-        }
752
-    }
753
-
754
-
755
-    /**
756
-     * register translations for a registered script
757
-     *
758
-     * @param string $handle
759
-     */
760
-    public function registerTranslation($handle)
761
-    {
762
-        $this->i18n_registry->registerScriptI18n($handle);
763
-    }
764
-
765
-
766
-    /**
767
-     * @since 4.9.63.p
768
-     * @return bool
769
-     */
770
-    private function debug()
771
-    {
772
-        return apply_filters(
773
-            'FHEE__EventEspresso_core_services_assets_Registry__debug',
774
-            defined('EE_DEBUG') && EE_DEBUG
775
-        );
776
-    }
777
-
778
-
779
-    /**
780
-     * Get the dependencies array for the given js asset chunk name
781
-     *
782
-     * @param string $namespace
783
-     * @param string $chunk_name
784
-     * @return array
785
-     * @deprecated $VID:$
786
-     * @since 4.9.82.p
787
-     */
788
-    public function getJsDependencies($namespace, $chunk_name)
789
-    {
790
-        $details = $this->getJsAssetDetails($namespace, $chunk_name);
791
-        return isset($details['dependencies']) ? $details['dependencies'] : [];
792
-    }
793
-
794
-
795
-    /**
796
-     * Get the dependencies array for the given css asset chunk name
797
-     *
798
-     * @param string $namespace
799
-     * @param string $chunk_name
800
-     * @return array
801
-     * @deprecated $VID:$
802
-     * @since      4.9.82.p
803
-     */
804
-    public function getCssDependencies($namespace, $chunk_name)
805
-    {
806
-        $details = $this->getCssAssetDetails($namespace, $chunk_name);
807
-        return isset($details['dependencies']) ? $details['dependencies'] : [];
808
-    }
715
+	private function removeAlreadyRegisteredDataForScriptHandles()
716
+	{
717
+		if (empty($this->script_handles_with_data)) {
718
+			return;
719
+		}
720
+		foreach ($this->script_handles_with_data as $script_handle) {
721
+			$this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
722
+		}
723
+	}
724
+
725
+
726
+	/**
727
+	 * Removes any data dependency registered in WP_Scripts if its set.
728
+	 *
729
+	 * @param string $script_handle
730
+	 */
731
+	private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
732
+	{
733
+		if (isset($this->script_handles_with_data[ $script_handle ])) {
734
+			global $wp_scripts;
735
+			$unset_handle = false;
736
+			if ($wp_scripts->get_data($script_handle, 'data')) {
737
+				unset($wp_scripts->registered[ $script_handle ]->extra['data']);
738
+				$unset_handle = true;
739
+			}
740
+			//deal with inline_scripts
741
+			if ($wp_scripts->get_data($script_handle, 'before')) {
742
+				unset($wp_scripts->registered[ $script_handle ]->extra['before']);
743
+				$unset_handle = true;
744
+			}
745
+			if ($wp_scripts->get_data($script_handle, 'after')) {
746
+				unset($wp_scripts->registered[ $script_handle ]->extra['after']);
747
+			}
748
+			if ($unset_handle) {
749
+				unset($this->script_handles_with_data[ $script_handle ]);
750
+			}
751
+		}
752
+	}
753
+
754
+
755
+	/**
756
+	 * register translations for a registered script
757
+	 *
758
+	 * @param string $handle
759
+	 */
760
+	public function registerTranslation($handle)
761
+	{
762
+		$this->i18n_registry->registerScriptI18n($handle);
763
+	}
764
+
765
+
766
+	/**
767
+	 * @since 4.9.63.p
768
+	 * @return bool
769
+	 */
770
+	private function debug()
771
+	{
772
+		return apply_filters(
773
+			'FHEE__EventEspresso_core_services_assets_Registry__debug',
774
+			defined('EE_DEBUG') && EE_DEBUG
775
+		);
776
+	}
777
+
778
+
779
+	/**
780
+	 * Get the dependencies array for the given js asset chunk name
781
+	 *
782
+	 * @param string $namespace
783
+	 * @param string $chunk_name
784
+	 * @return array
785
+	 * @deprecated $VID:$
786
+	 * @since 4.9.82.p
787
+	 */
788
+	public function getJsDependencies($namespace, $chunk_name)
789
+	{
790
+		$details = $this->getJsAssetDetails($namespace, $chunk_name);
791
+		return isset($details['dependencies']) ? $details['dependencies'] : [];
792
+	}
793
+
794
+
795
+	/**
796
+	 * Get the dependencies array for the given css asset chunk name
797
+	 *
798
+	 * @param string $namespace
799
+	 * @param string $chunk_name
800
+	 * @return array
801
+	 * @deprecated $VID:$
802
+	 * @since      4.9.82.p
803
+	 */
804
+	public function getCssDependencies($namespace, $chunk_name)
805
+	{
806
+		$details = $this->getCssAssetDetails($namespace, $chunk_name);
807
+		return isset($details['dependencies']) ? $details['dependencies'] : [];
808
+	}
809 809
 }
Please login to merge, or discard this patch.
Spacing   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
                 $script->version(),
185 185
                 $script->loadInFooter()
186 186
             );
187
-            if (! $registered && $this->debug()) {
187
+            if ( ! $registered && $this->debug()) {
188 188
                 throw new AssetRegistrationException($script->handle());
189 189
             }
190 190
             $script->setRegistered($registered);
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
         $this->removeAlreadyRegisteredDataForScriptHandles();
246 246
         wp_add_inline_script(
247 247
             'eejs-core',
248
-            'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)),
248
+            'var eejsdata='.wp_json_encode(array('data' => $this->jsdata)),
249 249
             'before'
250 250
         );
251 251
         $scripts = $this->assets->getJavascriptAssetsWithData();
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
     public function addData($key, $value)
276 276
     {
277 277
         if ($this->verifyDataNotExisting($key)) {
278
-            $this->jsdata[ $key ] = $value;
278
+            $this->jsdata[$key] = $value;
279 279
         }
280 280
     }
281 281
 
@@ -300,10 +300,10 @@  discard block
 block discarded – undo
300 300
      */
301 301
     public function pushData($key, $value)
302 302
     {
303
-        if (isset($this->jsdata[ $key ])
304
-            && ! is_array($this->jsdata[ $key ])
303
+        if (isset($this->jsdata[$key])
304
+            && ! is_array($this->jsdata[$key])
305 305
         ) {
306
-            if (! $this->debug()) {
306
+            if ( ! $this->debug()) {
307 307
                 return;
308 308
             }
309 309
             throw new InvalidArgumentException(
@@ -318,10 +318,10 @@  discard block
 block discarded – undo
318 318
                 )
319 319
             );
320 320
         }
321
-        if ( ! isset( $this->jsdata[ $key ] ) ) {
322
-            $this->jsdata[ $key ] = is_array($value) ? $value : [$value];
321
+        if ( ! isset($this->jsdata[$key])) {
322
+            $this->jsdata[$key] = is_array($value) ? $value : [$value];
323 323
         } else {
324
-            $this->jsdata[ $key ] = array_merge( $this->jsdata[$key], (array) $value);
324
+            $this->jsdata[$key] = array_merge($this->jsdata[$key], (array) $value);
325 325
         }
326 326
     }
327 327
 
@@ -336,12 +336,12 @@  discard block
 block discarded – undo
336 336
      */
337 337
     public function addTemplate($template_reference, $template_content)
338 338
     {
339
-        if (! isset($this->jsdata['templates'])) {
339
+        if ( ! isset($this->jsdata['templates'])) {
340 340
             $this->jsdata['templates'] = array();
341 341
         }
342 342
         //no overrides allowed.
343
-        if (isset($this->jsdata['templates'][ $template_reference ])) {
344
-            if (! $this->debug()) {
343
+        if (isset($this->jsdata['templates'][$template_reference])) {
344
+            if ( ! $this->debug()) {
345 345
                 return;
346 346
             }
347 347
             throw new InvalidArgumentException(
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
                 )
355 355
             );
356 356
         }
357
-        $this->jsdata['templates'][ $template_reference ] = $template_content;
357
+        $this->jsdata['templates'][$template_reference] = $template_content;
358 358
     }
359 359
 
360 360
 
@@ -366,8 +366,8 @@  discard block
 block discarded – undo
366 366
      */
367 367
     public function getTemplate($template_reference)
368 368
     {
369
-        return isset($this->jsdata['templates'][ $template_reference ])
370
-            ? $this->jsdata['templates'][ $template_reference ]
369
+        return isset($this->jsdata['templates'][$template_reference])
370
+            ? $this->jsdata['templates'][$template_reference]
371 371
             : '';
372 372
     }
373 373
 
@@ -380,8 +380,8 @@  discard block
 block discarded – undo
380 380
      */
381 381
     public function getData($key)
382 382
     {
383
-        return isset($this->jsdata[ $key ])
384
-            ? $this->jsdata[ $key ]
383
+        return isset($this->jsdata[$key])
384
+            ? $this->jsdata[$key]
385 385
             : false;
386 386
     }
387 387
 
@@ -396,11 +396,11 @@  discard block
 block discarded – undo
396 396
      */
397 397
     protected function verifyDataNotExisting($key)
398 398
     {
399
-        if (isset($this->jsdata[ $key ])) {
400
-            if (! $this->debug()) {
399
+        if (isset($this->jsdata[$key])) {
400
+            if ( ! $this->debug()) {
401 401
                 return false;
402 402
             }
403
-            if (is_array($this->jsdata[ $key ])) {
403
+            if (is_array($this->jsdata[$key])) {
404 404
                 throw new InvalidArgumentException(
405 405
                     sprintf(
406 406
                         __(
@@ -443,11 +443,11 @@  discard block
 block discarded – undo
443 443
     public function getAssetUrl($namespace, $chunk_name, $asset_type)
444 444
     {
445 445
         $url = isset(
446
-            $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ],
447
-            $this->manifest_data[ $namespace ]['url_base']
446
+            $this->manifest_data[$namespace][$chunk_name.'.'.$asset_type],
447
+            $this->manifest_data[$namespace]['url_base']
448 448
         )
449
-            ? $this->manifest_data[ $namespace ]['url_base']
450
-              . $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ]
449
+            ? $this->manifest_data[$namespace]['url_base']
450
+              . $this->manifest_data[$namespace][$chunk_name.'.'.$asset_type]
451 451
             : $chunk_name;
452 452
 
453 453
         return apply_filters(
@@ -498,21 +498,21 @@  discard block
 block discarded – undo
498 498
      */
499 499
     private function getDetailsForAsset($namespace, $chunk_name, $asset_type)
500 500
     {
501
-        $asset_index = $chunk_name . '.' . $asset_type;
502
-        if (! isset( $this->dependencies_data[ $namespace ][ $asset_index ])) {
503
-            $path = isset($this->manifest_data[ $namespace ]['path'])
504
-                ? $this->manifest_data[ $namespace ]['path']
501
+        $asset_index = $chunk_name.'.'.$asset_type;
502
+        if ( ! isset($this->dependencies_data[$namespace][$asset_index])) {
503
+            $path = isset($this->manifest_data[$namespace]['path'])
504
+                ? $this->manifest_data[$namespace]['path']
505 505
                 : '';
506
-            $dependencies_index = $chunk_name . '.' . Asset::TYPE_PHP;
507
-            $file_path = isset($this->manifest_data[ $namespace ][ $dependencies_index ])
508
-                ? $path . $this->manifest_data[ $namespace ][ $dependencies_index ]
506
+            $dependencies_index = $chunk_name.'.'.Asset::TYPE_PHP;
507
+            $file_path = isset($this->manifest_data[$namespace][$dependencies_index])
508
+                ? $path.$this->manifest_data[$namespace][$dependencies_index]
509 509
                 :
510 510
                 '';
511
-            $this->dependencies_data[ $namespace ][ $asset_index ] = $file_path !== '' && file_exists($file_path)
511
+            $this->dependencies_data[$namespace][$asset_index] = $file_path !== '' && file_exists($file_path)
512 512
                 ? $this->getDetailsForAssetType($namespace, $asset_type, $file_path, $chunk_name)
513 513
                 : [];
514 514
         }
515
-        $details = $this->dependencies_data[ $namespace ][ $asset_index ];
515
+        $details = $this->dependencies_data[$namespace][$asset_index];
516 516
         return $details;
517 517
     }
518 518
 
@@ -539,34 +539,34 @@  discard block
 block discarded – undo
539 539
             ? $asset_details['version']
540 540
             : '';
541 541
         if ($asset_type === Asset::TYPE_JS) {
542
-            $asset_details['dependencies'] =  $chunk_name === 'eejs-core'
542
+            $asset_details['dependencies'] = $chunk_name === 'eejs-core'
543 543
                 ? $asset_details['dependencies']
544
-                : $asset_details['dependencies'] + [ CoreAssetManager::JS_HANDLE_JS_CORE ];
544
+                : $asset_details['dependencies'] + [CoreAssetManager::JS_HANDLE_JS_CORE];
545 545
             return $asset_details;
546 546
         }
547 547
         // for css we need to make sure there is actually a css file related to this chunk.
548
-        if (isset($this->manifest_data[ $namespace ])) {
548
+        if (isset($this->manifest_data[$namespace])) {
549 549
             // array of css chunk files for ee.
550 550
             $css_chunks = array_map(
551
-                static function ($value) {
551
+                static function($value) {
552 552
                     return str_replace('.css', '', $value);
553 553
                 },
554 554
                 array_filter(
555
-                    array_keys($this->manifest_data[ $namespace ]),
556
-                    static function ($value) {
555
+                    array_keys($this->manifest_data[$namespace]),
556
+                    static function($value) {
557 557
                         return strpos($value, '.css') !== false;
558 558
                     }
559 559
                 )
560 560
             );
561 561
             // add known wp chunks with css
562
-            $css_chunks = array_merge( $css_chunks, $this->wp_css_handle_dependencies);
562
+            $css_chunks = array_merge($css_chunks, $this->wp_css_handle_dependencies);
563 563
             // flip for easier search
564 564
             $css_chunks = array_flip($css_chunks);
565 565
             // now let's filter the dependencies for the incoming chunk to actual chunks that have styles
566 566
             $asset_details['dependencies'] = array_filter(
567 567
                 $asset_details['dependencies'],
568
-                static function ($chunk_name) use ($css_chunks) {
569
-                    return isset($css_chunks[ $chunk_name ]);
568
+                static function($chunk_name) use ($css_chunks) {
569
+                    return isset($css_chunks[$chunk_name]);
570 570
                 }
571 571
             );
572 572
             return $asset_details;
@@ -615,7 +615,7 @@  discard block
 block discarded – undo
615 615
             $this->registerManifestFile(
616 616
                 $manifest_file->assetNamespace(),
617 617
                 $manifest_file->urlBase(),
618
-                $manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST,
618
+                $manifest_file->filepath().Registry::FILE_NAME_BUILD_MANIFEST,
619 619
                 $manifest_file->filepath()
620 620
             );
621 621
         }
@@ -636,8 +636,8 @@  discard block
 block discarded – undo
636 636
      */
637 637
     public function registerManifestFile($namespace, $url_base, $manifest_file, $manifest_file_path = '')
638 638
     {
639
-        if (isset($this->manifest_data[ $namespace ])) {
640
-            if (! $this->debug()) {
639
+        if (isset($this->manifest_data[$namespace])) {
640
+            if ( ! $this->debug()) {
641 641
                 return;
642 642
             }
643 643
             throw new InvalidArgumentException(
@@ -670,12 +670,12 @@  discard block
 block discarded – undo
670 670
             }
671 671
             return;
672 672
         }
673
-        $this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file);
674
-        if (! isset($this->manifest_data[ $namespace ]['url_base'])) {
675
-            $this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base);
673
+        $this->manifest_data[$namespace] = $this->decodeManifestFile($manifest_file);
674
+        if ( ! isset($this->manifest_data[$namespace]['url_base'])) {
675
+            $this->manifest_data[$namespace]['url_base'] = trailingslashit($url_base);
676 676
         }
677
-        if (! isset($this->manifest_data[ $namespace ]['path'])) {
678
-            $this->manifest_data[ $namespace ]['path'] = $manifest_file_path;
677
+        if ( ! isset($this->manifest_data[$namespace]['path'])) {
678
+            $this->manifest_data[$namespace]['path'] = $manifest_file_path;
679 679
         }
680 680
     }
681 681
 
@@ -690,7 +690,7 @@  discard block
 block discarded – undo
690 690
      */
691 691
     private function decodeManifestFile($manifest_file)
692 692
     {
693
-        if (! file_exists($manifest_file)) {
693
+        if ( ! file_exists($manifest_file)) {
694 694
             throw new InvalidFilePathException($manifest_file);
695 695
         }
696 696
         return json_decode(file_get_contents($manifest_file), true);
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
      */
705 705
     private function addRegisteredScriptHandlesWithData($script_handle)
706 706
     {
707
-        $this->script_handles_with_data[ $script_handle ] = $script_handle;
707
+        $this->script_handles_with_data[$script_handle] = $script_handle;
708 708
     }
709 709
 
710 710
 
@@ -730,23 +730,23 @@  discard block
 block discarded – undo
730 730
      */
731 731
     private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
732 732
     {
733
-        if (isset($this->script_handles_with_data[ $script_handle ])) {
733
+        if (isset($this->script_handles_with_data[$script_handle])) {
734 734
             global $wp_scripts;
735 735
             $unset_handle = false;
736 736
             if ($wp_scripts->get_data($script_handle, 'data')) {
737
-                unset($wp_scripts->registered[ $script_handle ]->extra['data']);
737
+                unset($wp_scripts->registered[$script_handle]->extra['data']);
738 738
                 $unset_handle = true;
739 739
             }
740 740
             //deal with inline_scripts
741 741
             if ($wp_scripts->get_data($script_handle, 'before')) {
742
-                unset($wp_scripts->registered[ $script_handle ]->extra['before']);
742
+                unset($wp_scripts->registered[$script_handle]->extra['before']);
743 743
                 $unset_handle = true;
744 744
             }
745 745
             if ($wp_scripts->get_data($script_handle, 'after')) {
746
-                unset($wp_scripts->registered[ $script_handle ]->extra['after']);
746
+                unset($wp_scripts->registered[$script_handle]->extra['after']);
747 747
             }
748 748
             if ($unset_handle) {
749
-                unset($this->script_handles_with_data[ $script_handle ]);
749
+                unset($this->script_handles_with_data[$script_handle]);
750 750
             }
751 751
         }
752 752
     }
Please login to merge, or discard this patch.
core/domain/values/assets/Asset.php 1 patch
Indentation   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -16,168 +16,168 @@
 block discarded – undo
16 16
 abstract class Asset
17 17
 {
18 18
 
19
-    /**
20
-     * indicates the file extension for a build distribution CSS file
21
-     */
22
-    const FILE_EXTENSION_DISTRIBUTION_CSS = '.dist.css';
23
-
24
-    /**
25
-     * indicates the file extension for a build distribution JS file
26
-     */
27
-    const FILE_EXTENSION_DISTRIBUTION_JS = '.dist.js';
28
-
29
-    /**
30
-     * Indicates the file extension for a build distribution dependencies json file.
31
-     */
32
-    const FILE_EXTENSION_DISTRIBUTION_DEPS = '.dist.deps.php';
33
-
34
-    /**
35
-     * indicates a Cascading Style Sheet asset
36
-     */
37
-    const TYPE_CSS = 'css';
38
-
39
-    /**
40
-     * indicates a Javascript asset
41
-     */
42
-    const TYPE_JS = 'js';
43
-
44
-    /**
45
-     * indicates a JSON asset
46
-     */
47
-    CONST TYPE_JSON = 'json';
48
-    /**
49
-     * indicates a PHP asset
50
-     */
51
-    CONST TYPE_PHP = 'php';
52
-
53
-    /**
54
-     * indicates a Javascript manifest file
55
-     */
56
-    const TYPE_MANIFEST = 'manifest';
57
-
58
-    /**
59
-     * @var DomainInterface $domain
60
-     */
61
-    protected $domain;
62
-
63
-    /**
64
-     * @var string $type
65
-     */
66
-    private $type;
67
-
68
-    /**
69
-     * @var string $handle
70
-     */
71
-    private $handle;
72
-
73
-    /**
74
-     * @var bool $registered
75
-     */
76
-    private $registered = false;
77
-
78
-
79
-    /**
80
-     * Asset constructor.
81
-     *
82
-     * @param                 $type
83
-     * @param string          $handle
84
-     * @param DomainInterface $domain
85
-     * @throws InvalidDataTypeException
86
-     */
87
-    public function __construct($type, $handle, DomainInterface $domain)
88
-    {
89
-        $this->domain = $domain;
90
-        $this->setType($type);
91
-        $this->setHandle($handle);
92
-    }
93
-
94
-
95
-    /**
96
-     * @return array
97
-     */
98
-    public function validAssetTypes()
99
-    {
100
-        return array(
101
-            Asset::TYPE_CSS,
102
-            Asset::TYPE_JS,
103
-            Asset::TYPE_MANIFEST,
104
-        );
105
-    }
106
-
107
-
108
-    /**
109
-     * @param string $type
110
-     * @throws InvalidDataTypeException
111
-     */
112
-    private function setType($type)
113
-    {
114
-        if (! in_array($type, $this->validAssetTypes(), true)) {
115
-            throw new InvalidDataTypeException(
116
-                'Asset::$type',
117
-                $type,
118
-                'one of the TYPE_* class constants on \EventEspresso\core\domain\values\Asset is required'
119
-            );
120
-        }
121
-        $this->type = $type;
122
-    }
123
-
124
-
125
-    /**
126
-     * @param string $handle
127
-     * @throws InvalidDataTypeException
128
-     */
129
-    private function setHandle($handle)
130
-    {
131
-        if (! is_string($handle)) {
132
-            throw new InvalidDataTypeException(
133
-                '$handle',
134
-                $handle,
135
-                'string'
136
-            );
137
-        }
138
-        $this->handle = $handle;
139
-    }
140
-
141
-
142
-    /**
143
-     * @return string
144
-     */
145
-    public function assetNamespace()
146
-    {
147
-        return $this->domain->assetNamespace();
148
-    }
149
-
150
-
151
-    /**
152
-     * @return string
153
-     */
154
-    public function type()
155
-    {
156
-        return $this->type;
157
-    }
158
-
159
-
160
-    /**
161
-     * @return string
162
-     */
163
-    public function handle()
164
-    {
165
-        return $this->handle;
166
-    }
167
-
168
-    /**
169
-     * @return bool
170
-     */
171
-    public function isRegistered()
172
-    {
173
-        return $this->registered;
174
-    }
175
-
176
-    /**
177
-     * @param bool $registered
178
-     */
179
-    public function setRegistered($registered = true)
180
-    {
181
-        $this->registered = filter_var($registered, FILTER_VALIDATE_BOOLEAN);
182
-    }
19
+	/**
20
+	 * indicates the file extension for a build distribution CSS file
21
+	 */
22
+	const FILE_EXTENSION_DISTRIBUTION_CSS = '.dist.css';
23
+
24
+	/**
25
+	 * indicates the file extension for a build distribution JS file
26
+	 */
27
+	const FILE_EXTENSION_DISTRIBUTION_JS = '.dist.js';
28
+
29
+	/**
30
+	 * Indicates the file extension for a build distribution dependencies json file.
31
+	 */
32
+	const FILE_EXTENSION_DISTRIBUTION_DEPS = '.dist.deps.php';
33
+
34
+	/**
35
+	 * indicates a Cascading Style Sheet asset
36
+	 */
37
+	const TYPE_CSS = 'css';
38
+
39
+	/**
40
+	 * indicates a Javascript asset
41
+	 */
42
+	const TYPE_JS = 'js';
43
+
44
+	/**
45
+	 * indicates a JSON asset
46
+	 */
47
+	CONST TYPE_JSON = 'json';
48
+	/**
49
+	 * indicates a PHP asset
50
+	 */
51
+	CONST TYPE_PHP = 'php';
52
+
53
+	/**
54
+	 * indicates a Javascript manifest file
55
+	 */
56
+	const TYPE_MANIFEST = 'manifest';
57
+
58
+	/**
59
+	 * @var DomainInterface $domain
60
+	 */
61
+	protected $domain;
62
+
63
+	/**
64
+	 * @var string $type
65
+	 */
66
+	private $type;
67
+
68
+	/**
69
+	 * @var string $handle
70
+	 */
71
+	private $handle;
72
+
73
+	/**
74
+	 * @var bool $registered
75
+	 */
76
+	private $registered = false;
77
+
78
+
79
+	/**
80
+	 * Asset constructor.
81
+	 *
82
+	 * @param                 $type
83
+	 * @param string          $handle
84
+	 * @param DomainInterface $domain
85
+	 * @throws InvalidDataTypeException
86
+	 */
87
+	public function __construct($type, $handle, DomainInterface $domain)
88
+	{
89
+		$this->domain = $domain;
90
+		$this->setType($type);
91
+		$this->setHandle($handle);
92
+	}
93
+
94
+
95
+	/**
96
+	 * @return array
97
+	 */
98
+	public function validAssetTypes()
99
+	{
100
+		return array(
101
+			Asset::TYPE_CSS,
102
+			Asset::TYPE_JS,
103
+			Asset::TYPE_MANIFEST,
104
+		);
105
+	}
106
+
107
+
108
+	/**
109
+	 * @param string $type
110
+	 * @throws InvalidDataTypeException
111
+	 */
112
+	private function setType($type)
113
+	{
114
+		if (! in_array($type, $this->validAssetTypes(), true)) {
115
+			throw new InvalidDataTypeException(
116
+				'Asset::$type',
117
+				$type,
118
+				'one of the TYPE_* class constants on \EventEspresso\core\domain\values\Asset is required'
119
+			);
120
+		}
121
+		$this->type = $type;
122
+	}
123
+
124
+
125
+	/**
126
+	 * @param string $handle
127
+	 * @throws InvalidDataTypeException
128
+	 */
129
+	private function setHandle($handle)
130
+	{
131
+		if (! is_string($handle)) {
132
+			throw new InvalidDataTypeException(
133
+				'$handle',
134
+				$handle,
135
+				'string'
136
+			);
137
+		}
138
+		$this->handle = $handle;
139
+	}
140
+
141
+
142
+	/**
143
+	 * @return string
144
+	 */
145
+	public function assetNamespace()
146
+	{
147
+		return $this->domain->assetNamespace();
148
+	}
149
+
150
+
151
+	/**
152
+	 * @return string
153
+	 */
154
+	public function type()
155
+	{
156
+		return $this->type;
157
+	}
158
+
159
+
160
+	/**
161
+	 * @return string
162
+	 */
163
+	public function handle()
164
+	{
165
+		return $this->handle;
166
+	}
167
+
168
+	/**
169
+	 * @return bool
170
+	 */
171
+	public function isRegistered()
172
+	{
173
+		return $this->registered;
174
+	}
175
+
176
+	/**
177
+	 * @param bool $registered
178
+	 */
179
+	public function setRegistered($registered = true)
180
+	{
181
+		$this->registered = filter_var($registered, FILTER_VALIDATE_BOOLEAN);
182
+	}
183 183
 }
Please login to merge, or discard this patch.
core/domain/values/assets/BrowserAsset.php 2 patches
Indentation   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -17,148 +17,148 @@
 block discarded – undo
17 17
 abstract class BrowserAsset extends Asset
18 18
 {
19 19
 
20
-    /**
21
-     * @var string $source
22
-     */
23
-    private $source;
24
-
25
-    /**
26
-     * @var array $dependencies
27
-     */
28
-    private $dependencies;
29
-
30
-    /**
31
-     * @var string $version
32
-     */
33
-    private $version;
34
-
35
-
36
-    /**
37
-     * Asset constructor.
38
-     *
39
-     * @param string          $type
40
-     * @param string          $handle
41
-     * @param string          $source
42
-     * @param array           $dependencies
43
-     * @param DomainInterface $domain
44
-     * @param string          $version
45
-     * @throws DomainException
46
-     * @throws InvalidDataTypeException
47
-     */
48
-    public function __construct($type, $handle, $source, array $dependencies, DomainInterface $domain, $version = '')
49
-    {
50
-        parent::__construct($type, $handle, $domain);
51
-        $this->setSource($source);
52
-        $this->setDependencies($dependencies);
53
-        $this->setVersion($version, false);
54
-    }
55
-
56
-
57
-    /**
58
-     * @since 4.9.62.p
59
-     */
60
-    abstract public function enqueueAsset();
61
-
62
-
63
-    /**
64
-     * @return array
65
-     */
66
-    public function dependencies()
67
-    {
68
-        return $this->dependencies;
69
-    }
70
-
71
-
72
-    /**
73
-     * @param array $dependencies
74
-     */
75
-    private function setDependencies(array $dependencies)
76
-    {
77
-        $this->dependencies = $dependencies;
78
-    }
79
-
80
-
81
-    /**
82
-     * @since 4.9.62.p
83
-     * @return bool
84
-     */
85
-    public function hasDependencies()
86
-    {
87
-        return count($this->dependencies) > 0;
88
-    }
89
-
90
-
91
-    /**
92
-     * @return string
93
-     */
94
-    public function source()
95
-    {
96
-        return $this->source;
97
-    }
98
-
99
-
100
-    /**
101
-     * @param string $source
102
-     * @throws InvalidDataTypeException
103
-     */
104
-    private function setSource($source)
105
-    {
106
-        if (! is_string($source)) {
107
-            throw new InvalidDataTypeException(
108
-                '$source',
109
-                $source,
110
-                'string'
111
-            );
112
-        }
113
-        $this->source = $source;
114
-    }
115
-
116
-
117
-    /**
118
-     * @return string
119
-     * @throws InvalidDataTypeException
120
-     * @throws DomainException
121
-     */
122
-    public function version()
123
-    {
124
-        return $this->version;
125
-    }
126
-
127
-
128
-    /**
129
-     * @param string $version
130
-     * @param bool   $fluent
131
-     * @return BrowserAsset|null
132
-     * @throws DomainException
133
-     * @throws InvalidDataTypeException
134
-     */
135
-    public function setVersion($version, $fluent = true)
136
-    {
137
-        // if version is NOT set and this asset was NOT built for distribution,
138
-        // then set the version equal to the EE core plugin version
139
-        if (empty($version) && ! $this->isBuiltDistributionSource()) {
140
-            $version = $this->domain->version();
141
-        }
142
-        if (! is_string($version)) {
143
-            throw new InvalidDataTypeException(
144
-                '$version',
145
-                $version,
146
-                'string'
147
-            );
148
-        }
149
-        $this->version = $version;
150
-        if ($fluent) {
151
-            return $this;
152
-        }
153
-        return null;
154
-    }
155
-
156
-
157
-    /**
158
-     * @return bool
159
-     */
160
-    public function isBuiltDistributionSource() {
161
-        return substr($this->source, -8) === Asset::FILE_EXTENSION_DISTRIBUTION_JS
162
-               || substr($this->source, -9) === Asset::FILE_EXTENSION_DISTRIBUTION_CSS;
163
-    }
20
+	/**
21
+	 * @var string $source
22
+	 */
23
+	private $source;
24
+
25
+	/**
26
+	 * @var array $dependencies
27
+	 */
28
+	private $dependencies;
29
+
30
+	/**
31
+	 * @var string $version
32
+	 */
33
+	private $version;
34
+
35
+
36
+	/**
37
+	 * Asset constructor.
38
+	 *
39
+	 * @param string          $type
40
+	 * @param string          $handle
41
+	 * @param string          $source
42
+	 * @param array           $dependencies
43
+	 * @param DomainInterface $domain
44
+	 * @param string          $version
45
+	 * @throws DomainException
46
+	 * @throws InvalidDataTypeException
47
+	 */
48
+	public function __construct($type, $handle, $source, array $dependencies, DomainInterface $domain, $version = '')
49
+	{
50
+		parent::__construct($type, $handle, $domain);
51
+		$this->setSource($source);
52
+		$this->setDependencies($dependencies);
53
+		$this->setVersion($version, false);
54
+	}
55
+
56
+
57
+	/**
58
+	 * @since 4.9.62.p
59
+	 */
60
+	abstract public function enqueueAsset();
61
+
62
+
63
+	/**
64
+	 * @return array
65
+	 */
66
+	public function dependencies()
67
+	{
68
+		return $this->dependencies;
69
+	}
70
+
71
+
72
+	/**
73
+	 * @param array $dependencies
74
+	 */
75
+	private function setDependencies(array $dependencies)
76
+	{
77
+		$this->dependencies = $dependencies;
78
+	}
79
+
80
+
81
+	/**
82
+	 * @since 4.9.62.p
83
+	 * @return bool
84
+	 */
85
+	public function hasDependencies()
86
+	{
87
+		return count($this->dependencies) > 0;
88
+	}
89
+
90
+
91
+	/**
92
+	 * @return string
93
+	 */
94
+	public function source()
95
+	{
96
+		return $this->source;
97
+	}
98
+
99
+
100
+	/**
101
+	 * @param string $source
102
+	 * @throws InvalidDataTypeException
103
+	 */
104
+	private function setSource($source)
105
+	{
106
+		if (! is_string($source)) {
107
+			throw new InvalidDataTypeException(
108
+				'$source',
109
+				$source,
110
+				'string'
111
+			);
112
+		}
113
+		$this->source = $source;
114
+	}
115
+
116
+
117
+	/**
118
+	 * @return string
119
+	 * @throws InvalidDataTypeException
120
+	 * @throws DomainException
121
+	 */
122
+	public function version()
123
+	{
124
+		return $this->version;
125
+	}
126
+
127
+
128
+	/**
129
+	 * @param string $version
130
+	 * @param bool   $fluent
131
+	 * @return BrowserAsset|null
132
+	 * @throws DomainException
133
+	 * @throws InvalidDataTypeException
134
+	 */
135
+	public function setVersion($version, $fluent = true)
136
+	{
137
+		// if version is NOT set and this asset was NOT built for distribution,
138
+		// then set the version equal to the EE core plugin version
139
+		if (empty($version) && ! $this->isBuiltDistributionSource()) {
140
+			$version = $this->domain->version();
141
+		}
142
+		if (! is_string($version)) {
143
+			throw new InvalidDataTypeException(
144
+				'$version',
145
+				$version,
146
+				'string'
147
+			);
148
+		}
149
+		$this->version = $version;
150
+		if ($fluent) {
151
+			return $this;
152
+		}
153
+		return null;
154
+	}
155
+
156
+
157
+	/**
158
+	 * @return bool
159
+	 */
160
+	public function isBuiltDistributionSource() {
161
+		return substr($this->source, -8) === Asset::FILE_EXTENSION_DISTRIBUTION_JS
162
+			   || substr($this->source, -9) === Asset::FILE_EXTENSION_DISTRIBUTION_CSS;
163
+	}
164 164
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
      */
104 104
     private function setSource($source)
105 105
     {
106
-        if (! is_string($source)) {
106
+        if ( ! is_string($source)) {
107 107
             throw new InvalidDataTypeException(
108 108
                 '$source',
109 109
                 $source,
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
         if (empty($version) && ! $this->isBuiltDistributionSource()) {
140 140
             $version = $this->domain->version();
141 141
         }
142
-        if (! is_string($version)) {
142
+        if ( ! is_string($version)) {
143 143
             throw new InvalidDataTypeException(
144 144
                 '$version',
145 145
                 $version,
Please login to merge, or discard this patch.
core/domain/values/assets/StylesheetAsset.php 1 patch
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -17,68 +17,68 @@
 block discarded – undo
17 17
 class StylesheetAsset extends BrowserAsset
18 18
 {
19 19
 
20
-    /**
21
-     * @var string $media
22
-     */
23
-    private $media;
20
+	/**
21
+	 * @var string $media
22
+	 */
23
+	private $media;
24 24
 
25 25
 
26
-    /**
27
-     * CssFile constructor.
28
-     *
29
-     * @param                 $handle
30
-     * @param string          $source
31
-     * @param array           $dependencies
32
-     * @param DomainInterface $domain
33
-     * @param string          $media
34
-     * @param string          $version
35
-     * @throws InvalidDataTypeException
36
-     * @throws DomainException
37
-     */
38
-    public function __construct(
39
-        $handle,
40
-        $source,
41
-        array $dependencies,
42
-        DomainInterface $domain,
43
-        $media = 'all',
44
-        $version = ''
45
-    ) {
46
-        parent::__construct(Asset::TYPE_CSS, $handle, $source, $dependencies, $domain, $version);
47
-        $this->setMedia($media);
48
-    }
26
+	/**
27
+	 * CssFile constructor.
28
+	 *
29
+	 * @param                 $handle
30
+	 * @param string          $source
31
+	 * @param array           $dependencies
32
+	 * @param DomainInterface $domain
33
+	 * @param string          $media
34
+	 * @param string          $version
35
+	 * @throws InvalidDataTypeException
36
+	 * @throws DomainException
37
+	 */
38
+	public function __construct(
39
+		$handle,
40
+		$source,
41
+		array $dependencies,
42
+		DomainInterface $domain,
43
+		$media = 'all',
44
+		$version = ''
45
+	) {
46
+		parent::__construct(Asset::TYPE_CSS, $handle, $source, $dependencies, $domain, $version);
47
+		$this->setMedia($media);
48
+	}
49 49
 
50 50
 
51
-    /**
52
-     * @return string
53
-     */
54
-    public function media()
55
-    {
56
-        return $this->media;
57
-    }
51
+	/**
52
+	 * @return string
53
+	 */
54
+	public function media()
55
+	{
56
+		return $this->media;
57
+	}
58 58
 
59 59
 
60
-    /**
61
-     * @param string $media
62
-     * @throws InvalidDataTypeException
63
-     */
64
-    private function setMedia($media)
65
-    {
66
-        if (! is_string($media)) {
67
-            throw new InvalidDataTypeException(
68
-                '$media',
69
-                $media,
70
-                'string'
71
-            );
72
-        }
73
-        $this->media = $media;
74
-    }
60
+	/**
61
+	 * @param string $media
62
+	 * @throws InvalidDataTypeException
63
+	 */
64
+	private function setMedia($media)
65
+	{
66
+		if (! is_string($media)) {
67
+			throw new InvalidDataTypeException(
68
+				'$media',
69
+				$media,
70
+				'string'
71
+			);
72
+		}
73
+		$this->media = $media;
74
+	}
75 75
 
76 76
 
77
-    /**
78
-     * @since 4.9.62.p
79
-     */
80
-    public function enqueueAsset()
81
-    {
82
-        wp_enqueue_style($this->handle());
83
-    }
77
+	/**
78
+	 * @since 4.9.62.p
79
+	 */
80
+	public function enqueueAsset()
81
+	{
82
+		wp_enqueue_style($this->handle());
83
+	}
84 84
 }
Please login to merge, or discard this patch.
core/domain/values/assets/JavascriptAsset.php 1 patch
Indentation   +141 added lines, -141 removed lines patch added patch discarded remove patch
@@ -18,145 +18,145 @@
 block discarded – undo
18 18
 class JavascriptAsset extends BrowserAsset
19 19
 {
20 20
 
21
-    /**
22
-     * @var boolean $load_in_footer
23
-     */
24
-    private $load_in_footer = false;
25
-
26
-    /**
27
-     * @var boolean $requires_translation
28
-     */
29
-    private $requires_translation = false;
30
-
31
-    /**
32
-     * @var boolean $has_inline_data
33
-     */
34
-    private $has_inline_data = false;
35
-
36
-    /**
37
-     * @var Closure $inline_data_callback
38
-     */
39
-    private $inline_data_callback;
40
-
41
-
42
-    /**
43
-     * Asset constructor.
44
-     *
45
-     * @param string          $handle
46
-     * @param string          $source
47
-     * @param array           $dependencies
48
-     * @param bool            $load_in_footer
49
-     * @param DomainInterface $domain
50
-     * @param string          $version
51
-     * @throws InvalidDataTypeException
52
-     * @throws DomainException
53
-     */
54
-    public function __construct(
55
-        $handle,
56
-        $source,
57
-        array $dependencies,
58
-        $load_in_footer,
59
-        DomainInterface $domain,
60
-        $version = ''
61
-    ) {
62
-        parent::__construct(Asset::TYPE_JS, $handle, $source, $dependencies, $domain, $version);
63
-        $this->setLoadInFooter($load_in_footer);
64
-    }
65
-
66
-
67
-    /**
68
-     * @return bool
69
-     */
70
-    public function loadInFooter()
71
-    {
72
-        return $this->load_in_footer;
73
-    }
74
-
75
-
76
-    /**
77
-     * @param bool $load_in_footer
78
-     */
79
-    private function setLoadInFooter($load_in_footer = true)
80
-    {
81
-        $this->load_in_footer = filter_var($load_in_footer, FILTER_VALIDATE_BOOLEAN);
82
-    }
83
-
84
-
85
-    /**
86
-     * @return bool
87
-     */
88
-    public function requiresTranslation()
89
-    {
90
-        return $this->requires_translation;
91
-    }
92
-
93
-
94
-    /**
95
-     * @param bool $requires_translation
96
-     * @return JavascriptAsset
97
-     */
98
-    public function setRequiresTranslation($requires_translation = true)
99
-    {
100
-        $this->requires_translation = filter_var($requires_translation, FILTER_VALIDATE_BOOLEAN);
101
-        return $this;
102
-    }
103
-
104
-
105
-    /**
106
-     * @return bool
107
-     */
108
-    public function hasInlineData()
109
-    {
110
-        return $this->has_inline_data;
111
-    }
112
-
113
-
114
-    /**
115
-     * @param bool $has_inline_data
116
-     * @return JavascriptAsset
117
-     */
118
-    public function setHasInlineData($has_inline_data = true)
119
-    {
120
-        $this->has_inline_data = filter_var($has_inline_data, FILTER_VALIDATE_BOOLEAN);
121
-        return $this;
122
-    }
123
-
124
-
125
-    /**
126
-     * @return Closure
127
-     */
128
-    public function inlineDataCallback()
129
-    {
130
-        return $this->inline_data_callback;
131
-    }
132
-
133
-
134
-    /**
135
-     * @return bool
136
-     */
137
-    public function hasInlineDataCallback()
138
-    {
139
-        return $this->inline_data_callback instanceof Closure;
140
-    }
141
-
142
-
143
-    /**
144
-     * @param Closure $inline_data_callback
145
-     * @return JavascriptAsset
146
-     */
147
-    public function setInlineDataCallback(Closure $inline_data_callback)
148
-    {
149
-        $this->inline_data_callback = $inline_data_callback;
150
-        $this->setHasInlineData();
151
-        return $this;
152
-    }
153
-
154
-
155
-    /**
156
-     * @since 4.9.62.p
157
-     */
158
-    public function enqueueAsset()
159
-    {
160
-        wp_enqueue_script($this->handle());
161
-    }
21
+	/**
22
+	 * @var boolean $load_in_footer
23
+	 */
24
+	private $load_in_footer = false;
25
+
26
+	/**
27
+	 * @var boolean $requires_translation
28
+	 */
29
+	private $requires_translation = false;
30
+
31
+	/**
32
+	 * @var boolean $has_inline_data
33
+	 */
34
+	private $has_inline_data = false;
35
+
36
+	/**
37
+	 * @var Closure $inline_data_callback
38
+	 */
39
+	private $inline_data_callback;
40
+
41
+
42
+	/**
43
+	 * Asset constructor.
44
+	 *
45
+	 * @param string          $handle
46
+	 * @param string          $source
47
+	 * @param array           $dependencies
48
+	 * @param bool            $load_in_footer
49
+	 * @param DomainInterface $domain
50
+	 * @param string          $version
51
+	 * @throws InvalidDataTypeException
52
+	 * @throws DomainException
53
+	 */
54
+	public function __construct(
55
+		$handle,
56
+		$source,
57
+		array $dependencies,
58
+		$load_in_footer,
59
+		DomainInterface $domain,
60
+		$version = ''
61
+	) {
62
+		parent::__construct(Asset::TYPE_JS, $handle, $source, $dependencies, $domain, $version);
63
+		$this->setLoadInFooter($load_in_footer);
64
+	}
65
+
66
+
67
+	/**
68
+	 * @return bool
69
+	 */
70
+	public function loadInFooter()
71
+	{
72
+		return $this->load_in_footer;
73
+	}
74
+
75
+
76
+	/**
77
+	 * @param bool $load_in_footer
78
+	 */
79
+	private function setLoadInFooter($load_in_footer = true)
80
+	{
81
+		$this->load_in_footer = filter_var($load_in_footer, FILTER_VALIDATE_BOOLEAN);
82
+	}
83
+
84
+
85
+	/**
86
+	 * @return bool
87
+	 */
88
+	public function requiresTranslation()
89
+	{
90
+		return $this->requires_translation;
91
+	}
92
+
93
+
94
+	/**
95
+	 * @param bool $requires_translation
96
+	 * @return JavascriptAsset
97
+	 */
98
+	public function setRequiresTranslation($requires_translation = true)
99
+	{
100
+		$this->requires_translation = filter_var($requires_translation, FILTER_VALIDATE_BOOLEAN);
101
+		return $this;
102
+	}
103
+
104
+
105
+	/**
106
+	 * @return bool
107
+	 */
108
+	public function hasInlineData()
109
+	{
110
+		return $this->has_inline_data;
111
+	}
112
+
113
+
114
+	/**
115
+	 * @param bool $has_inline_data
116
+	 * @return JavascriptAsset
117
+	 */
118
+	public function setHasInlineData($has_inline_data = true)
119
+	{
120
+		$this->has_inline_data = filter_var($has_inline_data, FILTER_VALIDATE_BOOLEAN);
121
+		return $this;
122
+	}
123
+
124
+
125
+	/**
126
+	 * @return Closure
127
+	 */
128
+	public function inlineDataCallback()
129
+	{
130
+		return $this->inline_data_callback;
131
+	}
132
+
133
+
134
+	/**
135
+	 * @return bool
136
+	 */
137
+	public function hasInlineDataCallback()
138
+	{
139
+		return $this->inline_data_callback instanceof Closure;
140
+	}
141
+
142
+
143
+	/**
144
+	 * @param Closure $inline_data_callback
145
+	 * @return JavascriptAsset
146
+	 */
147
+	public function setInlineDataCallback(Closure $inline_data_callback)
148
+	{
149
+		$this->inline_data_callback = $inline_data_callback;
150
+		$this->setHasInlineData();
151
+		return $this;
152
+	}
153
+
154
+
155
+	/**
156
+	 * @since 4.9.62.p
157
+	 */
158
+	public function enqueueAsset()
159
+	{
160
+		wp_enqueue_script($this->handle());
161
+	}
162 162
 }
Please login to merge, or discard this patch.
core/domain/services/assets/CoreAssetManager.php 2 patches
Indentation   +438 added lines, -438 removed lines patch added patch discarded remove patch
@@ -32,461 +32,461 @@
 block discarded – undo
32 32
 class CoreAssetManager extends AssetManager
33 33
 {
34 34
 
35
-    // WordPress core / Third party JS asset handles
36
-    const JS_HANDLE_JQUERY = 'jquery';
35
+	// WordPress core / Third party JS asset handles
36
+	const JS_HANDLE_JQUERY = 'jquery';
37 37
 
38
-    const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate';
38
+	const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate';
39 39
 
40
-    const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods';
40
+	const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods';
41 41
 
42
-    const JS_HANDLE_UNDERSCORE = 'underscore';
42
+	const JS_HANDLE_UNDERSCORE = 'underscore';
43 43
 
44
-    const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core';
44
+	const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core';
45 45
 
46
-    /**
47
-     * @since 4.9.71.p
48
-     */
49
-    const JS_HANDLE_REACT = 'react';
46
+	/**
47
+	 * @since 4.9.71.p
48
+	 */
49
+	const JS_HANDLE_REACT = 'react';
50 50
 
51
-    /**
52
-     * @since 4.9.71.p
53
-     */
54
-    const JS_HANDLE_REACT_DOM = 'react-dom';
51
+	/**
52
+	 * @since 4.9.71.p
53
+	 */
54
+	const JS_HANDLE_REACT_DOM = 'react-dom';
55 55
 
56
-    /**
57
-     * @since 4.9.71.p
58
-     */
59
-    const JS_HANDLE_LODASH = 'lodash';
56
+	/**
57
+	 * @since 4.9.71.p
58
+	 */
59
+	const JS_HANDLE_LODASH = 'lodash';
60 60
 
61
-    const JS_HANDLE_JS_CORE = 'eejs-core';
61
+	const JS_HANDLE_JS_CORE = 'eejs-core';
62 62
 
63
-    const JS_HANDLE_VENDOR = 'eventespresso-vendor';
63
+	const JS_HANDLE_VENDOR = 'eventespresso-vendor';
64 64
 
65
-    const JS_HANDLE_DATA_STORES = 'eventespresso-data-stores';
65
+	const JS_HANDLE_DATA_STORES = 'eventespresso-data-stores';
66 66
 
67
-    const JS_HANDLE_HELPERS = 'eventespresso-helpers';
67
+	const JS_HANDLE_HELPERS = 'eventespresso-helpers';
68 68
 
69
-    const JS_HANDLE_MODEL = 'eventespresso-model';
69
+	const JS_HANDLE_MODEL = 'eventespresso-model';
70 70
 
71
-    const JS_HANDLE_VALUE_OBJECTS = 'eventespresso-value-objects';
71
+	const JS_HANDLE_VALUE_OBJECTS = 'eventespresso-value-objects';
72 72
 
73
-    const JS_HANDLE_HOCS = 'eventespresso-hocs';
73
+	const JS_HANDLE_HOCS = 'eventespresso-hocs';
74 74
 
75
-    const JS_HANDLE_COMPONENTS = 'eventespresso-components';
75
+	const JS_HANDLE_COMPONENTS = 'eventespresso-components';
76 76
 
77
-    const JS_HANDLE_EDITOR_HOCS = 'eventespresso-editor-hocs';
78
-
79
-    const JS_HANDLE_VALIDATORS = 'eventespresso-validators';
77
+	const JS_HANDLE_EDITOR_HOCS = 'eventespresso-editor-hocs';
78
+
79
+	const JS_HANDLE_VALIDATORS = 'eventespresso-validators';
80 80
 
81
-    const JS_HANDLE_CORE = 'espresso_core';
81
+	const JS_HANDLE_CORE = 'espresso_core';
82 82
 
83
-    const JS_HANDLE_I18N = 'eei18n';
83
+	const JS_HANDLE_I18N = 'eei18n';
84 84
 
85
-    const JS_HANDLE_ACCOUNTING = 'ee-accounting';
86
-
87
-    const JS_HANDLE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page';
88
-
89
-    // EE CSS assets handles
90
-    const CSS_HANDLE_DEFAULT = 'espresso_default';
91
-
92
-    const CSS_HANDLE_CUSTOM = 'espresso_custom_css';
93
-
94
-    const CSS_HANDLE_COMPONENTS = 'eventespresso-components';
95
-
96
-    const CSS_HANDLE_CORE_CSS_DEFAULT = 'eventespresso-core-css-default';
97
-
98
-    /**
99
-     * @var EE_Currency_Config $currency_config
100
-     */
101
-    protected $currency_config;
102
-
103
-    /**
104
-     * @var EE_Template_Config $template_config
105
-     */
106
-    protected $template_config;
107
-
108
-
109
-    /**
110
-     * CoreAssetRegister constructor.
111
-     *
112
-     * @param AssetCollection    $assets
113
-     * @param EE_Currency_Config $currency_config
114
-     * @param EE_Template_Config $template_config
115
-     * @param DomainInterface    $domain
116
-     * @param Registry           $registry
117
-     */
118
-    public function __construct(
119
-        AssetCollection $assets,
120
-        EE_Currency_Config $currency_config,
121
-        EE_Template_Config $template_config,
122
-        DomainInterface $domain,
123
-        Registry $registry
124
-    ) {
125
-        $this->currency_config = $currency_config;
126
-        $this->template_config = $template_config;
127
-        parent::__construct($domain, $assets, $registry);
128
-    }
129
-
130
-
131
-    /**
132
-     * @since 4.9.62.p
133
-     * @throws DomainException
134
-     * @throws DuplicateCollectionIdentifierException
135
-     * @throws InvalidArgumentException
136
-     * @throws InvalidDataTypeException
137
-     * @throws InvalidEntityException
138
-     * @throws InvalidInterfaceException
139
-     */
140
-    public function addAssets()
141
-    {
142
-        $this->addJavascriptFiles();
143
-        $this->addStylesheetFiles();
144
-    }
145
-
146
-
147
-    /**
148
-     * @since 4.9.62.p
149
-     * @throws DomainException
150
-     * @throws DuplicateCollectionIdentifierException
151
-     * @throws InvalidArgumentException
152
-     * @throws InvalidDataTypeException
153
-     * @throws InvalidEntityException
154
-     * @throws InvalidInterfaceException
155
-     */
156
-    public function addJavascriptFiles()
157
-    {
158
-        $this->loadCoreJs();
159
-        $this->loadJqueryValidate();
160
-        $this->loadAccountingJs();
161
-        add_action(
162
-            'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
163
-            array($this, 'loadQtipJs')
164
-        );
165
-        $this->registerAdminAssets();
166
-    }
167
-
168
-
169
-    /**
170
-     * @throws DuplicateCollectionIdentifierException
171
-     * @throws InvalidDataTypeException
172
-     * @throws InvalidEntityException
173
-     * @throws DomainException
174
-     * @since 4.9.62.p
175
-     */
176
-    public function addStylesheetFiles()
177
-    {
178
-        $this->loadCoreCss();
179
-    }
180
-
181
-
182
-    /**
183
-     * core default javascript
184
-     *
185
-     * @since 4.9.62.p
186
-     * @throws DomainException
187
-     * @throws DuplicateCollectionIdentifierException
188
-     * @throws InvalidArgumentException
189
-     * @throws InvalidDataTypeException
190
-     * @throws InvalidEntityException
191
-     * @throws InvalidInterfaceException
192
-     */
193
-    private function loadCoreJs()
194
-    {
195
-        // conditionally load third-party libraries that WP core MIGHT have.
196
-        $this->registerWpAssets();
197
-
198
-        $this->addJs(self::JS_HANDLE_JS_CORE)->setHasInlineData();
199
-        $this->addJs(self::JS_HANDLE_VENDOR);
200
-        $this->addJs(self::JS_HANDLE_VALIDATORS)->setRequiresTranslation();
201
-        $this->addJs(self::JS_HANDLE_HELPERS)->setRequiresTranslation();
202
-        $this->addJs(self::JS_HANDLE_MODEL)->setRequiresTranslation();
203
-        $this->addJs(self::JS_HANDLE_VALUE_OBJECTS)->setRequiresTranslation();
204
-        $this->addJs(self::JS_HANDLE_DATA_STORES)->setRequiresTranslation()->setInlineDataCallback(
205
-            static function () {
206
-                wp_add_inline_script(
207
-                    CoreAssetManager::JS_HANDLE_DATA_STORES,
208
-                    is_admin()
209
-                        ? 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware( eejs.middleWares.apiFetch.CONTEXT_CAPS_EDIT ) )'
210
-                        : 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware )'
211
-                );
212
-            }
213
-        );
214
-        $this->addJs(self::JS_HANDLE_HOCS, [self::JS_HANDLE_DATA_STORES])->setRequiresTranslation();
215
-        $this->addJs(self::JS_HANDLE_COMPONENTS, [self::JS_HANDLE_DATA_STORES])->setRequiresTranslation();
216
-        $this->addJs(self::JS_HANDLE_EDITOR_HOCS)->setRequiresTranslation();
217
-
218
-        $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest'));
219
-        $this->registry->addData(
220
-            'paths',
221
-            array(
222
-                'base_rest_route' => rest_url(),
223
-                'rest_route' => rest_url('ee/v4.8.36/'),
224
-                'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(),
225
-                'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(),
226
-                'site_url' => site_url('/'),
227
-                'admin_url' => admin_url('/'),
228
-            )
229
-        );
230
-        // Event Espresso brand name
231
-        $this->registry->addData('brandName', Domain::brandName());
232
-        /** site formatting values **/
233
-        $this->registry->addData(
234
-            'site_formats',
235
-            array(
236
-                'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats()
237
-            )
238
-        );
239
-        /** currency data **/
240
-        $this->registry->addData(
241
-            'currency_config',
242
-            $this->getCurrencySettings()
243
-        );
244
-        /** site timezone */
245
-        $this->registry->addData(
246
-            'default_timezone',
247
-            array(
248
-                'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(),
249
-                'string' => get_option('timezone_string'),
250
-                'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(),
251
-            )
252
-        );
253
-        /** site locale (user locale if user logged in) */
254
-        $this->registry->addData(
255
-            'locale',
256
-            array(
257
-                'user' => get_user_locale(),
258
-                'site' => get_locale()
259
-            )
260
-        );
261
-
262
-        $this->addJavascript(
263
-            CoreAssetManager::JS_HANDLE_CORE,
264
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
265
-            array(CoreAssetManager::JS_HANDLE_JQUERY)
266
-        )
267
-        ->setInlineDataCallback(
268
-            static function () {
269
-                wp_localize_script(
270
-                    CoreAssetManager::JS_HANDLE_CORE,
271
-                    CoreAssetManager::JS_HANDLE_I18N,
272
-                    EE_Registry::$i18n_js_strings
273
-                );
274
-            }
275
-        );
276
-    }
277
-
278
-
279
-    /**
280
-     * Registers vendor files that are bundled with a later version WP but might not be for the current version of
281
-     * WordPress in the running environment.
282
-     *
283
-     * @throws DuplicateCollectionIdentifierException
284
-     * @throws InvalidDataTypeException
285
-     * @throws InvalidEntityException
286
-     * @throws DomainException
287
-     * @since 4.9.71.p
288
-     */
289
-    private function registerWpAssets()
290
-    {
291
-        global $wp_version;
292
-        if (version_compare($wp_version, '5.0.beta', '>=')) {
293
-            return;
294
-        }
295
-        $this->addVendorJavascript(CoreAssetManager::JS_HANDLE_REACT, [], true, '16.6.0');
296
-        $this->addVendorJavascript(
297
-            CoreAssetManager::JS_HANDLE_REACT_DOM,
298
-            array(CoreAssetManager::JS_HANDLE_REACT),
299
-            true,
300
-            '16.6.0'
301
-        );
302
-        $this->addVendorJavascript(CoreAssetManager::JS_HANDLE_LODASH, [], true, '4.17.11')
303
-            ->setInlineDataCallback(
304
-                static function() {
305
-                    wp_add_inline_script(
306
-                        CoreAssetManager::JS_HANDLE_LODASH,
307
-                        'window.lodash = _.noConflict();'
308
-                    );
309
-                }
310
-            );
311
-    }
312
-
313
-
314
-    /**
315
-     * Returns configuration data for the accounting-js library.
316
-     * @since 4.9.71.p
317
-     * @return array
318
-     */
319
-    private function getAccountingSettings() {
320
-        return array(
321
-            'currency' => array(
322
-                'symbol'    => $this->currency_config->sign,
323
-                'format'    => array(
324
-                    'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
325
-                    'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
326
-                    'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
327
-                ),
328
-                'decimal'   => $this->currency_config->dec_mrk,
329
-                'thousand'  => $this->currency_config->thsnds,
330
-                'precision' => $this->currency_config->dec_plc,
331
-            ),
332
-            'number'   => array(
333
-                'precision' => $this->currency_config->dec_plc,
334
-                'thousand'  => $this->currency_config->thsnds,
335
-                'decimal'   => $this->currency_config->dec_mrk,
336
-            ),
337
-        );
338
-    }
339
-
340
-
341
-    /**
342
-     * Returns configuration data for the js Currency VO.
343
-     * @since 4.9.71.p
344
-     * @return array
345
-     */
346
-    private function getCurrencySettings()
347
-    {
348
-        return array(
349
-            'code' => $this->currency_config->code,
350
-            'singularLabel' => $this->currency_config->name,
351
-            'pluralLabel' => $this->currency_config->plural,
352
-            'sign' => $this->currency_config->sign,
353
-            'signB4' => $this->currency_config->sign_b4,
354
-            'decimalPlaces' => $this->currency_config->dec_plc,
355
-            'decimalMark' => $this->currency_config->dec_mrk,
356
-            'thousandsSeparator' => $this->currency_config->thsnds,
357
-        );
358
-    }
359
-
360
-
361
-    /**
362
-     * @throws DuplicateCollectionIdentifierException
363
-     * @throws InvalidDataTypeException
364
-     * @throws InvalidEntityException
365
-     * @throws DomainException
366
-     * @since 4.9.62.p
367
-     */
368
-    private function loadCoreCss()
369
-    {
370
-        if ($this->template_config->enable_default_style && ! is_admin()) {
371
-            $this->addStylesheet(
372
-                CoreAssetManager::CSS_HANDLE_DEFAULT,
373
-                is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
374
-                    ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
375
-                    : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
376
-                array('dashicons')
377
-            );
378
-            //Load custom style sheet if available
379
-            if ($this->template_config->custom_style_sheet !== null) {
380
-                $this->addStylesheet(
381
-                    CoreAssetManager::CSS_HANDLE_CUSTOM,
382
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
383
-                    array(CoreAssetManager::CSS_HANDLE_DEFAULT)
384
-                );
385
-            }
386
-        }
387
-        $this->addCss(self::CSS_HANDLE_CORE_CSS_DEFAULT, ['dashicons']);
388
-        $this->addCss(self::CSS_HANDLE_COMPONENTS, [self::CSS_HANDLE_CORE_CSS_DEFAULT]);
389
-    }
390
-
391
-
392
-    /**
393
-     * jQuery Validate for form validation
394
-     *
395
-     * @since 4.9.62.p
396
-     * @throws DomainException
397
-     * @throws DuplicateCollectionIdentifierException
398
-     * @throws InvalidDataTypeException
399
-     * @throws InvalidEntityException
400
-     */
401
-    private function loadJqueryValidate()
402
-    {
403
-        $this->addJavascript(
404
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
405
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
406
-            array(CoreAssetManager::JS_HANDLE_JQUERY),
407
-            true,
408
-            '1.15.0'
409
-        );
410
-
411
-        $this->addJavascript(
412
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
413
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
414
-            array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE),
415
-            true,
416
-            '1.15.0'
417
-        );
418
-    }
419
-
420
-
421
-    /**
422
-     * accounting.js for performing client-side calculations
423
-     *
424
-     * @since 4.9.62.p
425
-     * @throws DomainException
426
-     * @throws DuplicateCollectionIdentifierException
427
-     * @throws InvalidDataTypeException
428
-     * @throws InvalidEntityException
429
-     */
430
-    private function loadAccountingJs()
431
-    {
432
-        //accounting.js library
433
-        // @link http://josscrowcroft.github.io/accounting.js/
434
-        $this->addJavascript(
435
-            CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
436
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
437
-            array(CoreAssetManager::JS_HANDLE_UNDERSCORE),
438
-            true,
439
-            '0.3.2'
440
-        );
441
-
442
-        $this->addJavascript(
443
-            CoreAssetManager::JS_HANDLE_ACCOUNTING,
444
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
445
-            array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
446
-        )
447
-        ->setInlineDataCallback(
448
-            function () {
449
-                 wp_localize_script(
450
-                     CoreAssetManager::JS_HANDLE_ACCOUNTING,
451
-                     'EE_ACCOUNTING_CFG',
452
-                     $this->getAccountingSettings()
453
-                 );
454
-            }
455
-        );
456
-    }
457
-
458
-
459
-    /**
460
-     * registers assets for cleaning your ears
461
-     *
462
-     * @param JavascriptAsset $script
463
-     */
464
-    public function loadQtipJs(JavascriptAsset $script)
465
-    {
466
-        // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
467
-        // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
468
-        if (
469
-            $script->handle() === CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE
470
-            && apply_filters('FHEE_load_qtip', false)
471
-        ) {
472
-            EEH_Qtip_Loader::instance()->register_and_enqueue();
473
-        }
474
-    }
475
-
476
-
477
-    /**
478
-     * assets that are used in the WordPress admin
479
-     *
480
-     * @throws DuplicateCollectionIdentifierException
481
-     * @throws InvalidDataTypeException
482
-     * @throws InvalidEntityException
483
-     * @throws DomainException
484
-     * @since 4.9.62.p
485
-     */
486
-    private function registerAdminAssets()
487
-    {
488
-        $this->addJs(self::JS_HANDLE_WP_PLUGINS_PAGE)->setRequiresTranslation();
489
-        // note usage of the "JS_HANDLE.." constant is intentional here because css uses the same handle.
490
-        $this->addCss(self::JS_HANDLE_WP_PLUGINS_PAGE);
491
-    }
85
+	const JS_HANDLE_ACCOUNTING = 'ee-accounting';
86
+
87
+	const JS_HANDLE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page';
88
+
89
+	// EE CSS assets handles
90
+	const CSS_HANDLE_DEFAULT = 'espresso_default';
91
+
92
+	const CSS_HANDLE_CUSTOM = 'espresso_custom_css';
93
+
94
+	const CSS_HANDLE_COMPONENTS = 'eventespresso-components';
95
+
96
+	const CSS_HANDLE_CORE_CSS_DEFAULT = 'eventespresso-core-css-default';
97
+
98
+	/**
99
+	 * @var EE_Currency_Config $currency_config
100
+	 */
101
+	protected $currency_config;
102
+
103
+	/**
104
+	 * @var EE_Template_Config $template_config
105
+	 */
106
+	protected $template_config;
107
+
108
+
109
+	/**
110
+	 * CoreAssetRegister constructor.
111
+	 *
112
+	 * @param AssetCollection    $assets
113
+	 * @param EE_Currency_Config $currency_config
114
+	 * @param EE_Template_Config $template_config
115
+	 * @param DomainInterface    $domain
116
+	 * @param Registry           $registry
117
+	 */
118
+	public function __construct(
119
+		AssetCollection $assets,
120
+		EE_Currency_Config $currency_config,
121
+		EE_Template_Config $template_config,
122
+		DomainInterface $domain,
123
+		Registry $registry
124
+	) {
125
+		$this->currency_config = $currency_config;
126
+		$this->template_config = $template_config;
127
+		parent::__construct($domain, $assets, $registry);
128
+	}
129
+
130
+
131
+	/**
132
+	 * @since 4.9.62.p
133
+	 * @throws DomainException
134
+	 * @throws DuplicateCollectionIdentifierException
135
+	 * @throws InvalidArgumentException
136
+	 * @throws InvalidDataTypeException
137
+	 * @throws InvalidEntityException
138
+	 * @throws InvalidInterfaceException
139
+	 */
140
+	public function addAssets()
141
+	{
142
+		$this->addJavascriptFiles();
143
+		$this->addStylesheetFiles();
144
+	}
145
+
146
+
147
+	/**
148
+	 * @since 4.9.62.p
149
+	 * @throws DomainException
150
+	 * @throws DuplicateCollectionIdentifierException
151
+	 * @throws InvalidArgumentException
152
+	 * @throws InvalidDataTypeException
153
+	 * @throws InvalidEntityException
154
+	 * @throws InvalidInterfaceException
155
+	 */
156
+	public function addJavascriptFiles()
157
+	{
158
+		$this->loadCoreJs();
159
+		$this->loadJqueryValidate();
160
+		$this->loadAccountingJs();
161
+		add_action(
162
+			'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
163
+			array($this, 'loadQtipJs')
164
+		);
165
+		$this->registerAdminAssets();
166
+	}
167
+
168
+
169
+	/**
170
+	 * @throws DuplicateCollectionIdentifierException
171
+	 * @throws InvalidDataTypeException
172
+	 * @throws InvalidEntityException
173
+	 * @throws DomainException
174
+	 * @since 4.9.62.p
175
+	 */
176
+	public function addStylesheetFiles()
177
+	{
178
+		$this->loadCoreCss();
179
+	}
180
+
181
+
182
+	/**
183
+	 * core default javascript
184
+	 *
185
+	 * @since 4.9.62.p
186
+	 * @throws DomainException
187
+	 * @throws DuplicateCollectionIdentifierException
188
+	 * @throws InvalidArgumentException
189
+	 * @throws InvalidDataTypeException
190
+	 * @throws InvalidEntityException
191
+	 * @throws InvalidInterfaceException
192
+	 */
193
+	private function loadCoreJs()
194
+	{
195
+		// conditionally load third-party libraries that WP core MIGHT have.
196
+		$this->registerWpAssets();
197
+
198
+		$this->addJs(self::JS_HANDLE_JS_CORE)->setHasInlineData();
199
+		$this->addJs(self::JS_HANDLE_VENDOR);
200
+		$this->addJs(self::JS_HANDLE_VALIDATORS)->setRequiresTranslation();
201
+		$this->addJs(self::JS_HANDLE_HELPERS)->setRequiresTranslation();
202
+		$this->addJs(self::JS_HANDLE_MODEL)->setRequiresTranslation();
203
+		$this->addJs(self::JS_HANDLE_VALUE_OBJECTS)->setRequiresTranslation();
204
+		$this->addJs(self::JS_HANDLE_DATA_STORES)->setRequiresTranslation()->setInlineDataCallback(
205
+			static function () {
206
+				wp_add_inline_script(
207
+					CoreAssetManager::JS_HANDLE_DATA_STORES,
208
+					is_admin()
209
+						? 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware( eejs.middleWares.apiFetch.CONTEXT_CAPS_EDIT ) )'
210
+						: 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware )'
211
+				);
212
+			}
213
+		);
214
+		$this->addJs(self::JS_HANDLE_HOCS, [self::JS_HANDLE_DATA_STORES])->setRequiresTranslation();
215
+		$this->addJs(self::JS_HANDLE_COMPONENTS, [self::JS_HANDLE_DATA_STORES])->setRequiresTranslation();
216
+		$this->addJs(self::JS_HANDLE_EDITOR_HOCS)->setRequiresTranslation();
217
+
218
+		$this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest'));
219
+		$this->registry->addData(
220
+			'paths',
221
+			array(
222
+				'base_rest_route' => rest_url(),
223
+				'rest_route' => rest_url('ee/v4.8.36/'),
224
+				'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(),
225
+				'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(),
226
+				'site_url' => site_url('/'),
227
+				'admin_url' => admin_url('/'),
228
+			)
229
+		);
230
+		// Event Espresso brand name
231
+		$this->registry->addData('brandName', Domain::brandName());
232
+		/** site formatting values **/
233
+		$this->registry->addData(
234
+			'site_formats',
235
+			array(
236
+				'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats()
237
+			)
238
+		);
239
+		/** currency data **/
240
+		$this->registry->addData(
241
+			'currency_config',
242
+			$this->getCurrencySettings()
243
+		);
244
+		/** site timezone */
245
+		$this->registry->addData(
246
+			'default_timezone',
247
+			array(
248
+				'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(),
249
+				'string' => get_option('timezone_string'),
250
+				'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(),
251
+			)
252
+		);
253
+		/** site locale (user locale if user logged in) */
254
+		$this->registry->addData(
255
+			'locale',
256
+			array(
257
+				'user' => get_user_locale(),
258
+				'site' => get_locale()
259
+			)
260
+		);
261
+
262
+		$this->addJavascript(
263
+			CoreAssetManager::JS_HANDLE_CORE,
264
+			EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
265
+			array(CoreAssetManager::JS_HANDLE_JQUERY)
266
+		)
267
+		->setInlineDataCallback(
268
+			static function () {
269
+				wp_localize_script(
270
+					CoreAssetManager::JS_HANDLE_CORE,
271
+					CoreAssetManager::JS_HANDLE_I18N,
272
+					EE_Registry::$i18n_js_strings
273
+				);
274
+			}
275
+		);
276
+	}
277
+
278
+
279
+	/**
280
+	 * Registers vendor files that are bundled with a later version WP but might not be for the current version of
281
+	 * WordPress in the running environment.
282
+	 *
283
+	 * @throws DuplicateCollectionIdentifierException
284
+	 * @throws InvalidDataTypeException
285
+	 * @throws InvalidEntityException
286
+	 * @throws DomainException
287
+	 * @since 4.9.71.p
288
+	 */
289
+	private function registerWpAssets()
290
+	{
291
+		global $wp_version;
292
+		if (version_compare($wp_version, '5.0.beta', '>=')) {
293
+			return;
294
+		}
295
+		$this->addVendorJavascript(CoreAssetManager::JS_HANDLE_REACT, [], true, '16.6.0');
296
+		$this->addVendorJavascript(
297
+			CoreAssetManager::JS_HANDLE_REACT_DOM,
298
+			array(CoreAssetManager::JS_HANDLE_REACT),
299
+			true,
300
+			'16.6.0'
301
+		);
302
+		$this->addVendorJavascript(CoreAssetManager::JS_HANDLE_LODASH, [], true, '4.17.11')
303
+			->setInlineDataCallback(
304
+				static function() {
305
+					wp_add_inline_script(
306
+						CoreAssetManager::JS_HANDLE_LODASH,
307
+						'window.lodash = _.noConflict();'
308
+					);
309
+				}
310
+			);
311
+	}
312
+
313
+
314
+	/**
315
+	 * Returns configuration data for the accounting-js library.
316
+	 * @since 4.9.71.p
317
+	 * @return array
318
+	 */
319
+	private function getAccountingSettings() {
320
+		return array(
321
+			'currency' => array(
322
+				'symbol'    => $this->currency_config->sign,
323
+				'format'    => array(
324
+					'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
325
+					'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
326
+					'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
327
+				),
328
+				'decimal'   => $this->currency_config->dec_mrk,
329
+				'thousand'  => $this->currency_config->thsnds,
330
+				'precision' => $this->currency_config->dec_plc,
331
+			),
332
+			'number'   => array(
333
+				'precision' => $this->currency_config->dec_plc,
334
+				'thousand'  => $this->currency_config->thsnds,
335
+				'decimal'   => $this->currency_config->dec_mrk,
336
+			),
337
+		);
338
+	}
339
+
340
+
341
+	/**
342
+	 * Returns configuration data for the js Currency VO.
343
+	 * @since 4.9.71.p
344
+	 * @return array
345
+	 */
346
+	private function getCurrencySettings()
347
+	{
348
+		return array(
349
+			'code' => $this->currency_config->code,
350
+			'singularLabel' => $this->currency_config->name,
351
+			'pluralLabel' => $this->currency_config->plural,
352
+			'sign' => $this->currency_config->sign,
353
+			'signB4' => $this->currency_config->sign_b4,
354
+			'decimalPlaces' => $this->currency_config->dec_plc,
355
+			'decimalMark' => $this->currency_config->dec_mrk,
356
+			'thousandsSeparator' => $this->currency_config->thsnds,
357
+		);
358
+	}
359
+
360
+
361
+	/**
362
+	 * @throws DuplicateCollectionIdentifierException
363
+	 * @throws InvalidDataTypeException
364
+	 * @throws InvalidEntityException
365
+	 * @throws DomainException
366
+	 * @since 4.9.62.p
367
+	 */
368
+	private function loadCoreCss()
369
+	{
370
+		if ($this->template_config->enable_default_style && ! is_admin()) {
371
+			$this->addStylesheet(
372
+				CoreAssetManager::CSS_HANDLE_DEFAULT,
373
+				is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
374
+					? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
375
+					: EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
376
+				array('dashicons')
377
+			);
378
+			//Load custom style sheet if available
379
+			if ($this->template_config->custom_style_sheet !== null) {
380
+				$this->addStylesheet(
381
+					CoreAssetManager::CSS_HANDLE_CUSTOM,
382
+					EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
383
+					array(CoreAssetManager::CSS_HANDLE_DEFAULT)
384
+				);
385
+			}
386
+		}
387
+		$this->addCss(self::CSS_HANDLE_CORE_CSS_DEFAULT, ['dashicons']);
388
+		$this->addCss(self::CSS_HANDLE_COMPONENTS, [self::CSS_HANDLE_CORE_CSS_DEFAULT]);
389
+	}
390
+
391
+
392
+	/**
393
+	 * jQuery Validate for form validation
394
+	 *
395
+	 * @since 4.9.62.p
396
+	 * @throws DomainException
397
+	 * @throws DuplicateCollectionIdentifierException
398
+	 * @throws InvalidDataTypeException
399
+	 * @throws InvalidEntityException
400
+	 */
401
+	private function loadJqueryValidate()
402
+	{
403
+		$this->addJavascript(
404
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
405
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
406
+			array(CoreAssetManager::JS_HANDLE_JQUERY),
407
+			true,
408
+			'1.15.0'
409
+		);
410
+
411
+		$this->addJavascript(
412
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
413
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
414
+			array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE),
415
+			true,
416
+			'1.15.0'
417
+		);
418
+	}
419
+
420
+
421
+	/**
422
+	 * accounting.js for performing client-side calculations
423
+	 *
424
+	 * @since 4.9.62.p
425
+	 * @throws DomainException
426
+	 * @throws DuplicateCollectionIdentifierException
427
+	 * @throws InvalidDataTypeException
428
+	 * @throws InvalidEntityException
429
+	 */
430
+	private function loadAccountingJs()
431
+	{
432
+		//accounting.js library
433
+		// @link http://josscrowcroft.github.io/accounting.js/
434
+		$this->addJavascript(
435
+			CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
436
+			EE_THIRD_PARTY_URL . 'accounting/accounting.js',
437
+			array(CoreAssetManager::JS_HANDLE_UNDERSCORE),
438
+			true,
439
+			'0.3.2'
440
+		);
441
+
442
+		$this->addJavascript(
443
+			CoreAssetManager::JS_HANDLE_ACCOUNTING,
444
+			EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
445
+			array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
446
+		)
447
+		->setInlineDataCallback(
448
+			function () {
449
+				 wp_localize_script(
450
+					 CoreAssetManager::JS_HANDLE_ACCOUNTING,
451
+					 'EE_ACCOUNTING_CFG',
452
+					 $this->getAccountingSettings()
453
+				 );
454
+			}
455
+		);
456
+	}
457
+
458
+
459
+	/**
460
+	 * registers assets for cleaning your ears
461
+	 *
462
+	 * @param JavascriptAsset $script
463
+	 */
464
+	public function loadQtipJs(JavascriptAsset $script)
465
+	{
466
+		// qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
467
+		// can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
468
+		if (
469
+			$script->handle() === CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE
470
+			&& apply_filters('FHEE_load_qtip', false)
471
+		) {
472
+			EEH_Qtip_Loader::instance()->register_and_enqueue();
473
+		}
474
+	}
475
+
476
+
477
+	/**
478
+	 * assets that are used in the WordPress admin
479
+	 *
480
+	 * @throws DuplicateCollectionIdentifierException
481
+	 * @throws InvalidDataTypeException
482
+	 * @throws InvalidEntityException
483
+	 * @throws DomainException
484
+	 * @since 4.9.62.p
485
+	 */
486
+	private function registerAdminAssets()
487
+	{
488
+		$this->addJs(self::JS_HANDLE_WP_PLUGINS_PAGE)->setRequiresTranslation();
489
+		// note usage of the "JS_HANDLE.." constant is intentional here because css uses the same handle.
490
+		$this->addCss(self::JS_HANDLE_WP_PLUGINS_PAGE);
491
+	}
492 492
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
         $this->addJs(self::JS_HANDLE_MODEL)->setRequiresTranslation();
203 203
         $this->addJs(self::JS_HANDLE_VALUE_OBJECTS)->setRequiresTranslation();
204 204
         $this->addJs(self::JS_HANDLE_DATA_STORES)->setRequiresTranslation()->setInlineDataCallback(
205
-            static function () {
205
+            static function() {
206 206
                 wp_add_inline_script(
207 207
                     CoreAssetManager::JS_HANDLE_DATA_STORES,
208 208
                     is_admin()
@@ -261,11 +261,11 @@  discard block
 block discarded – undo
261 261
 
262 262
         $this->addJavascript(
263 263
             CoreAssetManager::JS_HANDLE_CORE,
264
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
264
+            EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js',
265 265
             array(CoreAssetManager::JS_HANDLE_JQUERY)
266 266
         )
267 267
         ->setInlineDataCallback(
268
-            static function () {
268
+            static function() {
269 269
                 wp_localize_script(
270 270
                     CoreAssetManager::JS_HANDLE_CORE,
271 271
                     CoreAssetManager::JS_HANDLE_I18N,
@@ -370,16 +370,16 @@  discard block
 block discarded – undo
370 370
         if ($this->template_config->enable_default_style && ! is_admin()) {
371 371
             $this->addStylesheet(
372 372
                 CoreAssetManager::CSS_HANDLE_DEFAULT,
373
-                is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
373
+                is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/style.css')
374 374
                     ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
375
-                    : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
375
+                    : EE_GLOBAL_ASSETS_URL.'css/espresso_default.css',
376 376
                 array('dashicons')
377 377
             );
378 378
             //Load custom style sheet if available
379 379
             if ($this->template_config->custom_style_sheet !== null) {
380 380
                 $this->addStylesheet(
381 381
                     CoreAssetManager::CSS_HANDLE_CUSTOM,
382
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
382
+                    EVENT_ESPRESSO_UPLOAD_URL.'css/'.$this->template_config->custom_style_sheet,
383 383
                     array(CoreAssetManager::CSS_HANDLE_DEFAULT)
384 384
                 );
385 385
             }
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
     {
403 403
         $this->addJavascript(
404 404
             CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
405
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
405
+            EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.min.js',
406 406
             array(CoreAssetManager::JS_HANDLE_JQUERY),
407 407
             true,
408 408
             '1.15.0'
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
 
411 411
         $this->addJavascript(
412 412
             CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
413
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
413
+            EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.additional-methods.min.js',
414 414
             array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE),
415 415
             true,
416 416
             '1.15.0'
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
         // @link http://josscrowcroft.github.io/accounting.js/
434 434
         $this->addJavascript(
435 435
             CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
436
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
436
+            EE_THIRD_PARTY_URL.'accounting/accounting.js',
437 437
             array(CoreAssetManager::JS_HANDLE_UNDERSCORE),
438 438
             true,
439 439
             '0.3.2'
@@ -441,11 +441,11 @@  discard block
 block discarded – undo
441 441
 
442 442
         $this->addJavascript(
443 443
             CoreAssetManager::JS_HANDLE_ACCOUNTING,
444
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
444
+            EE_GLOBAL_ASSETS_URL.'scripts/ee-accounting-config.js',
445 445
             array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
446 446
         )
447 447
         ->setInlineDataCallback(
448
-            function () {
448
+            function() {
449 449
                  wp_localize_script(
450 450
                      CoreAssetManager::JS_HANDLE_ACCOUNTING,
451 451
                      'EE_ACCOUNTING_CFG',
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -37,103 +37,103 @@
 block discarded – undo
37 37
  * @since           4.0
38 38
  */
39 39
 if (function_exists('espresso_version')) {
40
-    if (! function_exists('espresso_duplicate_plugin_error')) {
41
-        /**
42
-         *    espresso_duplicate_plugin_error
43
-         *    displays if more than one version of EE is activated at the same time
44
-         */
45
-        function espresso_duplicate_plugin_error()
46
-        {
47
-            ?>
40
+	if (! function_exists('espresso_duplicate_plugin_error')) {
41
+		/**
42
+		 *    espresso_duplicate_plugin_error
43
+		 *    displays if more than one version of EE is activated at the same time
44
+		 */
45
+		function espresso_duplicate_plugin_error()
46
+		{
47
+			?>
48 48
             <div class="error">
49 49
                 <p>
50 50
                     <?php
51
-                    echo esc_html__(
52
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
53
-                        'event_espresso'
54
-                    ); ?>
51
+					echo esc_html__(
52
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
53
+						'event_espresso'
54
+					); ?>
55 55
                 </p>
56 56
             </div>
57 57
             <?php
58
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
59
-        }
60
-    }
61
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
58
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
59
+		}
60
+	}
61
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
62 62
 } else {
63
-    define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
64
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
65
-        /**
66
-         * espresso_minimum_php_version_error
67
-         *
68
-         * @return void
69
-         */
70
-        function espresso_minimum_php_version_error()
71
-        {
72
-            ?>
63
+	define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
64
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
65
+		/**
66
+		 * espresso_minimum_php_version_error
67
+		 *
68
+		 * @return void
69
+		 */
70
+		function espresso_minimum_php_version_error()
71
+		{
72
+			?>
73 73
             <div class="error">
74 74
                 <p>
75 75
                     <?php
76
-                    printf(
77
-                        esc_html__(
78
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
79
-                            'event_espresso'
80
-                        ),
81
-                        EE_MIN_PHP_VER_REQUIRED,
82
-                        PHP_VERSION,
83
-                        '<br/>',
84
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
85
-                    );
86
-                    ?>
76
+					printf(
77
+						esc_html__(
78
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
79
+							'event_espresso'
80
+						),
81
+						EE_MIN_PHP_VER_REQUIRED,
82
+						PHP_VERSION,
83
+						'<br/>',
84
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
85
+					);
86
+					?>
87 87
                 </p>
88 88
             </div>
89 89
             <?php
90
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
91
-        }
90
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
91
+		}
92 92
 
93
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
94
-    } else {
95
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
96
-        /**
97
-         * espresso_version
98
-         * Returns the plugin version
99
-         *
100
-         * @return string
101
-         */
102
-        function espresso_version()
103
-        {
104
-            return apply_filters('FHEE__espresso__espresso_version', '4.10.2.rc.046');
105
-        }
93
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
94
+	} else {
95
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
96
+		/**
97
+		 * espresso_version
98
+		 * Returns the plugin version
99
+		 *
100
+		 * @return string
101
+		 */
102
+		function espresso_version()
103
+		{
104
+			return apply_filters('FHEE__espresso__espresso_version', '4.10.2.rc.046');
105
+		}
106 106
 
107
-        /**
108
-         * espresso_plugin_activation
109
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
110
-         */
111
-        function espresso_plugin_activation()
112
-        {
113
-            update_option('ee_espresso_activation', true);
114
-        }
107
+		/**
108
+		 * espresso_plugin_activation
109
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
110
+		 */
111
+		function espresso_plugin_activation()
112
+		{
113
+			update_option('ee_espresso_activation', true);
114
+		}
115 115
 
116
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
116
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117 117
 
118
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
119
-        bootstrap_espresso();
120
-    }
118
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
119
+		bootstrap_espresso();
120
+	}
121 121
 }
122 122
 if (! function_exists('espresso_deactivate_plugin')) {
123
-    /**
124
-     *    deactivate_plugin
125
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
126
-     *
127
-     * @access public
128
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
129
-     * @return    void
130
-     */
131
-    function espresso_deactivate_plugin($plugin_basename = '')
132
-    {
133
-        if (! function_exists('deactivate_plugins')) {
134
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
135
-        }
136
-        unset($_GET['activate'], $_REQUEST['activate']);
137
-        deactivate_plugins($plugin_basename);
138
-    }
123
+	/**
124
+	 *    deactivate_plugin
125
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
126
+	 *
127
+	 * @access public
128
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
129
+	 * @return    void
130
+	 */
131
+	function espresso_deactivate_plugin($plugin_basename = '')
132
+	{
133
+		if (! function_exists('deactivate_plugins')) {
134
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
135
+		}
136
+		unset($_GET['activate'], $_REQUEST['activate']);
137
+		deactivate_plugins($plugin_basename);
138
+	}
139 139
 }
Please login to merge, or discard this patch.