Completed
Pull Request — master (#1286)
by Darren
10:40
created
core/domain/services/assets/CoreAssetManager.php 1 patch
Indentation   +433 added lines, -433 removed lines patch added patch discarded remove patch
@@ -32,456 +32,456 @@
 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
-     * @since 4.9.62.p
171
-     * @throws DuplicateCollectionIdentifierException
172
-     * @throws InvalidDataTypeException
173
-     * @throws InvalidEntityException
174
-     */
175
-    public function addStylesheetFiles()
176
-    {
177
-        $this->loadCoreCss();
178
-    }
179
-
180
-
181
-    /**
182
-     * core default javascript
183
-     *
184
-     * @since 4.9.62.p
185
-     * @throws DomainException
186
-     * @throws DuplicateCollectionIdentifierException
187
-     * @throws InvalidArgumentException
188
-     * @throws InvalidDataTypeException
189
-     * @throws InvalidEntityException
190
-     * @throws InvalidInterfaceException
191
-     */
192
-    private function loadCoreJs()
193
-    {
194
-        // conditionally load third-party libraries that WP core MIGHT have.
195
-        $this->registerWpAssets();
196
-
197
-        $this->addJs(self::JS_HANDLE_JS_CORE)->setHasInlineData();
198
-        $this->addJs(self::JS_HANDLE_VENDOR);
199
-        $this->addJs(self::JS_HANDLE_VALIDATORS)->setRequiresTranslation();
200
-        $this->addJs(self::JS_HANDLE_HELPERS)->setRequiresTranslation();
201
-        $this->addJs(self::JS_HANDLE_MODEL)->setRequiresTranslation();
202
-        $this->addJs(self::JS_HANDLE_VALUE_OBJECTS)->setRequiresTranslation();
203
-        $this->addJs(self::JS_HANDLE_DATA_STORES)->setRequiresTranslation()->setInlineDataCallback(
204
-            function () {
205
-                wp_add_inline_script(
206
-                    CoreAssetManager::JS_HANDLE_DATA_STORES,
207
-                    is_admin()
208
-                        ? 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware( eejs.middleWares.apiFetch.CONTEXT_CAPS_EDIT ) )'
209
-                        : 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware )'
210
-                );
211
-            }
212
-        );
213
-        $this->addJs(self::JS_HANDLE_HOCS, self::JS_HANDLE_DATA_STORES)->setRequiresTranslation();
214
-        $this->addJs(self::JS_HANDLE_COMPONENTS, self::JS_HANDLE_DATA_STORES)->setRequiresTranslation();
215
-        $this->addJs(self::JS_HANDLE_EDITOR_HOCS)->setRequiresTranslation();
216
-
217
-        $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest'));
218
-        $this->registry->addData(
219
-            'paths',
220
-            array(
221
-                'base_rest_route' => rest_url(),
222
-                'rest_route' => rest_url('ee/v4.8.36/'),
223
-                'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(),
224
-                'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(),
225
-                'site_url' => site_url('/'),
226
-                'admin_url' => admin_url('/'),
227
-            )
228
-        );
229
-        // Event Espresso brand name
230
-        $this->registry->addData('brandName', Domain::brandName());
231
-        /** site formatting values **/
232
-        $this->registry->addData(
233
-            'site_formats',
234
-            array(
235
-                'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats()
236
-            )
237
-        );
238
-        /** currency data **/
239
-        $this->registry->addData(
240
-            'currency_config',
241
-            $this->getCurrencySettings()
242
-        );
243
-        /** site timezone */
244
-        $this->registry->addData(
245
-            'default_timezone',
246
-            array(
247
-                'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(),
248
-                'string' => get_option('timezone_string'),
249
-                'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(),
250
-            )
251
-        );
252
-        /** site locale (user locale if user logged in) */
253
-        $this->registry->addData(
254
-            'locale',
255
-            array(
256
-                'user' => get_user_locale(),
257
-                'site' => get_locale()
258
-            )
259
-        );
260
-
261
-        $this->addJavascript(
262
-            CoreAssetManager::JS_HANDLE_CORE,
263
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
264
-            array(CoreAssetManager::JS_HANDLE_JQUERY)
265
-        )
266
-        ->setInlineDataCallback(
267
-            function () {
268
-                wp_localize_script(
269
-                    CoreAssetManager::JS_HANDLE_CORE,
270
-                    CoreAssetManager::JS_HANDLE_I18N,
271
-                    EE_Registry::$i18n_js_strings
272
-                );
273
-            }
274
-        );
275
-    }
276
-
277
-
278
-    /**
279
-     * Registers vendor files that are bundled with a later version WP but might not be for the current version of
280
-     * WordPress in the running environment.
281
-     *
282
-     * @throws DuplicateCollectionIdentifierException
283
-     * @throws InvalidDataTypeException
284
-     * @throws InvalidEntityException
285
-     * @throws DomainException
286
-     * @since 4.9.71.p
287
-     */
288
-    private function registerWpAssets()
289
-    {
290
-        global $wp_version;
291
-        if (version_compare($wp_version, '5.0.beta', '>=')) {
292
-            return;
293
-        }
294
-        $this->addVendorJavascript(CoreAssetManager::JS_HANDLE_REACT)
295
-            ->setVersion('16.6.0');
296
-        $this->addVendorJavascript(
297
-            CoreAssetManager::JS_HANDLE_REACT_DOM,
298
-            array(CoreAssetManager::JS_HANDLE_REACT)
299
-        )->setVersion('16.6.0');
300
-        $this->addVendorJavascript(CoreAssetManager::JS_HANDLE_LODASH)
301
-            ->setInlineDataCallback(
302
-                function() {
303
-                    wp_add_inline_script(
304
-                        CoreAssetManager::JS_HANDLE_LODASH,
305
-                        'window.lodash = _.noConflict();'
306
-                    );
307
-                }
308
-            )
309
-            ->setVersion('4.17.11');
310
-    }
311
-
312
-
313
-    /**
314
-     * Returns configuration data for the accounting-js library.
315
-     * @since 4.9.71.p
316
-     * @return array
317
-     */
318
-    private function getAccountingSettings() {
319
-        return array(
320
-            'currency' => array(
321
-                'symbol'    => $this->currency_config->sign,
322
-                'format'    => array(
323
-                    'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
324
-                    'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
325
-                    'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
326
-                ),
327
-                'decimal'   => $this->currency_config->dec_mrk,
328
-                'thousand'  => $this->currency_config->thsnds,
329
-                'precision' => $this->currency_config->dec_plc,
330
-            ),
331
-            'number'   => array(
332
-                'precision' => $this->currency_config->dec_plc,
333
-                'thousand'  => $this->currency_config->thsnds,
334
-                'decimal'   => $this->currency_config->dec_mrk,
335
-            ),
336
-        );
337
-    }
338
-
339
-
340
-    /**
341
-     * Returns configuration data for the js Currency VO.
342
-     * @since 4.9.71.p
343
-     * @return array
344
-     */
345
-    private function getCurrencySettings()
346
-    {
347
-        return array(
348
-            'code' => $this->currency_config->code,
349
-            'singularLabel' => $this->currency_config->name,
350
-            'pluralLabel' => $this->currency_config->plural,
351
-            'sign' => $this->currency_config->sign,
352
-            'signB4' => $this->currency_config->sign_b4,
353
-            'decimalPlaces' => $this->currency_config->dec_plc,
354
-            'decimalMark' => $this->currency_config->dec_mrk,
355
-            'thousandsSeparator' => $this->currency_config->thsnds,
356
-        );
357
-    }
358
-
359
-
360
-    /**
361
-     * @since 4.9.62.p
362
-     * @throws DuplicateCollectionIdentifierException
363
-     * @throws InvalidDataTypeException
364
-     * @throws InvalidEntityException
365
-     */
366
-    private function loadCoreCss()
367
-    {
368
-        if ($this->template_config->enable_default_style && ! is_admin()) {
369
-            $this->addStylesheet(
370
-                CoreAssetManager::CSS_HANDLE_DEFAULT,
371
-                is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
372
-                    ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
373
-                    : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
374
-                array('dashicons')
375
-            );
376
-            //Load custom style sheet if available
377
-            if ($this->template_config->custom_style_sheet !== null) {
378
-                $this->addStylesheet(
379
-                    CoreAssetManager::CSS_HANDLE_CUSTOM,
380
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
381
-                    array(CoreAssetManager::CSS_HANDLE_DEFAULT)
382
-                );
383
-            }
384
-        }
385
-        $this->addCss(self::CSS_HANDLE_CORE_CSS_DEFAULT, 'dashicons');
386
-        $this->addCss(self::CSS_HANDLE_COMPONENTS, self::CSS_HANDLE_CORE_CSS_DEFAULT);
387
-    }
388
-
389
-
390
-    /**
391
-     * jQuery Validate for form validation
392
-     *
393
-     * @since 4.9.62.p
394
-     * @throws DomainException
395
-     * @throws DuplicateCollectionIdentifierException
396
-     * @throws InvalidDataTypeException
397
-     * @throws InvalidEntityException
398
-     */
399
-    private function loadJqueryValidate()
400
-    {
401
-        $this->addJavascript(
402
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
403
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
404
-            array(CoreAssetManager::JS_HANDLE_JQUERY)
405
-        )
406
-        ->setVersion('1.15.0');
407
-
408
-        $this->addJavascript(
409
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
410
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
411
-            array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE)
412
-        )
413
-        ->setVersion('1.15.0');
414
-    }
415
-
416
-
417
-    /**
418
-     * accounting.js for performing client-side calculations
419
-     *
420
-     * @since 4.9.62.p
421
-     * @throws DomainException
422
-     * @throws DuplicateCollectionIdentifierException
423
-     * @throws InvalidDataTypeException
424
-     * @throws InvalidEntityException
425
-     */
426
-    private function loadAccountingJs()
427
-    {
428
-        //accounting.js library
429
-        // @link http://josscrowcroft.github.io/accounting.js/
430
-        $this->addJavascript(
431
-            CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
432
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
433
-            array(CoreAssetManager::JS_HANDLE_UNDERSCORE)
434
-        )
435
-        ->setVersion('0.3.2');
436
-
437
-        $this->addJavascript(
438
-            CoreAssetManager::JS_HANDLE_ACCOUNTING,
439
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
440
-            array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
441
-        )
442
-        ->setInlineDataCallback(
443
-            function () {
444
-                 wp_localize_script(
445
-                     CoreAssetManager::JS_HANDLE_ACCOUNTING,
446
-                     'EE_ACCOUNTING_CFG',
447
-                     $this->getAccountingSettings()
448
-                 );
449
-            }
450
-        )
451
-        ->setVersion();
452
-    }
453
-
454
-
455
-    /**
456
-     * registers assets for cleaning your ears
457
-     *
458
-     * @param JavascriptAsset $script
459
-     */
460
-    public function loadQtipJs(JavascriptAsset $script)
461
-    {
462
-        // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
463
-        // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
464
-        if (
465
-            $script->handle() === CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE
466
-            && apply_filters('FHEE_load_qtip', false)
467
-        ) {
468
-            EEH_Qtip_Loader::instance()->register_and_enqueue();
469
-        }
470
-    }
471
-
472
-
473
-    /**
474
-     * assets that are used in the WordPress admin
475
-     *
476
-     * @since 4.9.62.p
477
-     * @throws DuplicateCollectionIdentifierException
478
-     * @throws InvalidDataTypeException
479
-     * @throws InvalidEntityException
480
-     */
481
-    private function registerAdminAssets()
482
-    {
483
-        $this->addJs(self::JS_HANDLE_WP_PLUGINS_PAGE)->setRequiresTranslation();
484
-        // note usage of the "JS_HANDLE.." constant is intentional here because css uses the same handle.
485
-        $this->addCss(self::JS_HANDLE_WP_PLUGINS_PAGE);
486
-    }
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
+	 * @since 4.9.62.p
171
+	 * @throws DuplicateCollectionIdentifierException
172
+	 * @throws InvalidDataTypeException
173
+	 * @throws InvalidEntityException
174
+	 */
175
+	public function addStylesheetFiles()
176
+	{
177
+		$this->loadCoreCss();
178
+	}
179
+
180
+
181
+	/**
182
+	 * core default javascript
183
+	 *
184
+	 * @since 4.9.62.p
185
+	 * @throws DomainException
186
+	 * @throws DuplicateCollectionIdentifierException
187
+	 * @throws InvalidArgumentException
188
+	 * @throws InvalidDataTypeException
189
+	 * @throws InvalidEntityException
190
+	 * @throws InvalidInterfaceException
191
+	 */
192
+	private function loadCoreJs()
193
+	{
194
+		// conditionally load third-party libraries that WP core MIGHT have.
195
+		$this->registerWpAssets();
196
+
197
+		$this->addJs(self::JS_HANDLE_JS_CORE)->setHasInlineData();
198
+		$this->addJs(self::JS_HANDLE_VENDOR);
199
+		$this->addJs(self::JS_HANDLE_VALIDATORS)->setRequiresTranslation();
200
+		$this->addJs(self::JS_HANDLE_HELPERS)->setRequiresTranslation();
201
+		$this->addJs(self::JS_HANDLE_MODEL)->setRequiresTranslation();
202
+		$this->addJs(self::JS_HANDLE_VALUE_OBJECTS)->setRequiresTranslation();
203
+		$this->addJs(self::JS_HANDLE_DATA_STORES)->setRequiresTranslation()->setInlineDataCallback(
204
+			function () {
205
+				wp_add_inline_script(
206
+					CoreAssetManager::JS_HANDLE_DATA_STORES,
207
+					is_admin()
208
+						? 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware( eejs.middleWares.apiFetch.CONTEXT_CAPS_EDIT ) )'
209
+						: 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware )'
210
+				);
211
+			}
212
+		);
213
+		$this->addJs(self::JS_HANDLE_HOCS, self::JS_HANDLE_DATA_STORES)->setRequiresTranslation();
214
+		$this->addJs(self::JS_HANDLE_COMPONENTS, self::JS_HANDLE_DATA_STORES)->setRequiresTranslation();
215
+		$this->addJs(self::JS_HANDLE_EDITOR_HOCS)->setRequiresTranslation();
216
+
217
+		$this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest'));
218
+		$this->registry->addData(
219
+			'paths',
220
+			array(
221
+				'base_rest_route' => rest_url(),
222
+				'rest_route' => rest_url('ee/v4.8.36/'),
223
+				'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(),
224
+				'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(),
225
+				'site_url' => site_url('/'),
226
+				'admin_url' => admin_url('/'),
227
+			)
228
+		);
229
+		// Event Espresso brand name
230
+		$this->registry->addData('brandName', Domain::brandName());
231
+		/** site formatting values **/
232
+		$this->registry->addData(
233
+			'site_formats',
234
+			array(
235
+				'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats()
236
+			)
237
+		);
238
+		/** currency data **/
239
+		$this->registry->addData(
240
+			'currency_config',
241
+			$this->getCurrencySettings()
242
+		);
243
+		/** site timezone */
244
+		$this->registry->addData(
245
+			'default_timezone',
246
+			array(
247
+				'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(),
248
+				'string' => get_option('timezone_string'),
249
+				'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(),
250
+			)
251
+		);
252
+		/** site locale (user locale if user logged in) */
253
+		$this->registry->addData(
254
+			'locale',
255
+			array(
256
+				'user' => get_user_locale(),
257
+				'site' => get_locale()
258
+			)
259
+		);
260
+
261
+		$this->addJavascript(
262
+			CoreAssetManager::JS_HANDLE_CORE,
263
+			EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
264
+			array(CoreAssetManager::JS_HANDLE_JQUERY)
265
+		)
266
+		->setInlineDataCallback(
267
+			function () {
268
+				wp_localize_script(
269
+					CoreAssetManager::JS_HANDLE_CORE,
270
+					CoreAssetManager::JS_HANDLE_I18N,
271
+					EE_Registry::$i18n_js_strings
272
+				);
273
+			}
274
+		);
275
+	}
276
+
277
+
278
+	/**
279
+	 * Registers vendor files that are bundled with a later version WP but might not be for the current version of
280
+	 * WordPress in the running environment.
281
+	 *
282
+	 * @throws DuplicateCollectionIdentifierException
283
+	 * @throws InvalidDataTypeException
284
+	 * @throws InvalidEntityException
285
+	 * @throws DomainException
286
+	 * @since 4.9.71.p
287
+	 */
288
+	private function registerWpAssets()
289
+	{
290
+		global $wp_version;
291
+		if (version_compare($wp_version, '5.0.beta', '>=')) {
292
+			return;
293
+		}
294
+		$this->addVendorJavascript(CoreAssetManager::JS_HANDLE_REACT)
295
+			->setVersion('16.6.0');
296
+		$this->addVendorJavascript(
297
+			CoreAssetManager::JS_HANDLE_REACT_DOM,
298
+			array(CoreAssetManager::JS_HANDLE_REACT)
299
+		)->setVersion('16.6.0');
300
+		$this->addVendorJavascript(CoreAssetManager::JS_HANDLE_LODASH)
301
+			->setInlineDataCallback(
302
+				function() {
303
+					wp_add_inline_script(
304
+						CoreAssetManager::JS_HANDLE_LODASH,
305
+						'window.lodash = _.noConflict();'
306
+					);
307
+				}
308
+			)
309
+			->setVersion('4.17.11');
310
+	}
311
+
312
+
313
+	/**
314
+	 * Returns configuration data for the accounting-js library.
315
+	 * @since 4.9.71.p
316
+	 * @return array
317
+	 */
318
+	private function getAccountingSettings() {
319
+		return array(
320
+			'currency' => array(
321
+				'symbol'    => $this->currency_config->sign,
322
+				'format'    => array(
323
+					'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
324
+					'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
325
+					'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
326
+				),
327
+				'decimal'   => $this->currency_config->dec_mrk,
328
+				'thousand'  => $this->currency_config->thsnds,
329
+				'precision' => $this->currency_config->dec_plc,
330
+			),
331
+			'number'   => array(
332
+				'precision' => $this->currency_config->dec_plc,
333
+				'thousand'  => $this->currency_config->thsnds,
334
+				'decimal'   => $this->currency_config->dec_mrk,
335
+			),
336
+		);
337
+	}
338
+
339
+
340
+	/**
341
+	 * Returns configuration data for the js Currency VO.
342
+	 * @since 4.9.71.p
343
+	 * @return array
344
+	 */
345
+	private function getCurrencySettings()
346
+	{
347
+		return array(
348
+			'code' => $this->currency_config->code,
349
+			'singularLabel' => $this->currency_config->name,
350
+			'pluralLabel' => $this->currency_config->plural,
351
+			'sign' => $this->currency_config->sign,
352
+			'signB4' => $this->currency_config->sign_b4,
353
+			'decimalPlaces' => $this->currency_config->dec_plc,
354
+			'decimalMark' => $this->currency_config->dec_mrk,
355
+			'thousandsSeparator' => $this->currency_config->thsnds,
356
+		);
357
+	}
358
+
359
+
360
+	/**
361
+	 * @since 4.9.62.p
362
+	 * @throws DuplicateCollectionIdentifierException
363
+	 * @throws InvalidDataTypeException
364
+	 * @throws InvalidEntityException
365
+	 */
366
+	private function loadCoreCss()
367
+	{
368
+		if ($this->template_config->enable_default_style && ! is_admin()) {
369
+			$this->addStylesheet(
370
+				CoreAssetManager::CSS_HANDLE_DEFAULT,
371
+				is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
372
+					? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
373
+					: EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
374
+				array('dashicons')
375
+			);
376
+			//Load custom style sheet if available
377
+			if ($this->template_config->custom_style_sheet !== null) {
378
+				$this->addStylesheet(
379
+					CoreAssetManager::CSS_HANDLE_CUSTOM,
380
+					EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
381
+					array(CoreAssetManager::CSS_HANDLE_DEFAULT)
382
+				);
383
+			}
384
+		}
385
+		$this->addCss(self::CSS_HANDLE_CORE_CSS_DEFAULT, 'dashicons');
386
+		$this->addCss(self::CSS_HANDLE_COMPONENTS, self::CSS_HANDLE_CORE_CSS_DEFAULT);
387
+	}
388
+
389
+
390
+	/**
391
+	 * jQuery Validate for form validation
392
+	 *
393
+	 * @since 4.9.62.p
394
+	 * @throws DomainException
395
+	 * @throws DuplicateCollectionIdentifierException
396
+	 * @throws InvalidDataTypeException
397
+	 * @throws InvalidEntityException
398
+	 */
399
+	private function loadJqueryValidate()
400
+	{
401
+		$this->addJavascript(
402
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
403
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
404
+			array(CoreAssetManager::JS_HANDLE_JQUERY)
405
+		)
406
+		->setVersion('1.15.0');
407
+
408
+		$this->addJavascript(
409
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
410
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
411
+			array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE)
412
+		)
413
+		->setVersion('1.15.0');
414
+	}
415
+
416
+
417
+	/**
418
+	 * accounting.js for performing client-side calculations
419
+	 *
420
+	 * @since 4.9.62.p
421
+	 * @throws DomainException
422
+	 * @throws DuplicateCollectionIdentifierException
423
+	 * @throws InvalidDataTypeException
424
+	 * @throws InvalidEntityException
425
+	 */
426
+	private function loadAccountingJs()
427
+	{
428
+		//accounting.js library
429
+		// @link http://josscrowcroft.github.io/accounting.js/
430
+		$this->addJavascript(
431
+			CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
432
+			EE_THIRD_PARTY_URL . 'accounting/accounting.js',
433
+			array(CoreAssetManager::JS_HANDLE_UNDERSCORE)
434
+		)
435
+		->setVersion('0.3.2');
436
+
437
+		$this->addJavascript(
438
+			CoreAssetManager::JS_HANDLE_ACCOUNTING,
439
+			EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
440
+			array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
441
+		)
442
+		->setInlineDataCallback(
443
+			function () {
444
+				 wp_localize_script(
445
+					 CoreAssetManager::JS_HANDLE_ACCOUNTING,
446
+					 'EE_ACCOUNTING_CFG',
447
+					 $this->getAccountingSettings()
448
+				 );
449
+			}
450
+		)
451
+		->setVersion();
452
+	}
453
+
454
+
455
+	/**
456
+	 * registers assets for cleaning your ears
457
+	 *
458
+	 * @param JavascriptAsset $script
459
+	 */
460
+	public function loadQtipJs(JavascriptAsset $script)
461
+	{
462
+		// qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
463
+		// can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
464
+		if (
465
+			$script->handle() === CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE
466
+			&& apply_filters('FHEE_load_qtip', false)
467
+		) {
468
+			EEH_Qtip_Loader::instance()->register_and_enqueue();
469
+		}
470
+	}
471
+
472
+
473
+	/**
474
+	 * assets that are used in the WordPress admin
475
+	 *
476
+	 * @since 4.9.62.p
477
+	 * @throws DuplicateCollectionIdentifierException
478
+	 * @throws InvalidDataTypeException
479
+	 * @throws InvalidEntityException
480
+	 */
481
+	private function registerAdminAssets()
482
+	{
483
+		$this->addJs(self::JS_HANDLE_WP_PLUGINS_PAGE)->setRequiresTranslation();
484
+		// note usage of the "JS_HANDLE.." constant is intentional here because css uses the same handle.
485
+		$this->addCss(self::JS_HANDLE_WP_PLUGINS_PAGE);
486
+	}
487 487
 }
Please login to merge, or discard this patch.
core/services/assets/BlockAssetManager.php 2 patches
Indentation   +244 added lines, -244 removed lines patch added patch discarded remove patch
@@ -22,249 +22,249 @@
 block discarded – undo
22 22
 abstract class BlockAssetManager extends AssetManager implements BlockAssetManagerInterface
23 23
 {
24 24
 
25
-    /**
26
-     * @var string $editor_script_handle
27
-     */
28
-    private $editor_script_handle;
29
-
30
-    /**
31
-     * @var string $editor_style_handle
32
-     */
33
-    private $editor_style_handle;
34
-
35
-    /**
36
-     * @var string $script_handle
37
-     */
38
-    private $script_handle;
39
-
40
-    /**
41
-     * @var string $style_handle
42
-     */
43
-    private $style_handle;
44
-
45
-
46
-    /**
47
-     * @return string
48
-     */
49
-    public function getEditorScriptHandle()
50
-    {
51
-        return $this->editor_script_handle;
52
-    }
53
-
54
-
55
-    /**
56
-     * @param string $editor_script_handle
57
-     */
58
-    public function setEditorScriptHandle($editor_script_handle)
59
-    {
60
-        if(strpos($editor_script_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
61
-            $editor_script_handle = BlockInterface::NAME_SPACE . '-' . $editor_script_handle;
62
-        }
63
-        $this->editor_script_handle = $editor_script_handle;
64
-    }
65
-
66
-
67
-    /**
68
-     * @return string
69
-     */
70
-    public function getEditorStyleHandle()
71
-    {
72
-        return $this->editor_style_handle;
73
-    }
74
-
75
-
76
-    /**
77
-     * @param string $editor_style_handle
78
-     */
79
-    public function setEditorStyleHandle($editor_style_handle)
80
-    {
81
-        if (strpos($editor_style_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
82
-            $editor_style_handle = BlockInterface::NAME_SPACE . '-' . $editor_style_handle;
83
-        }
84
-        $this->editor_style_handle = $editor_style_handle;
85
-    }
86
-
87
-
88
-    /**
89
-     * @return string
90
-     */
91
-    public function getScriptHandle()
92
-    {
93
-        return $this->script_handle;
94
-    }
95
-
96
-
97
-    /**
98
-     * @param string $script_handle
99
-     */
100
-    public function setScriptHandle($script_handle)
101
-    {
102
-        if (strpos($script_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
103
-            $script_handle = BlockInterface::NAME_SPACE . '-' . $script_handle;
104
-        }
105
-        $this->script_handle = $script_handle;
106
-    }
107
-
108
-
109
-    /**
110
-     * @return string
111
-     */
112
-    public function getStyleHandle()
113
-    {
114
-        return $this->style_handle;
115
-    }
116
-
117
-
118
-    /**
119
-     * @param string $style_handle
120
-     */
121
-    public function setStyleHandle($style_handle)
122
-    {
123
-        if (strpos($style_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
124
-            $style_handle = BlockInterface::NAME_SPACE . '-' . $style_handle;
125
-        }
126
-        $this->style_handle = $style_handle;
127
-    }
128
-
129
-    /**
130
-     * @since 4.9.71.p
131
-     * @throws InvalidDataTypeException
132
-     * @throws InvalidEntityException
133
-     * @throws DuplicateCollectionIdentifierException
134
-     */
135
-    public function addAssets()
136
-    {
137
-        $this->addEditorScript($this->getEditorScriptHandle());
138
-        $this->addEditorStyle($this->getEditorStyleHandle());
139
-        $this->addScript($this->getScriptHandle());
140
-        $this->addStyle($this->getStyleHandle());
141
-    }
142
-
143
-
144
-    /**
145
-     * @param       $handle
146
-     * @param array $dependencies
147
-     * @since 4.9.71.p
148
-     * @return JavascriptAsset
149
-     * @throws InvalidDataTypeException
150
-     * @throws InvalidEntityException
151
-     * @throws DuplicateCollectionIdentifierException
152
-     */
153
-    public function addEditorScript($handle, array $dependencies = array())
154
-    {
155
-        if ($this->assets->hasJavascriptAsset($handle)){
156
-            return $this->assets->getJavascriptAsset($handle);
157
-        }
158
-        return $this->addJs($handle, $dependencies)->setRequiresTranslation();
159
-    }
160
-
161
-
162
-    /**
163
-     * @param        $handle
164
-     * @param array  $dependencies
165
-     * @since 4.9.71.p
166
-     * @return StylesheetAsset
167
-     * @throws InvalidDataTypeException
168
-     * @throws InvalidEntityException
169
-     * @throws DuplicateCollectionIdentifierException
170
-     */
171
-    public function addEditorStyle($handle, array $dependencies = array())
172
-    {
173
-        if ($this->assets->hasStylesheetAsset($handle)) {
174
-            return $this->assets->getStylesheetAsset($handle);
175
-        }
176
-        return $this->addCss($handle, $dependencies);
177
-    }
178
-
179
-
180
-    /**
181
-     * @param       $handle
182
-     * @param array $dependencies
183
-     * @since 4.9.71.p
184
-     * @return JavascriptAsset
185
-     * @throws InvalidDataTypeException
186
-     * @throws InvalidEntityException
187
-     * @throws DuplicateCollectionIdentifierException
188
-     */
189
-    public function addScript($handle, array $dependencies = array())
190
-    {
191
-        if ($this->assets->hasJavascriptAsset($handle)) {
192
-            return $this->assets->getJavascriptAsset($handle);
193
-        }
194
-        return $this->addJs($handle, $dependencies)->setRequiresTranslation();
195
-    }
196
-
197
-
198
-    /**
199
-     * @param        $handle
200
-     * @param array  $dependencies
201
-     * @since 4.9.71.p
202
-     * @return StylesheetAsset
203
-     * @throws InvalidDataTypeException
204
-     * @throws InvalidEntityException
205
-     * @throws DuplicateCollectionIdentifierException
206
-     */
207
-    public function addStyle($handle, array $dependencies = array())
208
-    {
209
-        if ($this->assets->hasStylesheetAsset($handle)) {
210
-            return $this->assets->getStylesheetAsset($handle);
211
-        }
212
-        return $this->addCss($handle, $dependencies);
213
-    }
214
-
215
-
216
-    /**
217
-     * @return JavascriptAsset|null
218
-     */
219
-    public function getEditorScript()
220
-    {
221
-        return $this->assets->getJavascriptAsset($this->editor_script_handle);
222
-    }
223
-
224
-
225
-    /**
226
-     * @return StylesheetAsset|null
227
-     */
228
-    public function getEditorStyle()
229
-    {
230
-        return $this->assets->getStylesheetAsset($this->editor_style_handle);
231
-    }
232
-
233
-
234
-    /**
235
-     * @return JavascriptAsset|null
236
-     */
237
-    public function getScript()
238
-    {
239
-        return $this->assets->getJavascriptAsset($this->script_handle);
240
-    }
241
-
242
-
243
-    /**
244
-     * @return StylesheetAsset|null
245
-     */
246
-    public function getStyle()
247
-    {
248
-        return $this->assets->getStylesheetAsset($this->style_handle);
249
-    }
250
-
251
-
252
-    /**
253
-     * @return  void
254
-     */
255
-    public function enqueueAssets()
256
-    {
257
-        $assets = array(
258
-            $this->getEditorScript(),
259
-            $this->getEditorStyle(),
260
-            $this->getScript(),
261
-            $this->getStyle(),
262
-        );
263
-        foreach ($assets as $asset) {
264
-            if ($asset instanceof BrowserAsset && $asset->isRegistered()) {
265
-                $asset->enqueueAsset();
266
-            }
267
-        }
268
-    }
25
+	/**
26
+	 * @var string $editor_script_handle
27
+	 */
28
+	private $editor_script_handle;
29
+
30
+	/**
31
+	 * @var string $editor_style_handle
32
+	 */
33
+	private $editor_style_handle;
34
+
35
+	/**
36
+	 * @var string $script_handle
37
+	 */
38
+	private $script_handle;
39
+
40
+	/**
41
+	 * @var string $style_handle
42
+	 */
43
+	private $style_handle;
44
+
45
+
46
+	/**
47
+	 * @return string
48
+	 */
49
+	public function getEditorScriptHandle()
50
+	{
51
+		return $this->editor_script_handle;
52
+	}
53
+
54
+
55
+	/**
56
+	 * @param string $editor_script_handle
57
+	 */
58
+	public function setEditorScriptHandle($editor_script_handle)
59
+	{
60
+		if(strpos($editor_script_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
61
+			$editor_script_handle = BlockInterface::NAME_SPACE . '-' . $editor_script_handle;
62
+		}
63
+		$this->editor_script_handle = $editor_script_handle;
64
+	}
65
+
66
+
67
+	/**
68
+	 * @return string
69
+	 */
70
+	public function getEditorStyleHandle()
71
+	{
72
+		return $this->editor_style_handle;
73
+	}
74
+
75
+
76
+	/**
77
+	 * @param string $editor_style_handle
78
+	 */
79
+	public function setEditorStyleHandle($editor_style_handle)
80
+	{
81
+		if (strpos($editor_style_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
82
+			$editor_style_handle = BlockInterface::NAME_SPACE . '-' . $editor_style_handle;
83
+		}
84
+		$this->editor_style_handle = $editor_style_handle;
85
+	}
86
+
87
+
88
+	/**
89
+	 * @return string
90
+	 */
91
+	public function getScriptHandle()
92
+	{
93
+		return $this->script_handle;
94
+	}
95
+
96
+
97
+	/**
98
+	 * @param string $script_handle
99
+	 */
100
+	public function setScriptHandle($script_handle)
101
+	{
102
+		if (strpos($script_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
103
+			$script_handle = BlockInterface::NAME_SPACE . '-' . $script_handle;
104
+		}
105
+		$this->script_handle = $script_handle;
106
+	}
107
+
108
+
109
+	/**
110
+	 * @return string
111
+	 */
112
+	public function getStyleHandle()
113
+	{
114
+		return $this->style_handle;
115
+	}
116
+
117
+
118
+	/**
119
+	 * @param string $style_handle
120
+	 */
121
+	public function setStyleHandle($style_handle)
122
+	{
123
+		if (strpos($style_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
124
+			$style_handle = BlockInterface::NAME_SPACE . '-' . $style_handle;
125
+		}
126
+		$this->style_handle = $style_handle;
127
+	}
128
+
129
+	/**
130
+	 * @since 4.9.71.p
131
+	 * @throws InvalidDataTypeException
132
+	 * @throws InvalidEntityException
133
+	 * @throws DuplicateCollectionIdentifierException
134
+	 */
135
+	public function addAssets()
136
+	{
137
+		$this->addEditorScript($this->getEditorScriptHandle());
138
+		$this->addEditorStyle($this->getEditorStyleHandle());
139
+		$this->addScript($this->getScriptHandle());
140
+		$this->addStyle($this->getStyleHandle());
141
+	}
142
+
143
+
144
+	/**
145
+	 * @param       $handle
146
+	 * @param array $dependencies
147
+	 * @since 4.9.71.p
148
+	 * @return JavascriptAsset
149
+	 * @throws InvalidDataTypeException
150
+	 * @throws InvalidEntityException
151
+	 * @throws DuplicateCollectionIdentifierException
152
+	 */
153
+	public function addEditorScript($handle, array $dependencies = array())
154
+	{
155
+		if ($this->assets->hasJavascriptAsset($handle)){
156
+			return $this->assets->getJavascriptAsset($handle);
157
+		}
158
+		return $this->addJs($handle, $dependencies)->setRequiresTranslation();
159
+	}
160
+
161
+
162
+	/**
163
+	 * @param        $handle
164
+	 * @param array  $dependencies
165
+	 * @since 4.9.71.p
166
+	 * @return StylesheetAsset
167
+	 * @throws InvalidDataTypeException
168
+	 * @throws InvalidEntityException
169
+	 * @throws DuplicateCollectionIdentifierException
170
+	 */
171
+	public function addEditorStyle($handle, array $dependencies = array())
172
+	{
173
+		if ($this->assets->hasStylesheetAsset($handle)) {
174
+			return $this->assets->getStylesheetAsset($handle);
175
+		}
176
+		return $this->addCss($handle, $dependencies);
177
+	}
178
+
179
+
180
+	/**
181
+	 * @param       $handle
182
+	 * @param array $dependencies
183
+	 * @since 4.9.71.p
184
+	 * @return JavascriptAsset
185
+	 * @throws InvalidDataTypeException
186
+	 * @throws InvalidEntityException
187
+	 * @throws DuplicateCollectionIdentifierException
188
+	 */
189
+	public function addScript($handle, array $dependencies = array())
190
+	{
191
+		if ($this->assets->hasJavascriptAsset($handle)) {
192
+			return $this->assets->getJavascriptAsset($handle);
193
+		}
194
+		return $this->addJs($handle, $dependencies)->setRequiresTranslation();
195
+	}
196
+
197
+
198
+	/**
199
+	 * @param        $handle
200
+	 * @param array  $dependencies
201
+	 * @since 4.9.71.p
202
+	 * @return StylesheetAsset
203
+	 * @throws InvalidDataTypeException
204
+	 * @throws InvalidEntityException
205
+	 * @throws DuplicateCollectionIdentifierException
206
+	 */
207
+	public function addStyle($handle, array $dependencies = array())
208
+	{
209
+		if ($this->assets->hasStylesheetAsset($handle)) {
210
+			return $this->assets->getStylesheetAsset($handle);
211
+		}
212
+		return $this->addCss($handle, $dependencies);
213
+	}
214
+
215
+
216
+	/**
217
+	 * @return JavascriptAsset|null
218
+	 */
219
+	public function getEditorScript()
220
+	{
221
+		return $this->assets->getJavascriptAsset($this->editor_script_handle);
222
+	}
223
+
224
+
225
+	/**
226
+	 * @return StylesheetAsset|null
227
+	 */
228
+	public function getEditorStyle()
229
+	{
230
+		return $this->assets->getStylesheetAsset($this->editor_style_handle);
231
+	}
232
+
233
+
234
+	/**
235
+	 * @return JavascriptAsset|null
236
+	 */
237
+	public function getScript()
238
+	{
239
+		return $this->assets->getJavascriptAsset($this->script_handle);
240
+	}
241
+
242
+
243
+	/**
244
+	 * @return StylesheetAsset|null
245
+	 */
246
+	public function getStyle()
247
+	{
248
+		return $this->assets->getStylesheetAsset($this->style_handle);
249
+	}
250
+
251
+
252
+	/**
253
+	 * @return  void
254
+	 */
255
+	public function enqueueAssets()
256
+	{
257
+		$assets = array(
258
+			$this->getEditorScript(),
259
+			$this->getEditorStyle(),
260
+			$this->getScript(),
261
+			$this->getStyle(),
262
+		);
263
+		foreach ($assets as $asset) {
264
+			if ($asset instanceof BrowserAsset && $asset->isRegistered()) {
265
+				$asset->enqueueAsset();
266
+			}
267
+		}
268
+	}
269 269
 
270 270
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -57,8 +57,8 @@  discard block
 block discarded – undo
57 57
      */
58 58
     public function setEditorScriptHandle($editor_script_handle)
59 59
     {
60
-        if(strpos($editor_script_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
61
-            $editor_script_handle = BlockInterface::NAME_SPACE . '-' . $editor_script_handle;
60
+        if (strpos($editor_script_handle, BlockInterface::NAME_SPACE.'-') !== 0) {
61
+            $editor_script_handle = BlockInterface::NAME_SPACE.'-'.$editor_script_handle;
62 62
         }
63 63
         $this->editor_script_handle = $editor_script_handle;
64 64
     }
@@ -78,8 +78,8 @@  discard block
 block discarded – undo
78 78
      */
79 79
     public function setEditorStyleHandle($editor_style_handle)
80 80
     {
81
-        if (strpos($editor_style_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
82
-            $editor_style_handle = BlockInterface::NAME_SPACE . '-' . $editor_style_handle;
81
+        if (strpos($editor_style_handle, BlockInterface::NAME_SPACE.'-') !== 0) {
82
+            $editor_style_handle = BlockInterface::NAME_SPACE.'-'.$editor_style_handle;
83 83
         }
84 84
         $this->editor_style_handle = $editor_style_handle;
85 85
     }
@@ -99,8 +99,8 @@  discard block
 block discarded – undo
99 99
      */
100 100
     public function setScriptHandle($script_handle)
101 101
     {
102
-        if (strpos($script_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
103
-            $script_handle = BlockInterface::NAME_SPACE . '-' . $script_handle;
102
+        if (strpos($script_handle, BlockInterface::NAME_SPACE.'-') !== 0) {
103
+            $script_handle = BlockInterface::NAME_SPACE.'-'.$script_handle;
104 104
         }
105 105
         $this->script_handle = $script_handle;
106 106
     }
@@ -120,8 +120,8 @@  discard block
 block discarded – undo
120 120
      */
121 121
     public function setStyleHandle($style_handle)
122 122
     {
123
-        if (strpos($style_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
124
-            $style_handle = BlockInterface::NAME_SPACE . '-' . $style_handle;
123
+        if (strpos($style_handle, BlockInterface::NAME_SPACE.'-') !== 0) {
124
+            $style_handle = BlockInterface::NAME_SPACE.'-'.$style_handle;
125 125
         }
126 126
         $this->style_handle = $style_handle;
127 127
     }
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
      */
153 153
     public function addEditorScript($handle, array $dependencies = array())
154 154
     {
155
-        if ($this->assets->hasJavascriptAsset($handle)){
155
+        if ($this->assets->hasJavascriptAsset($handle)) {
156 156
             return $this->assets->getJavascriptAsset($handle);
157 157
         }
158 158
         return $this->addJs($handle, $dependencies)->setRequiresTranslation();
Please login to merge, or discard this patch.
core/services/assets/Registry.php 2 patches
Indentation   +731 added lines, -731 removed lines patch added patch discarded remove patch
@@ -27,742 +27,742 @@
 block discarded – undo
27 27
 class Registry
28 28
 {
29 29
 
30
-    const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json';
31
-
32
-    /**
33
-     * @var AssetCollection $assets
34
-     */
35
-    protected $assets;
36
-
37
-    /**
38
-     * @var I18nRegistry
39
-     */
40
-    private $i18n_registry;
41
-
42
-    /**
43
-     * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
44
-     *
45
-     * @var array
46
-     */
47
-    protected $jsdata = array();
48
-
49
-    /**
50
-     * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
51
-     * page source.
52
-     *
53
-     * @var array
54
-     */
55
-    private $script_handles_with_data = array();
56
-
57
-
58
-    /**
59
-     * Holds the manifest data obtained from registered manifest files.
60
-     * Manifests are maps of asset chunk name to actual built asset file names.
61
-     * Shape of this array is:
62
-     * array(
63
-     *  'some_namespace_slug' => array(
64
-     *      'some_chunk_name' => array(
65
-     *          'js' => 'filename.js'
66
-     *          'css' => 'filename.js'
67
-     *      ),
68
-     *      'url_base' => 'https://baseurl.com/to/assets
69
-     *  )
70
-     * )
71
-     *
72
-     * @var array
73
-     */
74
-    private $manifest_data = array();
75
-
76
-
77
-    /**
78
-     * Holds any dependency data obtained from registered dependency map json.
79
-     * Dependency map json is generated via the @wordpress/dependency-extraction-webpack-plugin via the webpack config.
80
-     * @see https://github.com/WordPress/gutenberg/tree/master/packages/dependency-extraction-webpack-plugin
81
-     *
82
-     * @var array
83
-     */
84
-    private $dependencies_data = [];
85
-
86
-
87
-    /**
88
-     * This is a known array of possible wp css handles that correspond to what may be exposed as dependencies in our
89
-     * build process.  Currently the dependency export process in webpack does not consider css imports, so we derive
90
-     * them via the js dependencies (WP uses the same handle for both js and css). This is a list of known handles that
91
-     * are used for both js and css.
92
-     * @var array
93
-     */
94
-    private $wp_css_handle_dependencies = [
95
-        'wp-components',
96
-        'wp-block-editor',
97
-        'wp-block-library',
98
-        'wp-edit-post',
99
-        'wp-edit-widgets',
100
-        'wp-editor',
101
-        'wp-format-library',
102
-        'wp-list-reusable-blocks',
103
-        'wp-nux',
104
-    ];
105
-
106
-
107
-    /**
108
-     * Registry constructor.
109
-     * Hooking into WP actions for script registry.
110
-     *
111
-     * @param AssetCollection      $assets
112
-     * @param I18nRegistry         $i18n_registry
113
-     * @throws InvalidArgumentException
114
-     * @throws InvalidDataTypeException
115
-     * @throws InvalidInterfaceException
116
-     */
117
-    public function __construct(AssetCollection $assets, I18nRegistry $i18n_registry)
118
-    {
119
-        $this->assets = $assets;
120
-        $this->i18n_registry = $i18n_registry;
121
-        add_action('wp_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
122
-        add_action('admin_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
123
-        add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
124
-        add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
125
-        add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 4);
126
-        add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 4);
127
-        add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
128
-        add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
129
-    }
130
-
131
-
132
-    /**
133
-     * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n
134
-     * translation handling.
135
-     *
136
-     * @return I18nRegistry
137
-     */
138
-    public function getI18nRegistry()
139
-    {
140
-        return $this->i18n_registry;
141
-    }
142
-
143
-
144
-    /**
145
-     * Callback for the wp_enqueue_scripts actions used to register assets.
146
-     *
147
-     * @since 4.9.62.p
148
-     * @throws Exception
149
-     */
150
-    public function registerScriptsAndStyles()
151
-    {
152
-        try {
153
-            $this->registerScripts($this->assets->getJavascriptAssets());
154
-            $this->registerStyles($this->assets->getStylesheetAssets());
155
-        } catch (Exception $exception) {
156
-            new ExceptionStackTraceDisplay($exception);
157
-        }
158
-    }
159
-
160
-
161
-    /**
162
-     * Registers JS assets with WP core
163
-     *
164
-     * @since 4.9.62.p
165
-     * @param JavascriptAsset[] $scripts
166
-     * @throws AssetRegistrationException
167
-     * @throws InvalidDataTypeException
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
-     * @since 4.9.62.p
206
-     * @param StylesheetAsset[] $styles
207
-     * @throws InvalidDataTypeException
208
-     */
209
-    public function registerStyles(array $styles)
210
-    {
211
-        foreach ($styles as $style) {
212
-            // skip to next style if this has already been done
213
-            if ($style->isRegistered()) {
214
-                continue;
215
-            }
216
-            do_action(
217
-                'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style',
218
-                $style
219
-            );
220
-            wp_register_style(
221
-                $style->handle(),
222
-                $style->source(),
223
-                $style->dependencies(),
224
-                $style->version(),
225
-                $style->media()
226
-            );
227
-            $style->setRegistered();
228
-            do_action(
229
-                'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style',
230
-                $style
231
-            );
232
-        }
233
-    }
234
-
235
-
236
-    /**
237
-     * Call back for the script print in frontend and backend.
238
-     * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
239
-     *
240
-     * @since 4.9.31.rc.015
241
-     */
242
-    public function enqueueData()
243
-    {
244
-        $this->removeAlreadyRegisteredDataForScriptHandles();
245
-        wp_add_inline_script(
246
-            'eejs-core',
247
-            'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)),
248
-            'before'
249
-        );
250
-        $scripts = $this->assets->getJavascriptAssetsWithData();
251
-        foreach ($scripts as $script) {
252
-            $this->addRegisteredScriptHandlesWithData($script->handle());
253
-            if ($script->hasInlineDataCallback()) {
254
-                $localize = $script->inlineDataCallback();
255
-                $localize();
256
-            }
257
-        }
258
-    }
259
-
260
-
261
-    /**
262
-     * Used to add data to eejs.data object.
263
-     * Note:  Overriding existing data is not allowed.
264
-     * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
265
-     * If the data you add is something like this:
266
-     *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
267
-     * It will be exposed in the page source as:
268
-     *  eejs.data.my_plugin_data.foo == gar
269
-     *
270
-     * @param string       $key   Key used to access your data
271
-     * @param string|array $value Value to attach to key
272
-     * @throws InvalidArgumentException
273
-     */
274
-    public function addData($key, $value)
275
-    {
276
-        if ($this->verifyDataNotExisting($key)) {
277
-            $this->jsdata[ $key ] = $value;
278
-        }
279
-    }
280
-
281
-
282
-    /**
283
-     * Similar to addData except this allows for users to push values to an existing key where the values on key are
284
-     * elements in an array.
285
-     *
286
-     * When you use this method, the value you include will be merged with the array on $key.
287
-     * So if the $key was 'test' and you added a value of ['my_data'] then it would be represented in the javascript
288
-     * object like this, eejs.data.test = [ my_data,
289
-     * ]
290
-     * If there has already been a scalar value attached to the data object given key (via addData for instance), then
291
-     * this will throw an exception.
292
-     *
293
-     * Caution: Only add data using this method if you are okay with the potential for additional data added on the same
294
-     * key potentially overriding the existing data on merge (specifically with associative arrays).
295
-     *
296
-     * @param string       $key   Key to attach data to.
297
-     * @param string|array $value Value being registered.
298
-     * @throws InvalidArgumentException
299
-     */
300
-    public function pushData($key, $value)
301
-    {
302
-        if (isset($this->jsdata[ $key ])
303
-            && ! is_array($this->jsdata[ $key ])
304
-        ) {
305
-            if (! $this->debug()) {
306
-                return;
307
-            }
308
-            throw new InvalidArgumentException(
309
-                sprintf(
310
-                    __(
311
-                        'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
30
+	const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json';
31
+
32
+	/**
33
+	 * @var AssetCollection $assets
34
+	 */
35
+	protected $assets;
36
+
37
+	/**
38
+	 * @var I18nRegistry
39
+	 */
40
+	private $i18n_registry;
41
+
42
+	/**
43
+	 * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
44
+	 *
45
+	 * @var array
46
+	 */
47
+	protected $jsdata = array();
48
+
49
+	/**
50
+	 * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
51
+	 * page source.
52
+	 *
53
+	 * @var array
54
+	 */
55
+	private $script_handles_with_data = array();
56
+
57
+
58
+	/**
59
+	 * Holds the manifest data obtained from registered manifest files.
60
+	 * Manifests are maps of asset chunk name to actual built asset file names.
61
+	 * Shape of this array is:
62
+	 * array(
63
+	 *  'some_namespace_slug' => array(
64
+	 *      'some_chunk_name' => array(
65
+	 *          'js' => 'filename.js'
66
+	 *          'css' => 'filename.js'
67
+	 *      ),
68
+	 *      'url_base' => 'https://baseurl.com/to/assets
69
+	 *  )
70
+	 * )
71
+	 *
72
+	 * @var array
73
+	 */
74
+	private $manifest_data = array();
75
+
76
+
77
+	/**
78
+	 * Holds any dependency data obtained from registered dependency map json.
79
+	 * Dependency map json is generated via the @wordpress/dependency-extraction-webpack-plugin via the webpack config.
80
+	 * @see https://github.com/WordPress/gutenberg/tree/master/packages/dependency-extraction-webpack-plugin
81
+	 *
82
+	 * @var array
83
+	 */
84
+	private $dependencies_data = [];
85
+
86
+
87
+	/**
88
+	 * This is a known array of possible wp css handles that correspond to what may be exposed as dependencies in our
89
+	 * build process.  Currently the dependency export process in webpack does not consider css imports, so we derive
90
+	 * them via the js dependencies (WP uses the same handle for both js and css). This is a list of known handles that
91
+	 * are used for both js and css.
92
+	 * @var array
93
+	 */
94
+	private $wp_css_handle_dependencies = [
95
+		'wp-components',
96
+		'wp-block-editor',
97
+		'wp-block-library',
98
+		'wp-edit-post',
99
+		'wp-edit-widgets',
100
+		'wp-editor',
101
+		'wp-format-library',
102
+		'wp-list-reusable-blocks',
103
+		'wp-nux',
104
+	];
105
+
106
+
107
+	/**
108
+	 * Registry constructor.
109
+	 * Hooking into WP actions for script registry.
110
+	 *
111
+	 * @param AssetCollection      $assets
112
+	 * @param I18nRegistry         $i18n_registry
113
+	 * @throws InvalidArgumentException
114
+	 * @throws InvalidDataTypeException
115
+	 * @throws InvalidInterfaceException
116
+	 */
117
+	public function __construct(AssetCollection $assets, I18nRegistry $i18n_registry)
118
+	{
119
+		$this->assets = $assets;
120
+		$this->i18n_registry = $i18n_registry;
121
+		add_action('wp_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
122
+		add_action('admin_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
123
+		add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
124
+		add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
125
+		add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 4);
126
+		add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 4);
127
+		add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
128
+		add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
129
+	}
130
+
131
+
132
+	/**
133
+	 * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n
134
+	 * translation handling.
135
+	 *
136
+	 * @return I18nRegistry
137
+	 */
138
+	public function getI18nRegistry()
139
+	{
140
+		return $this->i18n_registry;
141
+	}
142
+
143
+
144
+	/**
145
+	 * Callback for the wp_enqueue_scripts actions used to register assets.
146
+	 *
147
+	 * @since 4.9.62.p
148
+	 * @throws Exception
149
+	 */
150
+	public function registerScriptsAndStyles()
151
+	{
152
+		try {
153
+			$this->registerScripts($this->assets->getJavascriptAssets());
154
+			$this->registerStyles($this->assets->getStylesheetAssets());
155
+		} catch (Exception $exception) {
156
+			new ExceptionStackTraceDisplay($exception);
157
+		}
158
+	}
159
+
160
+
161
+	/**
162
+	 * Registers JS assets with WP core
163
+	 *
164
+	 * @since 4.9.62.p
165
+	 * @param JavascriptAsset[] $scripts
166
+	 * @throws AssetRegistrationException
167
+	 * @throws InvalidDataTypeException
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
+	 * @since 4.9.62.p
206
+	 * @param StylesheetAsset[] $styles
207
+	 * @throws InvalidDataTypeException
208
+	 */
209
+	public function registerStyles(array $styles)
210
+	{
211
+		foreach ($styles as $style) {
212
+			// skip to next style if this has already been done
213
+			if ($style->isRegistered()) {
214
+				continue;
215
+			}
216
+			do_action(
217
+				'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style',
218
+				$style
219
+			);
220
+			wp_register_style(
221
+				$style->handle(),
222
+				$style->source(),
223
+				$style->dependencies(),
224
+				$style->version(),
225
+				$style->media()
226
+			);
227
+			$style->setRegistered();
228
+			do_action(
229
+				'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style',
230
+				$style
231
+			);
232
+		}
233
+	}
234
+
235
+
236
+	/**
237
+	 * Call back for the script print in frontend and backend.
238
+	 * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
239
+	 *
240
+	 * @since 4.9.31.rc.015
241
+	 */
242
+	public function enqueueData()
243
+	{
244
+		$this->removeAlreadyRegisteredDataForScriptHandles();
245
+		wp_add_inline_script(
246
+			'eejs-core',
247
+			'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)),
248
+			'before'
249
+		);
250
+		$scripts = $this->assets->getJavascriptAssetsWithData();
251
+		foreach ($scripts as $script) {
252
+			$this->addRegisteredScriptHandlesWithData($script->handle());
253
+			if ($script->hasInlineDataCallback()) {
254
+				$localize = $script->inlineDataCallback();
255
+				$localize();
256
+			}
257
+		}
258
+	}
259
+
260
+
261
+	/**
262
+	 * Used to add data to eejs.data object.
263
+	 * Note:  Overriding existing data is not allowed.
264
+	 * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
265
+	 * If the data you add is something like this:
266
+	 *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
267
+	 * It will be exposed in the page source as:
268
+	 *  eejs.data.my_plugin_data.foo == gar
269
+	 *
270
+	 * @param string       $key   Key used to access your data
271
+	 * @param string|array $value Value to attach to key
272
+	 * @throws InvalidArgumentException
273
+	 */
274
+	public function addData($key, $value)
275
+	{
276
+		if ($this->verifyDataNotExisting($key)) {
277
+			$this->jsdata[ $key ] = $value;
278
+		}
279
+	}
280
+
281
+
282
+	/**
283
+	 * Similar to addData except this allows for users to push values to an existing key where the values on key are
284
+	 * elements in an array.
285
+	 *
286
+	 * When you use this method, the value you include will be merged with the array on $key.
287
+	 * So if the $key was 'test' and you added a value of ['my_data'] then it would be represented in the javascript
288
+	 * object like this, eejs.data.test = [ my_data,
289
+	 * ]
290
+	 * If there has already been a scalar value attached to the data object given key (via addData for instance), then
291
+	 * this will throw an exception.
292
+	 *
293
+	 * Caution: Only add data using this method if you are okay with the potential for additional data added on the same
294
+	 * key potentially overriding the existing data on merge (specifically with associative arrays).
295
+	 *
296
+	 * @param string       $key   Key to attach data to.
297
+	 * @param string|array $value Value being registered.
298
+	 * @throws InvalidArgumentException
299
+	 */
300
+	public function pushData($key, $value)
301
+	{
302
+		if (isset($this->jsdata[ $key ])
303
+			&& ! is_array($this->jsdata[ $key ])
304
+		) {
305
+			if (! $this->debug()) {
306
+				return;
307
+			}
308
+			throw new InvalidArgumentException(
309
+				sprintf(
310
+					__(
311
+						'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
312 312
                          push values to this data element when it is an array.',
313
-                        'event_espresso'
314
-                    ),
315
-                    $key,
316
-                    __METHOD__
317
-                )
318
-            );
319
-        }
320
-        if ( ! isset( $this->jsdata[ $key ] ) ) {
321
-            $this->jsdata[ $key ] = is_array($value) ? $value : [$value];
322
-        } else {
323
-            $this->jsdata[ $key ] = array_merge( $this->jsdata[$key], (array) $value);
324
-        }
325
-    }
326
-
327
-
328
-    /**
329
-     * Used to set content used by javascript for a template.
330
-     * Note: Overrides of existing registered templates are not allowed.
331
-     *
332
-     * @param string $template_reference
333
-     * @param string $template_content
334
-     * @throws InvalidArgumentException
335
-     */
336
-    public function addTemplate($template_reference, $template_content)
337
-    {
338
-        if (! isset($this->jsdata['templates'])) {
339
-            $this->jsdata['templates'] = array();
340
-        }
341
-        //no overrides allowed.
342
-        if (isset($this->jsdata['templates'][ $template_reference ])) {
343
-            if (! $this->debug()) {
344
-                return;
345
-            }
346
-            throw new InvalidArgumentException(
347
-                sprintf(
348
-                    __(
349
-                        'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
350
-                        'event_espresso'
351
-                    ),
352
-                    $template_reference
353
-                )
354
-            );
355
-        }
356
-        $this->jsdata['templates'][ $template_reference ] = $template_content;
357
-    }
358
-
359
-
360
-    /**
361
-     * Retrieve the template content already registered for the given reference.
362
-     *
363
-     * @param string $template_reference
364
-     * @return string
365
-     */
366
-    public function getTemplate($template_reference)
367
-    {
368
-        return isset($this->jsdata['templates'][ $template_reference ])
369
-            ? $this->jsdata['templates'][ $template_reference ]
370
-            : '';
371
-    }
372
-
373
-
374
-    /**
375
-     * Retrieve registered data.
376
-     *
377
-     * @param string $key Name of key to attach data to.
378
-     * @return mixed                If there is no for the given key, then false is returned.
379
-     */
380
-    public function getData($key)
381
-    {
382
-        return isset($this->jsdata[ $key ])
383
-            ? $this->jsdata[ $key ]
384
-            : false;
385
-    }
386
-
387
-
388
-    /**
389
-     * Verifies whether the given data exists already on the jsdata array.
390
-     * Overriding data is not allowed.
391
-     *
392
-     * @param string $key Index for data.
393
-     * @return bool        If valid then return true.
394
-     * @throws InvalidArgumentException if data already exists.
395
-     */
396
-    protected function verifyDataNotExisting($key)
397
-    {
398
-        if (isset($this->jsdata[ $key ])) {
399
-            if (! $this->debug()) {
400
-                return false;
401
-            }
402
-            if (is_array($this->jsdata[ $key ])) {
403
-                throw new InvalidArgumentException(
404
-                    sprintf(
405
-                        __(
406
-                            'The value for %1$s already exists in the Registry::eejs object.
313
+						'event_espresso'
314
+					),
315
+					$key,
316
+					__METHOD__
317
+				)
318
+			);
319
+		}
320
+		if ( ! isset( $this->jsdata[ $key ] ) ) {
321
+			$this->jsdata[ $key ] = is_array($value) ? $value : [$value];
322
+		} else {
323
+			$this->jsdata[ $key ] = array_merge( $this->jsdata[$key], (array) $value);
324
+		}
325
+	}
326
+
327
+
328
+	/**
329
+	 * Used to set content used by javascript for a template.
330
+	 * Note: Overrides of existing registered templates are not allowed.
331
+	 *
332
+	 * @param string $template_reference
333
+	 * @param string $template_content
334
+	 * @throws InvalidArgumentException
335
+	 */
336
+	public function addTemplate($template_reference, $template_content)
337
+	{
338
+		if (! isset($this->jsdata['templates'])) {
339
+			$this->jsdata['templates'] = array();
340
+		}
341
+		//no overrides allowed.
342
+		if (isset($this->jsdata['templates'][ $template_reference ])) {
343
+			if (! $this->debug()) {
344
+				return;
345
+			}
346
+			throw new InvalidArgumentException(
347
+				sprintf(
348
+					__(
349
+						'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
350
+						'event_espresso'
351
+					),
352
+					$template_reference
353
+				)
354
+			);
355
+		}
356
+		$this->jsdata['templates'][ $template_reference ] = $template_content;
357
+	}
358
+
359
+
360
+	/**
361
+	 * Retrieve the template content already registered for the given reference.
362
+	 *
363
+	 * @param string $template_reference
364
+	 * @return string
365
+	 */
366
+	public function getTemplate($template_reference)
367
+	{
368
+		return isset($this->jsdata['templates'][ $template_reference ])
369
+			? $this->jsdata['templates'][ $template_reference ]
370
+			: '';
371
+	}
372
+
373
+
374
+	/**
375
+	 * Retrieve registered data.
376
+	 *
377
+	 * @param string $key Name of key to attach data to.
378
+	 * @return mixed                If there is no for the given key, then false is returned.
379
+	 */
380
+	public function getData($key)
381
+	{
382
+		return isset($this->jsdata[ $key ])
383
+			? $this->jsdata[ $key ]
384
+			: false;
385
+	}
386
+
387
+
388
+	/**
389
+	 * Verifies whether the given data exists already on the jsdata array.
390
+	 * Overriding data is not allowed.
391
+	 *
392
+	 * @param string $key Index for data.
393
+	 * @return bool        If valid then return true.
394
+	 * @throws InvalidArgumentException if data already exists.
395
+	 */
396
+	protected function verifyDataNotExisting($key)
397
+	{
398
+		if (isset($this->jsdata[ $key ])) {
399
+			if (! $this->debug()) {
400
+				return false;
401
+			}
402
+			if (is_array($this->jsdata[ $key ])) {
403
+				throw new InvalidArgumentException(
404
+					sprintf(
405
+						__(
406
+							'The value for %1$s already exists in the Registry::eejs object.
407 407
                             Overrides are not allowed. Since the value of this data is an array, you may want to use the
408 408
                             %2$s method to push your value to the array.',
409
-                            'event_espresso'
410
-                        ),
411
-                        $key,
412
-                        'pushData()'
413
-                    )
414
-                );
415
-            }
416
-            throw new InvalidArgumentException(
417
-                sprintf(
418
-                    __(
419
-                        'The value for %1$s already exists in the Registry::eejs object. Overrides are not
409
+							'event_espresso'
410
+						),
411
+						$key,
412
+						'pushData()'
413
+					)
414
+				);
415
+			}
416
+			throw new InvalidArgumentException(
417
+				sprintf(
418
+					__(
419
+						'The value for %1$s already exists in the Registry::eejs object. Overrides are not
420 420
                         allowed.  Consider attaching your value to a different key',
421
-                        'event_espresso'
422
-                    ),
423
-                    $key
424
-                )
425
-            );
426
-        }
427
-        return true;
428
-    }
429
-
430
-
431
-    /**
432
-     * Get the actual asset path for asset manifests.
433
-     * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
434
-     *
435
-     * @param string $namespace  The namespace associated with the manifest file hosting the map of chunk_name to actual
436
-     *                           asset file location.
437
-     * @param string $chunk_name
438
-     * @param string $asset_type
439
-     * @return string
440
-     * @since 4.9.59.p
441
-     */
442
-    public function getAssetUrl($namespace, $chunk_name, $asset_type)
443
-    {
444
-        $url = isset(
445
-            $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ],
446
-            $this->manifest_data[ $namespace ]['url_base']
447
-        )
448
-            ? $this->manifest_data[ $namespace ]['url_base']
449
-              . $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ]
450
-            : $chunk_name;
451
-
452
-        return apply_filters(
453
-            'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl',
454
-            $url,
455
-            $namespace,
456
-            $chunk_name,
457
-            $asset_type
458
-        );
459
-    }
460
-
461
-
462
-
463
-    /**
464
-     * Return the url to a js file for the given namespace and chunk name.
465
-     *
466
-     * @param string $namespace
467
-     * @param string $chunk_name
468
-     * @return string
469
-     */
470
-    public function getJsUrl($namespace, $chunk_name)
471
-    {
472
-        return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS);
473
-    }
474
-
475
-
476
-    /**
477
-     * Return the url to a css file for the given namespace and chunk name.
478
-     *
479
-     * @param string $namespace
480
-     * @param string $chunk_name
481
-     * @return string
482
-     */
483
-    public function getCssUrl($namespace, $chunk_name)
484
-    {
485
-        return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS);
486
-    }
487
-
488
-
489
-    /**
490
-     * Return the dependencies for a given asset $chunk_name
491
-     *
492
-     * @param string $namespace
493
-     * @param string $chunk_name
494
-     * @param string $asset_type
495
-     * @return array
496
-     * @since $VID:$
497
-     */
498
-    private function getDependenciesForAsset($namespace, $chunk_name, $asset_type)
499
-    {
500
-        $asset_index = $chunk_name . '.' . $asset_type;
501
-        if (! isset( $this->dependencies_data[ $namespace ][ $asset_index ])) {
502
-            $path = isset($this->manifest_data[ $namespace ]['path'])
503
-                ? $this->manifest_data[ $namespace ]['path']
504
-                : '';
505
-            $dependencies_index = $chunk_name . '.' . Asset::TYPE_JSON;
506
-            $file_path = isset($this->manifest_data[ $namespace ][ $dependencies_index ])
507
-                ? $path . $this->manifest_data[ $namespace ][ $dependencies_index ]
508
-                :
509
-                '';
510
-            $this->dependencies_data[ $namespace ][ $asset_index ] = $file_path !== '' && file_exists($file_path)
511
-                ? $this->getDependenciesForAssetType($namespace, $asset_type, $file_path, $chunk_name)
512
-                : [];
513
-        }
514
-        return $this->dependencies_data[ $namespace ][ $asset_index ];
515
-    }
516
-
517
-
518
-    /**
519
-     * Return dependencies according to asset type.
520
-     *
521
-     * For css assets, this filters the auto generated dependencies by css type.
522
-     *
523
-     * @param string $namespace
524
-     * @param string $asset_type
525
-     * @param string $file_path
526
-     * @param string $chunk_name
527
-     * @return array
528
-     * @since $VID:$
529
-     */
530
-    private function getDependenciesForAssetType($namespace, $asset_type, $file_path, $chunk_name)
531
-    {
532
-        $asset_dependencies = json_decode(file_get_contents($file_path), true);
533
-        if ($asset_type === Asset::TYPE_JS) {
534
-            return $chunk_name === 'eejs-core' ? $asset_dependencies : array_merge(
535
-                $asset_dependencies,
536
-                [ CoreAssetManager::JS_HANDLE_JS_CORE ]
537
-            );
538
-        }
539
-        // for css we need to make sure there is actually a css file related to this chunk.
540
-        if (isset($this->manifest_data[ $namespace ])) {
541
-            // array of css chunk files for ee.
542
-            $css_chunks = array_map(
543
-                function ($value) {
544
-                    return str_replace('.css', '', $value);
545
-                },
546
-                array_filter(
547
-                    array_keys($this->manifest_data[ $namespace ]),
548
-                    function ($value) {
549
-                        return strpos($value, '.css') !== false;
550
-                    }
551
-                )
552
-            );
553
-            // add known wp chunks with css
554
-            $css_chunks = array_merge( $css_chunks, $this->wp_css_handle_dependencies);
555
-            // flip for easier search
556
-            $css_chunks = array_flip($css_chunks);
557
-            // now let's filter the dependencies for the incoming chunk to actual chunks that have styles
558
-            return array_filter(
559
-                $asset_dependencies,
560
-                function ($chunk_name) use ($css_chunks) {
561
-                    return isset($css_chunks[ $chunk_name ]);
562
-                }
563
-            );
564
-        }
565
-        return [];
566
-    }
567
-
568
-
569
-    /**
570
-     * Get the dependencies array for the given js asset chunk name
571
-     *
572
-     * @param string $namespace
573
-     * @param string $chunk_name
574
-     * @return array
575
-     * @since $VID:$
576
-     */
577
-    public function getJsDependencies($namespace, $chunk_name)
578
-    {
579
-        return $this->getDependenciesForAsset($namespace, $chunk_name, Asset::TYPE_JS);
580
-    }
581
-
582
-
583
-    /**
584
-     * Get the dependencies array for the given css asset chunk name
585
-     *
586
-     * @param string $namespace
587
-     * @param string $chunk_name
588
-     * @return array
589
-     * @since $VID:$
590
-     */
591
-    public function getCssDependencies($namespace, $chunk_name)
592
-    {
593
-        return $this->getDependenciesForAsset($namespace, $chunk_name, Asset::TYPE_CSS);
594
-    }
595
-
596
-
597
-    /**
598
-     * @since 4.9.62.p
599
-     * @throws InvalidArgumentException
600
-     * @throws InvalidFilePathException
601
-     */
602
-    public function registerManifestFiles()
603
-    {
604
-        $manifest_files = $this->assets->getManifestFiles();
605
-        foreach ($manifest_files as $manifest_file) {
606
-            $this->registerManifestFile(
607
-                $manifest_file->assetNamespace(),
608
-                $manifest_file->urlBase(),
609
-                $manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST,
610
-                $manifest_file->filepath()
611
-            );
612
-        }
613
-    }
614
-
615
-
616
-    /**
617
-     * Used to register a js/css manifest file with the registered_manifest_files property.
618
-     *
619
-     * @param string $namespace     Provided to associate the manifest file with a specific namespace.
620
-     * @param string $url_base      The url base for the manifest file location.
621
-     * @param string $manifest_file The absolute path to the manifest file.
622
-     * @param string $manifest_file_path  The path to the folder containing the manifest file. If not provided will be
623
-     *                                    default to `plugin_root/assets/dist`.
624
-     * @throws InvalidArgumentException
625
-     * @throws InvalidFilePathException
626
-     * @since 4.9.59.p
627
-     */
628
-    private function registerManifestFile($namespace, $url_base, $manifest_file, $manifest_file_path = '')
629
-    {
630
-        if (isset($this->manifest_data[ $namespace ])) {
631
-            if (! $this->debug()) {
632
-                return;
633
-            }
634
-            throw new InvalidArgumentException(
635
-                sprintf(
636
-                    esc_html__(
637
-                        'The namespace for this manifest file has already been registered, choose a namespace other than %s',
638
-                        'event_espresso'
639
-                    ),
640
-                    $namespace
641
-                )
642
-            );
643
-        }
644
-        if (filter_var($url_base, FILTER_VALIDATE_URL) === false) {
645
-            if (is_admin()) {
646
-                EE_Error::add_error(
647
-                    sprintf(
648
-                        esc_html__(
649
-                            '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',
650
-                            'event_espresso'
651
-                        ),
652
-                        'Event Espresso',
653
-                        $url_base,
654
-                        'plugins_url',
655
-                        'WP_PLUGIN_URL'
656
-                    ),
657
-                    __FILE__,
658
-                    __FUNCTION__,
659
-                    __LINE__
660
-                );
661
-            }
662
-            return;
663
-        }
664
-        $this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file);
665
-        if (! isset($this->manifest_data[ $namespace ]['url_base'])) {
666
-            $this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base);
667
-        }
668
-        if (! isset($this->manifest_data[ $namespace ]['path'])) {
669
-            $this->manifest_data[ $namespace ]['path'] = $manifest_file_path;
670
-        }
671
-    }
672
-
673
-
674
-    /**
675
-     * Decodes json from the provided manifest file.
676
-     *
677
-     * @since 4.9.59.p
678
-     * @param string $manifest_file Path to manifest file.
679
-     * @return array
680
-     * @throws InvalidFilePathException
681
-     */
682
-    private function decodeManifestFile($manifest_file)
683
-    {
684
-        if (! file_exists($manifest_file)) {
685
-            throw new InvalidFilePathException($manifest_file);
686
-        }
687
-        return json_decode(file_get_contents($manifest_file), true);
688
-    }
689
-
690
-
691
-    /**
692
-     * This is used to set registered script handles that have data.
693
-     *
694
-     * @param string $script_handle
695
-     */
696
-    private function addRegisteredScriptHandlesWithData($script_handle)
697
-    {
698
-        $this->script_handles_with_data[ $script_handle ] = $script_handle;
699
-    }
700
-
701
-
702
-    /**i
421
+						'event_espresso'
422
+					),
423
+					$key
424
+				)
425
+			);
426
+		}
427
+		return true;
428
+	}
429
+
430
+
431
+	/**
432
+	 * Get the actual asset path for asset manifests.
433
+	 * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
434
+	 *
435
+	 * @param string $namespace  The namespace associated with the manifest file hosting the map of chunk_name to actual
436
+	 *                           asset file location.
437
+	 * @param string $chunk_name
438
+	 * @param string $asset_type
439
+	 * @return string
440
+	 * @since 4.9.59.p
441
+	 */
442
+	public function getAssetUrl($namespace, $chunk_name, $asset_type)
443
+	{
444
+		$url = isset(
445
+			$this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ],
446
+			$this->manifest_data[ $namespace ]['url_base']
447
+		)
448
+			? $this->manifest_data[ $namespace ]['url_base']
449
+			  . $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ]
450
+			: $chunk_name;
451
+
452
+		return apply_filters(
453
+			'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl',
454
+			$url,
455
+			$namespace,
456
+			$chunk_name,
457
+			$asset_type
458
+		);
459
+	}
460
+
461
+
462
+
463
+	/**
464
+	 * Return the url to a js file for the given namespace and chunk name.
465
+	 *
466
+	 * @param string $namespace
467
+	 * @param string $chunk_name
468
+	 * @return string
469
+	 */
470
+	public function getJsUrl($namespace, $chunk_name)
471
+	{
472
+		return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS);
473
+	}
474
+
475
+
476
+	/**
477
+	 * Return the url to a css file for the given namespace and chunk name.
478
+	 *
479
+	 * @param string $namespace
480
+	 * @param string $chunk_name
481
+	 * @return string
482
+	 */
483
+	public function getCssUrl($namespace, $chunk_name)
484
+	{
485
+		return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS);
486
+	}
487
+
488
+
489
+	/**
490
+	 * Return the dependencies for a given asset $chunk_name
491
+	 *
492
+	 * @param string $namespace
493
+	 * @param string $chunk_name
494
+	 * @param string $asset_type
495
+	 * @return array
496
+	 * @since $VID:$
497
+	 */
498
+	private function getDependenciesForAsset($namespace, $chunk_name, $asset_type)
499
+	{
500
+		$asset_index = $chunk_name . '.' . $asset_type;
501
+		if (! isset( $this->dependencies_data[ $namespace ][ $asset_index ])) {
502
+			$path = isset($this->manifest_data[ $namespace ]['path'])
503
+				? $this->manifest_data[ $namespace ]['path']
504
+				: '';
505
+			$dependencies_index = $chunk_name . '.' . Asset::TYPE_JSON;
506
+			$file_path = isset($this->manifest_data[ $namespace ][ $dependencies_index ])
507
+				? $path . $this->manifest_data[ $namespace ][ $dependencies_index ]
508
+				:
509
+				'';
510
+			$this->dependencies_data[ $namespace ][ $asset_index ] = $file_path !== '' && file_exists($file_path)
511
+				? $this->getDependenciesForAssetType($namespace, $asset_type, $file_path, $chunk_name)
512
+				: [];
513
+		}
514
+		return $this->dependencies_data[ $namespace ][ $asset_index ];
515
+	}
516
+
517
+
518
+	/**
519
+	 * Return dependencies according to asset type.
520
+	 *
521
+	 * For css assets, this filters the auto generated dependencies by css type.
522
+	 *
523
+	 * @param string $namespace
524
+	 * @param string $asset_type
525
+	 * @param string $file_path
526
+	 * @param string $chunk_name
527
+	 * @return array
528
+	 * @since $VID:$
529
+	 */
530
+	private function getDependenciesForAssetType($namespace, $asset_type, $file_path, $chunk_name)
531
+	{
532
+		$asset_dependencies = json_decode(file_get_contents($file_path), true);
533
+		if ($asset_type === Asset::TYPE_JS) {
534
+			return $chunk_name === 'eejs-core' ? $asset_dependencies : array_merge(
535
+				$asset_dependencies,
536
+				[ CoreAssetManager::JS_HANDLE_JS_CORE ]
537
+			);
538
+		}
539
+		// for css we need to make sure there is actually a css file related to this chunk.
540
+		if (isset($this->manifest_data[ $namespace ])) {
541
+			// array of css chunk files for ee.
542
+			$css_chunks = array_map(
543
+				function ($value) {
544
+					return str_replace('.css', '', $value);
545
+				},
546
+				array_filter(
547
+					array_keys($this->manifest_data[ $namespace ]),
548
+					function ($value) {
549
+						return strpos($value, '.css') !== false;
550
+					}
551
+				)
552
+			);
553
+			// add known wp chunks with css
554
+			$css_chunks = array_merge( $css_chunks, $this->wp_css_handle_dependencies);
555
+			// flip for easier search
556
+			$css_chunks = array_flip($css_chunks);
557
+			// now let's filter the dependencies for the incoming chunk to actual chunks that have styles
558
+			return array_filter(
559
+				$asset_dependencies,
560
+				function ($chunk_name) use ($css_chunks) {
561
+					return isset($css_chunks[ $chunk_name ]);
562
+				}
563
+			);
564
+		}
565
+		return [];
566
+	}
567
+
568
+
569
+	/**
570
+	 * Get the dependencies array for the given js asset chunk name
571
+	 *
572
+	 * @param string $namespace
573
+	 * @param string $chunk_name
574
+	 * @return array
575
+	 * @since $VID:$
576
+	 */
577
+	public function getJsDependencies($namespace, $chunk_name)
578
+	{
579
+		return $this->getDependenciesForAsset($namespace, $chunk_name, Asset::TYPE_JS);
580
+	}
581
+
582
+
583
+	/**
584
+	 * Get the dependencies array for the given css asset chunk name
585
+	 *
586
+	 * @param string $namespace
587
+	 * @param string $chunk_name
588
+	 * @return array
589
+	 * @since $VID:$
590
+	 */
591
+	public function getCssDependencies($namespace, $chunk_name)
592
+	{
593
+		return $this->getDependenciesForAsset($namespace, $chunk_name, Asset::TYPE_CSS);
594
+	}
595
+
596
+
597
+	/**
598
+	 * @since 4.9.62.p
599
+	 * @throws InvalidArgumentException
600
+	 * @throws InvalidFilePathException
601
+	 */
602
+	public function registerManifestFiles()
603
+	{
604
+		$manifest_files = $this->assets->getManifestFiles();
605
+		foreach ($manifest_files as $manifest_file) {
606
+			$this->registerManifestFile(
607
+				$manifest_file->assetNamespace(),
608
+				$manifest_file->urlBase(),
609
+				$manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST,
610
+				$manifest_file->filepath()
611
+			);
612
+		}
613
+	}
614
+
615
+
616
+	/**
617
+	 * Used to register a js/css manifest file with the registered_manifest_files property.
618
+	 *
619
+	 * @param string $namespace     Provided to associate the manifest file with a specific namespace.
620
+	 * @param string $url_base      The url base for the manifest file location.
621
+	 * @param string $manifest_file The absolute path to the manifest file.
622
+	 * @param string $manifest_file_path  The path to the folder containing the manifest file. If not provided will be
623
+	 *                                    default to `plugin_root/assets/dist`.
624
+	 * @throws InvalidArgumentException
625
+	 * @throws InvalidFilePathException
626
+	 * @since 4.9.59.p
627
+	 */
628
+	private function registerManifestFile($namespace, $url_base, $manifest_file, $manifest_file_path = '')
629
+	{
630
+		if (isset($this->manifest_data[ $namespace ])) {
631
+			if (! $this->debug()) {
632
+				return;
633
+			}
634
+			throw new InvalidArgumentException(
635
+				sprintf(
636
+					esc_html__(
637
+						'The namespace for this manifest file has already been registered, choose a namespace other than %s',
638
+						'event_espresso'
639
+					),
640
+					$namespace
641
+				)
642
+			);
643
+		}
644
+		if (filter_var($url_base, FILTER_VALIDATE_URL) === false) {
645
+			if (is_admin()) {
646
+				EE_Error::add_error(
647
+					sprintf(
648
+						esc_html__(
649
+							'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',
650
+							'event_espresso'
651
+						),
652
+						'Event Espresso',
653
+						$url_base,
654
+						'plugins_url',
655
+						'WP_PLUGIN_URL'
656
+					),
657
+					__FILE__,
658
+					__FUNCTION__,
659
+					__LINE__
660
+				);
661
+			}
662
+			return;
663
+		}
664
+		$this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file);
665
+		if (! isset($this->manifest_data[ $namespace ]['url_base'])) {
666
+			$this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base);
667
+		}
668
+		if (! isset($this->manifest_data[ $namespace ]['path'])) {
669
+			$this->manifest_data[ $namespace ]['path'] = $manifest_file_path;
670
+		}
671
+	}
672
+
673
+
674
+	/**
675
+	 * Decodes json from the provided manifest file.
676
+	 *
677
+	 * @since 4.9.59.p
678
+	 * @param string $manifest_file Path to manifest file.
679
+	 * @return array
680
+	 * @throws InvalidFilePathException
681
+	 */
682
+	private function decodeManifestFile($manifest_file)
683
+	{
684
+		if (! file_exists($manifest_file)) {
685
+			throw new InvalidFilePathException($manifest_file);
686
+		}
687
+		return json_decode(file_get_contents($manifest_file), true);
688
+	}
689
+
690
+
691
+	/**
692
+	 * This is used to set registered script handles that have data.
693
+	 *
694
+	 * @param string $script_handle
695
+	 */
696
+	private function addRegisteredScriptHandlesWithData($script_handle)
697
+	{
698
+		$this->script_handles_with_data[ $script_handle ] = $script_handle;
699
+	}
700
+
701
+
702
+	/**i
703 703
      * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the
704 704
      * Dependency stored in WP_Scripts if its set.
705 705
      */
706
-    private function removeAlreadyRegisteredDataForScriptHandles()
707
-    {
708
-        if (empty($this->script_handles_with_data)) {
709
-            return;
710
-        }
711
-        foreach ($this->script_handles_with_data as $script_handle) {
712
-            $this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
713
-        }
714
-    }
715
-
716
-
717
-    /**
718
-     * Removes any data dependency registered in WP_Scripts if its set.
719
-     *
720
-     * @param string $script_handle
721
-     */
722
-    private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
723
-    {
724
-        if (isset($this->script_handles_with_data[ $script_handle ])) {
725
-            global $wp_scripts;
726
-            $unset_handle = false;
727
-            if ($wp_scripts->get_data($script_handle, 'data')) {
728
-                unset($wp_scripts->registered[ $script_handle ]->extra['data']);
729
-                $unset_handle = true;
730
-            }
731
-            //deal with inline_scripts
732
-            if ($wp_scripts->get_data($script_handle, 'before')) {
733
-                unset($wp_scripts->registered[ $script_handle ]->extra['before']);
734
-                $unset_handle = true;
735
-            }
736
-            if ($wp_scripts->get_data($script_handle, 'after')) {
737
-                unset($wp_scripts->registered[ $script_handle ]->extra['after']);
738
-            }
739
-            if ($unset_handle) {
740
-                unset($this->script_handles_with_data[ $script_handle ]);
741
-            }
742
-        }
743
-    }
744
-
745
-
746
-    /**
747
-     * register translations for a registered script
748
-     *
749
-     * @param string $handle
750
-     */
751
-    public function registerTranslation($handle)
752
-    {
753
-        $this->i18n_registry->registerScriptI18n($handle);
754
-    }
755
-
756
-
757
-    /**
758
-     * @since 4.9.63.p
759
-     * @return bool
760
-     */
761
-    private function debug()
762
-    {
763
-        return apply_filters(
764
-            'FHEE__EventEspresso_core_services_assets_Registry__debug',
765
-            defined('EE_DEBUG') && EE_DEBUG
766
-        );
767
-    }
706
+	private function removeAlreadyRegisteredDataForScriptHandles()
707
+	{
708
+		if (empty($this->script_handles_with_data)) {
709
+			return;
710
+		}
711
+		foreach ($this->script_handles_with_data as $script_handle) {
712
+			$this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
713
+		}
714
+	}
715
+
716
+
717
+	/**
718
+	 * Removes any data dependency registered in WP_Scripts if its set.
719
+	 *
720
+	 * @param string $script_handle
721
+	 */
722
+	private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
723
+	{
724
+		if (isset($this->script_handles_with_data[ $script_handle ])) {
725
+			global $wp_scripts;
726
+			$unset_handle = false;
727
+			if ($wp_scripts->get_data($script_handle, 'data')) {
728
+				unset($wp_scripts->registered[ $script_handle ]->extra['data']);
729
+				$unset_handle = true;
730
+			}
731
+			//deal with inline_scripts
732
+			if ($wp_scripts->get_data($script_handle, 'before')) {
733
+				unset($wp_scripts->registered[ $script_handle ]->extra['before']);
734
+				$unset_handle = true;
735
+			}
736
+			if ($wp_scripts->get_data($script_handle, 'after')) {
737
+				unset($wp_scripts->registered[ $script_handle ]->extra['after']);
738
+			}
739
+			if ($unset_handle) {
740
+				unset($this->script_handles_with_data[ $script_handle ]);
741
+			}
742
+		}
743
+	}
744
+
745
+
746
+	/**
747
+	 * register translations for a registered script
748
+	 *
749
+	 * @param string $handle
750
+	 */
751
+	public function registerTranslation($handle)
752
+	{
753
+		$this->i18n_registry->registerScriptI18n($handle);
754
+	}
755
+
756
+
757
+	/**
758
+	 * @since 4.9.63.p
759
+	 * @return bool
760
+	 */
761
+	private function debug()
762
+	{
763
+		return apply_filters(
764
+			'FHEE__EventEspresso_core_services_assets_Registry__debug',
765
+			defined('EE_DEBUG') && EE_DEBUG
766
+		);
767
+	}
768 768
 }
Please login to merge, or discard this patch.
Spacing   +56 added lines, -56 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);
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
         $this->removeAlreadyRegisteredDataForScriptHandles();
245 245
         wp_add_inline_script(
246 246
             'eejs-core',
247
-            'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)),
247
+            'var eejsdata='.wp_json_encode(array('data' => $this->jsdata)),
248 248
             'before'
249 249
         );
250 250
         $scripts = $this->assets->getJavascriptAssetsWithData();
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
     public function addData($key, $value)
275 275
     {
276 276
         if ($this->verifyDataNotExisting($key)) {
277
-            $this->jsdata[ $key ] = $value;
277
+            $this->jsdata[$key] = $value;
278 278
         }
279 279
     }
280 280
 
@@ -299,10 +299,10 @@  discard block
 block discarded – undo
299 299
      */
300 300
     public function pushData($key, $value)
301 301
     {
302
-        if (isset($this->jsdata[ $key ])
303
-            && ! is_array($this->jsdata[ $key ])
302
+        if (isset($this->jsdata[$key])
303
+            && ! is_array($this->jsdata[$key])
304 304
         ) {
305
-            if (! $this->debug()) {
305
+            if ( ! $this->debug()) {
306 306
                 return;
307 307
             }
308 308
             throw new InvalidArgumentException(
@@ -317,10 +317,10 @@  discard block
 block discarded – undo
317 317
                 )
318 318
             );
319 319
         }
320
-        if ( ! isset( $this->jsdata[ $key ] ) ) {
321
-            $this->jsdata[ $key ] = is_array($value) ? $value : [$value];
320
+        if ( ! isset($this->jsdata[$key])) {
321
+            $this->jsdata[$key] = is_array($value) ? $value : [$value];
322 322
         } else {
323
-            $this->jsdata[ $key ] = array_merge( $this->jsdata[$key], (array) $value);
323
+            $this->jsdata[$key] = array_merge($this->jsdata[$key], (array) $value);
324 324
         }
325 325
     }
326 326
 
@@ -335,12 +335,12 @@  discard block
 block discarded – undo
335 335
      */
336 336
     public function addTemplate($template_reference, $template_content)
337 337
     {
338
-        if (! isset($this->jsdata['templates'])) {
338
+        if ( ! isset($this->jsdata['templates'])) {
339 339
             $this->jsdata['templates'] = array();
340 340
         }
341 341
         //no overrides allowed.
342
-        if (isset($this->jsdata['templates'][ $template_reference ])) {
343
-            if (! $this->debug()) {
342
+        if (isset($this->jsdata['templates'][$template_reference])) {
343
+            if ( ! $this->debug()) {
344 344
                 return;
345 345
             }
346 346
             throw new InvalidArgumentException(
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
                 )
354 354
             );
355 355
         }
356
-        $this->jsdata['templates'][ $template_reference ] = $template_content;
356
+        $this->jsdata['templates'][$template_reference] = $template_content;
357 357
     }
358 358
 
359 359
 
@@ -365,8 +365,8 @@  discard block
 block discarded – undo
365 365
      */
366 366
     public function getTemplate($template_reference)
367 367
     {
368
-        return isset($this->jsdata['templates'][ $template_reference ])
369
-            ? $this->jsdata['templates'][ $template_reference ]
368
+        return isset($this->jsdata['templates'][$template_reference])
369
+            ? $this->jsdata['templates'][$template_reference]
370 370
             : '';
371 371
     }
372 372
 
@@ -379,8 +379,8 @@  discard block
 block discarded – undo
379 379
      */
380 380
     public function getData($key)
381 381
     {
382
-        return isset($this->jsdata[ $key ])
383
-            ? $this->jsdata[ $key ]
382
+        return isset($this->jsdata[$key])
383
+            ? $this->jsdata[$key]
384 384
             : false;
385 385
     }
386 386
 
@@ -395,11 +395,11 @@  discard block
 block discarded – undo
395 395
      */
396 396
     protected function verifyDataNotExisting($key)
397 397
     {
398
-        if (isset($this->jsdata[ $key ])) {
399
-            if (! $this->debug()) {
398
+        if (isset($this->jsdata[$key])) {
399
+            if ( ! $this->debug()) {
400 400
                 return false;
401 401
             }
402
-            if (is_array($this->jsdata[ $key ])) {
402
+            if (is_array($this->jsdata[$key])) {
403 403
                 throw new InvalidArgumentException(
404 404
                     sprintf(
405 405
                         __(
@@ -442,11 +442,11 @@  discard block
 block discarded – undo
442 442
     public function getAssetUrl($namespace, $chunk_name, $asset_type)
443 443
     {
444 444
         $url = isset(
445
-            $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ],
446
-            $this->manifest_data[ $namespace ]['url_base']
445
+            $this->manifest_data[$namespace][$chunk_name.'.'.$asset_type],
446
+            $this->manifest_data[$namespace]['url_base']
447 447
         )
448
-            ? $this->manifest_data[ $namespace ]['url_base']
449
-              . $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ]
448
+            ? $this->manifest_data[$namespace]['url_base']
449
+              . $this->manifest_data[$namespace][$chunk_name.'.'.$asset_type]
450 450
             : $chunk_name;
451 451
 
452 452
         return apply_filters(
@@ -497,21 +497,21 @@  discard block
 block discarded – undo
497 497
      */
498 498
     private function getDependenciesForAsset($namespace, $chunk_name, $asset_type)
499 499
     {
500
-        $asset_index = $chunk_name . '.' . $asset_type;
501
-        if (! isset( $this->dependencies_data[ $namespace ][ $asset_index ])) {
502
-            $path = isset($this->manifest_data[ $namespace ]['path'])
503
-                ? $this->manifest_data[ $namespace ]['path']
500
+        $asset_index = $chunk_name.'.'.$asset_type;
501
+        if ( ! isset($this->dependencies_data[$namespace][$asset_index])) {
502
+            $path = isset($this->manifest_data[$namespace]['path'])
503
+                ? $this->manifest_data[$namespace]['path']
504 504
                 : '';
505
-            $dependencies_index = $chunk_name . '.' . Asset::TYPE_JSON;
506
-            $file_path = isset($this->manifest_data[ $namespace ][ $dependencies_index ])
507
-                ? $path . $this->manifest_data[ $namespace ][ $dependencies_index ]
505
+            $dependencies_index = $chunk_name.'.'.Asset::TYPE_JSON;
506
+            $file_path = isset($this->manifest_data[$namespace][$dependencies_index])
507
+                ? $path.$this->manifest_data[$namespace][$dependencies_index]
508 508
                 :
509 509
                 '';
510
-            $this->dependencies_data[ $namespace ][ $asset_index ] = $file_path !== '' && file_exists($file_path)
510
+            $this->dependencies_data[$namespace][$asset_index] = $file_path !== '' && file_exists($file_path)
511 511
                 ? $this->getDependenciesForAssetType($namespace, $asset_type, $file_path, $chunk_name)
512 512
                 : [];
513 513
         }
514
-        return $this->dependencies_data[ $namespace ][ $asset_index ];
514
+        return $this->dependencies_data[$namespace][$asset_index];
515 515
     }
516 516
 
517 517
 
@@ -533,32 +533,32 @@  discard block
 block discarded – undo
533 533
         if ($asset_type === Asset::TYPE_JS) {
534 534
             return $chunk_name === 'eejs-core' ? $asset_dependencies : array_merge(
535 535
                 $asset_dependencies,
536
-                [ CoreAssetManager::JS_HANDLE_JS_CORE ]
536
+                [CoreAssetManager::JS_HANDLE_JS_CORE]
537 537
             );
538 538
         }
539 539
         // for css we need to make sure there is actually a css file related to this chunk.
540
-        if (isset($this->manifest_data[ $namespace ])) {
540
+        if (isset($this->manifest_data[$namespace])) {
541 541
             // array of css chunk files for ee.
542 542
             $css_chunks = array_map(
543
-                function ($value) {
543
+                function($value) {
544 544
                     return str_replace('.css', '', $value);
545 545
                 },
546 546
                 array_filter(
547
-                    array_keys($this->manifest_data[ $namespace ]),
548
-                    function ($value) {
547
+                    array_keys($this->manifest_data[$namespace]),
548
+                    function($value) {
549 549
                         return strpos($value, '.css') !== false;
550 550
                     }
551 551
                 )
552 552
             );
553 553
             // add known wp chunks with css
554
-            $css_chunks = array_merge( $css_chunks, $this->wp_css_handle_dependencies);
554
+            $css_chunks = array_merge($css_chunks, $this->wp_css_handle_dependencies);
555 555
             // flip for easier search
556 556
             $css_chunks = array_flip($css_chunks);
557 557
             // now let's filter the dependencies for the incoming chunk to actual chunks that have styles
558 558
             return array_filter(
559 559
                 $asset_dependencies,
560
-                function ($chunk_name) use ($css_chunks) {
561
-                    return isset($css_chunks[ $chunk_name ]);
560
+                function($chunk_name) use ($css_chunks) {
561
+                    return isset($css_chunks[$chunk_name]);
562 562
                 }
563 563
             );
564 564
         }
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
             $this->registerManifestFile(
607 607
                 $manifest_file->assetNamespace(),
608 608
                 $manifest_file->urlBase(),
609
-                $manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST,
609
+                $manifest_file->filepath().Registry::FILE_NAME_BUILD_MANIFEST,
610 610
                 $manifest_file->filepath()
611 611
             );
612 612
         }
@@ -627,8 +627,8 @@  discard block
 block discarded – undo
627 627
      */
628 628
     private function registerManifestFile($namespace, $url_base, $manifest_file, $manifest_file_path = '')
629 629
     {
630
-        if (isset($this->manifest_data[ $namespace ])) {
631
-            if (! $this->debug()) {
630
+        if (isset($this->manifest_data[$namespace])) {
631
+            if ( ! $this->debug()) {
632 632
                 return;
633 633
             }
634 634
             throw new InvalidArgumentException(
@@ -661,12 +661,12 @@  discard block
 block discarded – undo
661 661
             }
662 662
             return;
663 663
         }
664
-        $this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file);
665
-        if (! isset($this->manifest_data[ $namespace ]['url_base'])) {
666
-            $this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base);
664
+        $this->manifest_data[$namespace] = $this->decodeManifestFile($manifest_file);
665
+        if ( ! isset($this->manifest_data[$namespace]['url_base'])) {
666
+            $this->manifest_data[$namespace]['url_base'] = trailingslashit($url_base);
667 667
         }
668
-        if (! isset($this->manifest_data[ $namespace ]['path'])) {
669
-            $this->manifest_data[ $namespace ]['path'] = $manifest_file_path;
668
+        if ( ! isset($this->manifest_data[$namespace]['path'])) {
669
+            $this->manifest_data[$namespace]['path'] = $manifest_file_path;
670 670
         }
671 671
     }
672 672
 
@@ -681,7 +681,7 @@  discard block
 block discarded – undo
681 681
      */
682 682
     private function decodeManifestFile($manifest_file)
683 683
     {
684
-        if (! file_exists($manifest_file)) {
684
+        if ( ! file_exists($manifest_file)) {
685 685
             throw new InvalidFilePathException($manifest_file);
686 686
         }
687 687
         return json_decode(file_get_contents($manifest_file), true);
@@ -695,7 +695,7 @@  discard block
 block discarded – undo
695 695
      */
696 696
     private function addRegisteredScriptHandlesWithData($script_handle)
697 697
     {
698
-        $this->script_handles_with_data[ $script_handle ] = $script_handle;
698
+        $this->script_handles_with_data[$script_handle] = $script_handle;
699 699
     }
700 700
 
701 701
 
@@ -721,23 +721,23 @@  discard block
 block discarded – undo
721 721
      */
722 722
     private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
723 723
     {
724
-        if (isset($this->script_handles_with_data[ $script_handle ])) {
724
+        if (isset($this->script_handles_with_data[$script_handle])) {
725 725
             global $wp_scripts;
726 726
             $unset_handle = false;
727 727
             if ($wp_scripts->get_data($script_handle, 'data')) {
728
-                unset($wp_scripts->registered[ $script_handle ]->extra['data']);
728
+                unset($wp_scripts->registered[$script_handle]->extra['data']);
729 729
                 $unset_handle = true;
730 730
             }
731 731
             //deal with inline_scripts
732 732
             if ($wp_scripts->get_data($script_handle, 'before')) {
733
-                unset($wp_scripts->registered[ $script_handle ]->extra['before']);
733
+                unset($wp_scripts->registered[$script_handle]->extra['before']);
734 734
                 $unset_handle = true;
735 735
             }
736 736
             if ($wp_scripts->get_data($script_handle, 'after')) {
737
-                unset($wp_scripts->registered[ $script_handle ]->extra['after']);
737
+                unset($wp_scripts->registered[$script_handle]->extra['after']);
738 738
             }
739 739
             if ($unset_handle) {
740
-                unset($this->script_handles_with_data[ $script_handle ]);
740
+                unset($this->script_handles_with_data[$script_handle]);
741 741
             }
742 742
         }
743 743
     }
Please login to merge, or discard this patch.