Completed
Pull Request — master (#287)
by Darren
13:17
created
core/services/assets/Registry.php 2 patches
Indentation   +526 added lines, -526 removed lines patch added patch discarded remove patch
@@ -25,536 +25,536 @@
 block discarded – undo
25 25
 class Registry
26 26
 {
27 27
 
28
-    const ASSET_TYPE_CSS = 'css';
29
-    const ASSET_TYPE_JS = 'js';
30
-
31
-    /**
32
-     * @var EE_Template_Config $template_config
33
-     */
34
-    protected $template_config;
35
-
36
-    /**
37
-     * @var EE_Currency_Config $currency_config
38
-     */
39
-    protected $currency_config;
40
-
41
-    /**
42
-     * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
43
-     *
44
-     * @var array
45
-     */
46
-    protected $jsdata = array();
47
-
48
-
49
-    /**
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
-     * @var array
53
-     */
54
-    protected $script_handles_with_data = array();
55
-
56
-
57
-    /**
58
-     * @var DomainInterface
59
-     */
60
-    protected $domain;
61
-
62
-
63
-    /**
64
-     * Holds a cache of all registered asset manifests.
65
-     * Manifests are maps of asset chunk name to actual built filenames.
66
-     * @var array
67
-     */
68
-    private $cached_manifests = array();
69
-
70
-
71
-    /**
72
-     * Registry constructor.
73
-     * Hooking into WP actions for script registry.
74
-     *
75
-     * @param EE_Template_Config $template_config
76
-     * @param EE_Currency_Config $currency_config
77
-     * @param DomainInterface    $domain
78
-     */
79
-    public function __construct(
80
-        EE_Template_Config $template_config,
81
-        EE_Currency_Config $currency_config,
82
-        DomainInterface $domain
83
-    ) {
84
-        $this->template_config = $template_config;
85
-        $this->currency_config = $currency_config;
86
-        $this->domain = $domain;
87
-        add_action('wp_enqueue_scripts', array($this, 'scripts'), 1);
88
-        add_action('admin_enqueue_scripts', array($this, 'scripts'), 1);
89
-        add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 2);
90
-        add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 2);
91
-        add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
92
-        add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
93
-    }
94
-
95
-
96
-    /**
97
-     * Callback for the WP script actions.
98
-     * Used to register globally accessible core scripts.
99
-     * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency.
100
-     *
101
-     * @throws InvalidFilePathException
102
-     */
103
-    public function scripts()
104
-    {
105
-        global $wp_version;
106
-        wp_register_script(
107
-            'ee-manifest',
108
-            $this->getAssetUrl('manifest', self::ASSET_TYPE_JS),
109
-            array(),
110
-            null,
111
-            true
112
-        );
113
-        wp_register_script(
114
-            'eejs-core',
115
-            $this->getAssetUrl('eejs', self::ASSET_TYPE_JS),
116
-            array('ee-manifest'),
117
-            null,
118
-            true
119
-        );
120
-        wp_register_script(
121
-            'ee-vendor-react',
122
-            $this->getAssetUrl('vendorReact', self::ASSET_TYPE_JS),
123
-            array('eejs-core'),
124
-            null,
125
-            true
126
-        );
127
-        //only run this if WordPress 4.4.0 > is in use.
128
-        if (version_compare($wp_version, '4.4.0', '>')) {
129
-            //js.api
130
-            wp_register_script(
131
-                'eejs-api',
132
-                EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
133
-                array('underscore', 'eejs-core'),
134
-                EVENT_ESPRESSO_VERSION,
135
-                true
136
-            );
137
-            $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest');
138
-            $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/'));
139
-        }
140
-        if (! is_admin()) {
141
-            $this->loadCoreCss();
142
-        }
143
-        $this->loadCoreJs();
144
-        $this->loadJqueryValidate();
145
-        $this->loadAccountingJs();
146
-        $this->loadQtipJs();
147
-    }
148
-
149
-
150
-
151
-    /**
152
-     * Call back for the script print in frontend and backend.
153
-     * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
154
-     *
155
-     * @since 4.9.31.rc.015
156
-     */
157
-    public function enqueueData()
158
-    {
159
-        $this->removeAlreadyRegisteredDataForScriptHandles();
160
-        wp_localize_script('eejs-core', 'eejsdata', array('data' => $this->jsdata));
161
-        wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings);
162
-        $this->localizeAccountingJs();
163
-        $this->addRegisteredScriptHandlesWithData('eejs-core');
164
-        $this->addRegisteredScriptHandlesWithData('espresso_core');
165
-    }
166
-
167
-
168
-
169
-    /**
170
-     * Used to add data to eejs.data object.
171
-     * Note:  Overriding existing data is not allowed.
172
-     * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
173
-     * If the data you add is something like this:
174
-     *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
175
-     * It will be exposed in the page source as:
176
-     *  eejs.data.my_plugin_data.foo == gar
177
-     *
178
-     * @param string       $key   Key used to access your data
179
-     * @param string|array $value Value to attach to key
180
-     * @throws InvalidArgumentException
181
-     */
182
-    public function addData($key, $value)
183
-    {
184
-        if ($this->verifyDataNotExisting($key)) {
185
-            $this->jsdata[$key] = $value;
186
-        }
187
-    }
188
-
189
-
190
-
191
-    /**
192
-     * Similar to addData except this allows for users to push values to an existing key where the values on key are
193
-     * elements in an array.
194
-     * When you use this method, the value you include will be appended to the end of an array on $key.
195
-     * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript
196
-     * object like this, eejs.data.test = [ my_data,
197
-     * ]
198
-     * If there has already been a scalar value attached to the data object given key, then
199
-     * this will throw an exception.
200
-     *
201
-     * @param string       $key   Key to attach data to.
202
-     * @param string|array $value Value being registered.
203
-     * @throws InvalidArgumentException
204
-     */
205
-    public function pushData($key, $value)
206
-    {
207
-        if (isset($this->jsdata[$key])
208
-            && ! is_array($this->jsdata[$key])
209
-        ) {
210
-            throw new invalidArgumentException(
211
-                sprintf(
212
-                    __(
213
-                        'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
28
+	const ASSET_TYPE_CSS = 'css';
29
+	const ASSET_TYPE_JS = 'js';
30
+
31
+	/**
32
+	 * @var EE_Template_Config $template_config
33
+	 */
34
+	protected $template_config;
35
+
36
+	/**
37
+	 * @var EE_Currency_Config $currency_config
38
+	 */
39
+	protected $currency_config;
40
+
41
+	/**
42
+	 * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
43
+	 *
44
+	 * @var array
45
+	 */
46
+	protected $jsdata = array();
47
+
48
+
49
+	/**
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
+	 * @var array
53
+	 */
54
+	protected $script_handles_with_data = array();
55
+
56
+
57
+	/**
58
+	 * @var DomainInterface
59
+	 */
60
+	protected $domain;
61
+
62
+
63
+	/**
64
+	 * Holds a cache of all registered asset manifests.
65
+	 * Manifests are maps of asset chunk name to actual built filenames.
66
+	 * @var array
67
+	 */
68
+	private $cached_manifests = array();
69
+
70
+
71
+	/**
72
+	 * Registry constructor.
73
+	 * Hooking into WP actions for script registry.
74
+	 *
75
+	 * @param EE_Template_Config $template_config
76
+	 * @param EE_Currency_Config $currency_config
77
+	 * @param DomainInterface    $domain
78
+	 */
79
+	public function __construct(
80
+		EE_Template_Config $template_config,
81
+		EE_Currency_Config $currency_config,
82
+		DomainInterface $domain
83
+	) {
84
+		$this->template_config = $template_config;
85
+		$this->currency_config = $currency_config;
86
+		$this->domain = $domain;
87
+		add_action('wp_enqueue_scripts', array($this, 'scripts'), 1);
88
+		add_action('admin_enqueue_scripts', array($this, 'scripts'), 1);
89
+		add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 2);
90
+		add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 2);
91
+		add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
92
+		add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
93
+	}
94
+
95
+
96
+	/**
97
+	 * Callback for the WP script actions.
98
+	 * Used to register globally accessible core scripts.
99
+	 * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency.
100
+	 *
101
+	 * @throws InvalidFilePathException
102
+	 */
103
+	public function scripts()
104
+	{
105
+		global $wp_version;
106
+		wp_register_script(
107
+			'ee-manifest',
108
+			$this->getAssetUrl('manifest', self::ASSET_TYPE_JS),
109
+			array(),
110
+			null,
111
+			true
112
+		);
113
+		wp_register_script(
114
+			'eejs-core',
115
+			$this->getAssetUrl('eejs', self::ASSET_TYPE_JS),
116
+			array('ee-manifest'),
117
+			null,
118
+			true
119
+		);
120
+		wp_register_script(
121
+			'ee-vendor-react',
122
+			$this->getAssetUrl('vendorReact', self::ASSET_TYPE_JS),
123
+			array('eejs-core'),
124
+			null,
125
+			true
126
+		);
127
+		//only run this if WordPress 4.4.0 > is in use.
128
+		if (version_compare($wp_version, '4.4.0', '>')) {
129
+			//js.api
130
+			wp_register_script(
131
+				'eejs-api',
132
+				EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
133
+				array('underscore', 'eejs-core'),
134
+				EVENT_ESPRESSO_VERSION,
135
+				true
136
+			);
137
+			$this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest');
138
+			$this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/'));
139
+		}
140
+		if (! is_admin()) {
141
+			$this->loadCoreCss();
142
+		}
143
+		$this->loadCoreJs();
144
+		$this->loadJqueryValidate();
145
+		$this->loadAccountingJs();
146
+		$this->loadQtipJs();
147
+	}
148
+
149
+
150
+
151
+	/**
152
+	 * Call back for the script print in frontend and backend.
153
+	 * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
154
+	 *
155
+	 * @since 4.9.31.rc.015
156
+	 */
157
+	public function enqueueData()
158
+	{
159
+		$this->removeAlreadyRegisteredDataForScriptHandles();
160
+		wp_localize_script('eejs-core', 'eejsdata', array('data' => $this->jsdata));
161
+		wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings);
162
+		$this->localizeAccountingJs();
163
+		$this->addRegisteredScriptHandlesWithData('eejs-core');
164
+		$this->addRegisteredScriptHandlesWithData('espresso_core');
165
+	}
166
+
167
+
168
+
169
+	/**
170
+	 * Used to add data to eejs.data object.
171
+	 * Note:  Overriding existing data is not allowed.
172
+	 * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
173
+	 * If the data you add is something like this:
174
+	 *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
175
+	 * It will be exposed in the page source as:
176
+	 *  eejs.data.my_plugin_data.foo == gar
177
+	 *
178
+	 * @param string       $key   Key used to access your data
179
+	 * @param string|array $value Value to attach to key
180
+	 * @throws InvalidArgumentException
181
+	 */
182
+	public function addData($key, $value)
183
+	{
184
+		if ($this->verifyDataNotExisting($key)) {
185
+			$this->jsdata[$key] = $value;
186
+		}
187
+	}
188
+
189
+
190
+
191
+	/**
192
+	 * Similar to addData except this allows for users to push values to an existing key where the values on key are
193
+	 * elements in an array.
194
+	 * When you use this method, the value you include will be appended to the end of an array on $key.
195
+	 * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript
196
+	 * object like this, eejs.data.test = [ my_data,
197
+	 * ]
198
+	 * If there has already been a scalar value attached to the data object given key, then
199
+	 * this will throw an exception.
200
+	 *
201
+	 * @param string       $key   Key to attach data to.
202
+	 * @param string|array $value Value being registered.
203
+	 * @throws InvalidArgumentException
204
+	 */
205
+	public function pushData($key, $value)
206
+	{
207
+		if (isset($this->jsdata[$key])
208
+			&& ! is_array($this->jsdata[$key])
209
+		) {
210
+			throw new invalidArgumentException(
211
+				sprintf(
212
+					__(
213
+						'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
214 214
                          push values to this data element when it is an array.',
215
-                        'event_espresso'
216
-                    ),
217
-                    $key,
218
-                    __METHOD__
219
-                )
220
-            );
221
-        }
222
-        $this->jsdata[$key][] = $value;
223
-    }
224
-
225
-
226
-
227
-    /**
228
-     * Used to set content used by javascript for a template.
229
-     * Note: Overrides of existing registered templates are not allowed.
230
-     *
231
-     * @param string $template_reference
232
-     * @param string $template_content
233
-     * @throws InvalidArgumentException
234
-     */
235
-    public function addTemplate($template_reference, $template_content)
236
-    {
237
-        if (! isset($this->jsdata['templates'])) {
238
-            $this->jsdata['templates'] = array();
239
-        }
240
-        //no overrides allowed.
241
-        if (isset($this->jsdata['templates'][$template_reference])) {
242
-            throw new invalidArgumentException(
243
-                sprintf(
244
-                    __(
245
-                        'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
246
-                        'event_espresso'
247
-                    ),
248
-                    $template_reference
249
-                )
250
-            );
251
-        }
252
-        $this->jsdata['templates'][$template_reference] = $template_content;
253
-    }
254
-
255
-
256
-
257
-    /**
258
-     * Retrieve the template content already registered for the given reference.
259
-     *
260
-     * @param string $template_reference
261
-     * @return string
262
-     */
263
-    public function getTemplate($template_reference)
264
-    {
265
-        return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference])
266
-            ? $this->jsdata['templates'][$template_reference]
267
-            : '';
268
-    }
269
-
270
-
271
-
272
-    /**
273
-     * Retrieve registered data.
274
-     *
275
-     * @param string $key Name of key to attach data to.
276
-     * @return mixed                If there is no for the given key, then false is returned.
277
-     */
278
-    public function getData($key)
279
-    {
280
-        return isset($this->jsdata[$key])
281
-            ? $this->jsdata[$key]
282
-            : false;
283
-    }
284
-
285
-
286
-    /**
287
-     * Get the actual asset path for asset manifests.
288
-     * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
289
-     * @param string $chunk_name
290
-     * @param string $asset_type
291
-     * @return string
292
-     * @throws InvalidFilePathException
293
-     * @since $VID:$
294
-     */
295
-    public function getAssetUrl($chunk_name, $asset_type)
296
-    {
297
-        if (empty($this->cached_manifests)) {
298
-            $this->registerManifests();
299
-        }
300
-        return isset($this->cached_manifests[$chunk_name][$asset_type])
301
-            ? $this->domain->distributionAssetsUrl() . $this->cached_manifests[$chunk_name][$asset_type]
302
-            : $chunk_name;
303
-    }
304
-
305
-
306
-    /**
307
-     * Register any asset manifests.
308
-     * @throws InvalidFilePathException
309
-     * @since $VID:$
310
-     */
311
-    private function registerManifests()
312
-    {
313
-        if (! empty($this->cached_manifests)) {
314
-            //already registered get out.  This usually means that a $chunk_name (argument for getAssetUrl call) either
315
-            //doesn't exist in any registered manifest files.  This could be because the $chunk_name is an actual file
316
-            //url and thus not registered in the manifest, or a plugin registered its manifest files too late.
317
-            return;
318
-        }
319
-        $registered_manifest_files = apply_filters(
320
-            'FHEE__EventEspresso_core_services_assets_Registry__registerManifests__registered_manifest_files',
321
-            $this->domain->distributionAssetsPath() . 'build-manifest.json'
322
-        );
323
-        foreach ($registered_manifest_files as $file) {
324
-            if (! file_exists($file)) {
325
-                throw new InvalidFilePathException($file);
326
-            }
327
-            /** recommended to avoid array_merge in loops */
328
-            $this->cached_manifests[] = json_decode(file_get_contents($file), true);
329
-        }
330
-        //PHP below 5.6
331
-        $this->cached_manifests = call_user_func_array('array_merge', $this->cached_manifests);
332
-        //We can use this once we support PHP5.6+
333
-        //$this->cached_manifests = array_merge(...$this->cached_manifests);
334
-    }
335
-
336
-
337
-
338
-    /**
339
-     * Verifies whether the given data exists already on the jsdata array.
340
-     * Overriding data is not allowed.
341
-     *
342
-     * @param string $key Index for data.
343
-     * @return bool        If valid then return true.
344
-     * @throws InvalidArgumentException if data already exists.
345
-     */
346
-    protected function verifyDataNotExisting($key)
347
-    {
348
-        if (isset($this->jsdata[$key])) {
349
-            if (is_array($this->jsdata[$key])) {
350
-                throw new InvalidArgumentException(
351
-                    sprintf(
352
-                        __(
353
-                            'The value for %1$s already exists in the Registry::eejs object.
215
+						'event_espresso'
216
+					),
217
+					$key,
218
+					__METHOD__
219
+				)
220
+			);
221
+		}
222
+		$this->jsdata[$key][] = $value;
223
+	}
224
+
225
+
226
+
227
+	/**
228
+	 * Used to set content used by javascript for a template.
229
+	 * Note: Overrides of existing registered templates are not allowed.
230
+	 *
231
+	 * @param string $template_reference
232
+	 * @param string $template_content
233
+	 * @throws InvalidArgumentException
234
+	 */
235
+	public function addTemplate($template_reference, $template_content)
236
+	{
237
+		if (! isset($this->jsdata['templates'])) {
238
+			$this->jsdata['templates'] = array();
239
+		}
240
+		//no overrides allowed.
241
+		if (isset($this->jsdata['templates'][$template_reference])) {
242
+			throw new invalidArgumentException(
243
+				sprintf(
244
+					__(
245
+						'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
246
+						'event_espresso'
247
+					),
248
+					$template_reference
249
+				)
250
+			);
251
+		}
252
+		$this->jsdata['templates'][$template_reference] = $template_content;
253
+	}
254
+
255
+
256
+
257
+	/**
258
+	 * Retrieve the template content already registered for the given reference.
259
+	 *
260
+	 * @param string $template_reference
261
+	 * @return string
262
+	 */
263
+	public function getTemplate($template_reference)
264
+	{
265
+		return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference])
266
+			? $this->jsdata['templates'][$template_reference]
267
+			: '';
268
+	}
269
+
270
+
271
+
272
+	/**
273
+	 * Retrieve registered data.
274
+	 *
275
+	 * @param string $key Name of key to attach data to.
276
+	 * @return mixed                If there is no for the given key, then false is returned.
277
+	 */
278
+	public function getData($key)
279
+	{
280
+		return isset($this->jsdata[$key])
281
+			? $this->jsdata[$key]
282
+			: false;
283
+	}
284
+
285
+
286
+	/**
287
+	 * Get the actual asset path for asset manifests.
288
+	 * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
289
+	 * @param string $chunk_name
290
+	 * @param string $asset_type
291
+	 * @return string
292
+	 * @throws InvalidFilePathException
293
+	 * @since $VID:$
294
+	 */
295
+	public function getAssetUrl($chunk_name, $asset_type)
296
+	{
297
+		if (empty($this->cached_manifests)) {
298
+			$this->registerManifests();
299
+		}
300
+		return isset($this->cached_manifests[$chunk_name][$asset_type])
301
+			? $this->domain->distributionAssetsUrl() . $this->cached_manifests[$chunk_name][$asset_type]
302
+			: $chunk_name;
303
+	}
304
+
305
+
306
+	/**
307
+	 * Register any asset manifests.
308
+	 * @throws InvalidFilePathException
309
+	 * @since $VID:$
310
+	 */
311
+	private function registerManifests()
312
+	{
313
+		if (! empty($this->cached_manifests)) {
314
+			//already registered get out.  This usually means that a $chunk_name (argument for getAssetUrl call) either
315
+			//doesn't exist in any registered manifest files.  This could be because the $chunk_name is an actual file
316
+			//url and thus not registered in the manifest, or a plugin registered its manifest files too late.
317
+			return;
318
+		}
319
+		$registered_manifest_files = apply_filters(
320
+			'FHEE__EventEspresso_core_services_assets_Registry__registerManifests__registered_manifest_files',
321
+			$this->domain->distributionAssetsPath() . 'build-manifest.json'
322
+		);
323
+		foreach ($registered_manifest_files as $file) {
324
+			if (! file_exists($file)) {
325
+				throw new InvalidFilePathException($file);
326
+			}
327
+			/** recommended to avoid array_merge in loops */
328
+			$this->cached_manifests[] = json_decode(file_get_contents($file), true);
329
+		}
330
+		//PHP below 5.6
331
+		$this->cached_manifests = call_user_func_array('array_merge', $this->cached_manifests);
332
+		//We can use this once we support PHP5.6+
333
+		//$this->cached_manifests = array_merge(...$this->cached_manifests);
334
+	}
335
+
336
+
337
+
338
+	/**
339
+	 * Verifies whether the given data exists already on the jsdata array.
340
+	 * Overriding data is not allowed.
341
+	 *
342
+	 * @param string $key Index for data.
343
+	 * @return bool        If valid then return true.
344
+	 * @throws InvalidArgumentException if data already exists.
345
+	 */
346
+	protected function verifyDataNotExisting($key)
347
+	{
348
+		if (isset($this->jsdata[$key])) {
349
+			if (is_array($this->jsdata[$key])) {
350
+				throw new InvalidArgumentException(
351
+					sprintf(
352
+						__(
353
+							'The value for %1$s already exists in the Registry::eejs object.
354 354
                             Overrides are not allowed. Since the value of this data is an array, you may want to use the
355 355
                             %2$s method to push your value to the array.',
356
-                            'event_espresso'
357
-                        ),
358
-                        $key,
359
-                        'pushData()'
360
-                    )
361
-                );
362
-            }
363
-            throw new InvalidArgumentException(
364
-                sprintf(
365
-                    __(
366
-                        'The value for %1$s already exists in the Registry::eejs object. Overrides are not
356
+							'event_espresso'
357
+						),
358
+						$key,
359
+						'pushData()'
360
+					)
361
+				);
362
+			}
363
+			throw new InvalidArgumentException(
364
+				sprintf(
365
+					__(
366
+						'The value for %1$s already exists in the Registry::eejs object. Overrides are not
367 367
                         allowed.  Consider attaching your value to a different key',
368
-                        'event_espresso'
369
-                    ),
370
-                    $key
371
-                )
372
-            );
373
-        }
374
-        return true;
375
-    }
376
-
377
-
378
-
379
-    /**
380
-     * registers core default stylesheets
381
-     */
382
-    private function loadCoreCss()
383
-    {
384
-        if ($this->template_config->enable_default_style) {
385
-            $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
386
-                ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
387
-                : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css';
388
-            wp_register_style(
389
-                'espresso_default',
390
-                $default_stylesheet_path,
391
-                array('dashicons'),
392
-                EVENT_ESPRESSO_VERSION
393
-            );
394
-            //Load custom style sheet if available
395
-            if ($this->template_config->custom_style_sheet !== null) {
396
-                wp_register_style(
397
-                    'espresso_custom_css',
398
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
399
-                    array('espresso_default'),
400
-                    EVENT_ESPRESSO_VERSION
401
-                );
402
-            }
403
-        }
404
-    }
405
-
406
-
407
-
408
-    /**
409
-     * registers core default javascript
410
-     */
411
-    private function loadCoreJs()
412
-    {
413
-        // load core js
414
-        wp_register_script(
415
-            'espresso_core',
416
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
417
-            array('jquery'),
418
-            EVENT_ESPRESSO_VERSION,
419
-            true
420
-        );
421
-    }
422
-
423
-
424
-
425
-    /**
426
-     * registers jQuery Validate for form validation
427
-     */
428
-    private function loadJqueryValidate()
429
-    {
430
-        // register jQuery Validate and additional methods
431
-        wp_register_script(
432
-            'jquery-validate',
433
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
434
-            array('jquery'),
435
-            '1.15.0',
436
-            true
437
-        );
438
-        wp_register_script(
439
-            'jquery-validate-extra-methods',
440
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
441
-            array('jquery', 'jquery-validate'),
442
-            '1.15.0',
443
-            true
444
-        );
445
-    }
446
-
447
-
448
-
449
-    /**
450
-     * registers accounting.js for performing client-side calculations
451
-     */
452
-    private function loadAccountingJs()
453
-    {
454
-        //accounting.js library
455
-        // @link http://josscrowcroft.github.io/accounting.js/
456
-        wp_register_script(
457
-            'ee-accounting-core',
458
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
459
-            array('underscore'),
460
-            '0.3.2',
461
-            true
462
-        );
463
-        wp_register_script(
464
-            'ee-accounting',
465
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
466
-            array('ee-accounting-core'),
467
-            EVENT_ESPRESSO_VERSION,
468
-            true
469
-        );
470
-    }
471
-
472
-
473
-
474
-    /**
475
-     * registers accounting.js for performing client-side calculations
476
-     */
477
-    private function localizeAccountingJs()
478
-    {
479
-        wp_localize_script(
480
-            'ee-accounting',
481
-            'EE_ACCOUNTING_CFG',
482
-            array(
483
-                'currency' => array(
484
-                    'symbol'    => $this->currency_config->sign,
485
-                    'format'    => array(
486
-                        'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
487
-                        'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
488
-                        'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
489
-                    ),
490
-                    'decimal'   => $this->currency_config->dec_mrk,
491
-                    'thousand'  => $this->currency_config->thsnds,
492
-                    'precision' => $this->currency_config->dec_plc,
493
-                ),
494
-                'number'   => array(
495
-                    'precision' => $this->currency_config->dec_plc,
496
-                    'thousand'  => $this->currency_config->thsnds,
497
-                    'decimal'   => $this->currency_config->dec_mrk,
498
-                ),
499
-            )
500
-        );
501
-        $this->addRegisteredScriptHandlesWithData('ee-accounting');
502
-    }
503
-
504
-
505
-
506
-    /**
507
-     * registers assets for cleaning your ears
508
-     */
509
-    private function loadQtipJs()
510
-    {
511
-        // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
512
-        // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
513
-        if (apply_filters('FHEE_load_qtip', false)) {
514
-            EEH_Qtip_Loader::instance()->register_and_enqueue();
515
-        }
516
-    }
517
-
518
-
519
-    /**
520
-     * This is used to set registered script handles that have data.
521
-     * @param string $script_handle
522
-     */
523
-    private function addRegisteredScriptHandlesWithData($script_handle)
524
-    {
525
-        $this->script_handles_with_data[$script_handle] = $script_handle;
526
-    }
527
-
528
-
529
-    /**
530
-     * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the
531
-     * Dependency stored in WP_Scripts if its set.
532
-     */
533
-    private function removeAlreadyRegisteredDataForScriptHandles()
534
-    {
535
-        if (empty($this->script_handles_with_data)) {
536
-            return;
537
-        }
538
-        foreach ($this->script_handles_with_data as $script_handle) {
539
-            $this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
540
-        }
541
-    }
542
-
543
-
544
-    /**
545
-     * Removes any data dependency registered in WP_Scripts if its set.
546
-     * @param string $script_handle
547
-     */
548
-    private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
549
-    {
550
-        if (isset($this->script_handles_with_data[$script_handle])) {
551
-            global $wp_scripts;
552
-            if ($wp_scripts->get_data($script_handle, 'data')) {
553
-                unset($wp_scripts->registered[$script_handle]->extra['data']);
554
-                unset($this->script_handles_with_data[$script_handle]);
555
-            }
556
-        }
557
-    }
368
+						'event_espresso'
369
+					),
370
+					$key
371
+				)
372
+			);
373
+		}
374
+		return true;
375
+	}
376
+
377
+
378
+
379
+	/**
380
+	 * registers core default stylesheets
381
+	 */
382
+	private function loadCoreCss()
383
+	{
384
+		if ($this->template_config->enable_default_style) {
385
+			$default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
386
+				? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
387
+				: EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css';
388
+			wp_register_style(
389
+				'espresso_default',
390
+				$default_stylesheet_path,
391
+				array('dashicons'),
392
+				EVENT_ESPRESSO_VERSION
393
+			);
394
+			//Load custom style sheet if available
395
+			if ($this->template_config->custom_style_sheet !== null) {
396
+				wp_register_style(
397
+					'espresso_custom_css',
398
+					EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
399
+					array('espresso_default'),
400
+					EVENT_ESPRESSO_VERSION
401
+				);
402
+			}
403
+		}
404
+	}
405
+
406
+
407
+
408
+	/**
409
+	 * registers core default javascript
410
+	 */
411
+	private function loadCoreJs()
412
+	{
413
+		// load core js
414
+		wp_register_script(
415
+			'espresso_core',
416
+			EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
417
+			array('jquery'),
418
+			EVENT_ESPRESSO_VERSION,
419
+			true
420
+		);
421
+	}
422
+
423
+
424
+
425
+	/**
426
+	 * registers jQuery Validate for form validation
427
+	 */
428
+	private function loadJqueryValidate()
429
+	{
430
+		// register jQuery Validate and additional methods
431
+		wp_register_script(
432
+			'jquery-validate',
433
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
434
+			array('jquery'),
435
+			'1.15.0',
436
+			true
437
+		);
438
+		wp_register_script(
439
+			'jquery-validate-extra-methods',
440
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
441
+			array('jquery', 'jquery-validate'),
442
+			'1.15.0',
443
+			true
444
+		);
445
+	}
446
+
447
+
448
+
449
+	/**
450
+	 * registers accounting.js for performing client-side calculations
451
+	 */
452
+	private function loadAccountingJs()
453
+	{
454
+		//accounting.js library
455
+		// @link http://josscrowcroft.github.io/accounting.js/
456
+		wp_register_script(
457
+			'ee-accounting-core',
458
+			EE_THIRD_PARTY_URL . 'accounting/accounting.js',
459
+			array('underscore'),
460
+			'0.3.2',
461
+			true
462
+		);
463
+		wp_register_script(
464
+			'ee-accounting',
465
+			EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
466
+			array('ee-accounting-core'),
467
+			EVENT_ESPRESSO_VERSION,
468
+			true
469
+		);
470
+	}
471
+
472
+
473
+
474
+	/**
475
+	 * registers accounting.js for performing client-side calculations
476
+	 */
477
+	private function localizeAccountingJs()
478
+	{
479
+		wp_localize_script(
480
+			'ee-accounting',
481
+			'EE_ACCOUNTING_CFG',
482
+			array(
483
+				'currency' => array(
484
+					'symbol'    => $this->currency_config->sign,
485
+					'format'    => array(
486
+						'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
487
+						'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
488
+						'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
489
+					),
490
+					'decimal'   => $this->currency_config->dec_mrk,
491
+					'thousand'  => $this->currency_config->thsnds,
492
+					'precision' => $this->currency_config->dec_plc,
493
+				),
494
+				'number'   => array(
495
+					'precision' => $this->currency_config->dec_plc,
496
+					'thousand'  => $this->currency_config->thsnds,
497
+					'decimal'   => $this->currency_config->dec_mrk,
498
+				),
499
+			)
500
+		);
501
+		$this->addRegisteredScriptHandlesWithData('ee-accounting');
502
+	}
503
+
504
+
505
+
506
+	/**
507
+	 * registers assets for cleaning your ears
508
+	 */
509
+	private function loadQtipJs()
510
+	{
511
+		// qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
512
+		// can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
513
+		if (apply_filters('FHEE_load_qtip', false)) {
514
+			EEH_Qtip_Loader::instance()->register_and_enqueue();
515
+		}
516
+	}
517
+
518
+
519
+	/**
520
+	 * This is used to set registered script handles that have data.
521
+	 * @param string $script_handle
522
+	 */
523
+	private function addRegisteredScriptHandlesWithData($script_handle)
524
+	{
525
+		$this->script_handles_with_data[$script_handle] = $script_handle;
526
+	}
527
+
528
+
529
+	/**
530
+	 * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the
531
+	 * Dependency stored in WP_Scripts if its set.
532
+	 */
533
+	private function removeAlreadyRegisteredDataForScriptHandles()
534
+	{
535
+		if (empty($this->script_handles_with_data)) {
536
+			return;
537
+		}
538
+		foreach ($this->script_handles_with_data as $script_handle) {
539
+			$this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
540
+		}
541
+	}
542
+
543
+
544
+	/**
545
+	 * Removes any data dependency registered in WP_Scripts if its set.
546
+	 * @param string $script_handle
547
+	 */
548
+	private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
549
+	{
550
+		if (isset($this->script_handles_with_data[$script_handle])) {
551
+			global $wp_scripts;
552
+			if ($wp_scripts->get_data($script_handle, 'data')) {
553
+				unset($wp_scripts->registered[$script_handle]->extra['data']);
554
+				unset($this->script_handles_with_data[$script_handle]);
555
+			}
556
+		}
557
+	}
558 558
 
559 559
 
560 560
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
             //js.api
130 130
             wp_register_script(
131 131
                 'eejs-api',
132
-                EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
132
+                EE_LIBRARIES_URL.'rest_api/assets/js/eejs-api.min.js',
133 133
                 array('underscore', 'eejs-core'),
134 134
                 EVENT_ESPRESSO_VERSION,
135 135
                 true
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
             $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest');
138 138
             $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/'));
139 139
         }
140
-        if (! is_admin()) {
140
+        if ( ! is_admin()) {
141 141
             $this->loadCoreCss();
142 142
         }
143 143
         $this->loadCoreJs();
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
      */
235 235
     public function addTemplate($template_reference, $template_content)
236 236
     {
237
-        if (! isset($this->jsdata['templates'])) {
237
+        if ( ! isset($this->jsdata['templates'])) {
238 238
             $this->jsdata['templates'] = array();
239 239
         }
240 240
         //no overrides allowed.
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
             $this->registerManifests();
299 299
         }
300 300
         return isset($this->cached_manifests[$chunk_name][$asset_type])
301
-            ? $this->domain->distributionAssetsUrl() . $this->cached_manifests[$chunk_name][$asset_type]
301
+            ? $this->domain->distributionAssetsUrl().$this->cached_manifests[$chunk_name][$asset_type]
302 302
             : $chunk_name;
303 303
     }
304 304
 
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
      */
311 311
     private function registerManifests()
312 312
     {
313
-        if (! empty($this->cached_manifests)) {
313
+        if ( ! empty($this->cached_manifests)) {
314 314
             //already registered get out.  This usually means that a $chunk_name (argument for getAssetUrl call) either
315 315
             //doesn't exist in any registered manifest files.  This could be because the $chunk_name is an actual file
316 316
             //url and thus not registered in the manifest, or a plugin registered its manifest files too late.
@@ -318,10 +318,10 @@  discard block
 block discarded – undo
318 318
         }
319 319
         $registered_manifest_files = apply_filters(
320 320
             'FHEE__EventEspresso_core_services_assets_Registry__registerManifests__registered_manifest_files',
321
-            $this->domain->distributionAssetsPath() . 'build-manifest.json'
321
+            $this->domain->distributionAssetsPath().'build-manifest.json'
322 322
         );
323 323
         foreach ($registered_manifest_files as $file) {
324
-            if (! file_exists($file)) {
324
+            if ( ! file_exists($file)) {
325 325
                 throw new InvalidFilePathException($file);
326 326
             }
327 327
             /** recommended to avoid array_merge in loops */
@@ -382,9 +382,9 @@  discard block
 block discarded – undo
382 382
     private function loadCoreCss()
383 383
     {
384 384
         if ($this->template_config->enable_default_style) {
385
-            $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
385
+            $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/style.css')
386 386
                 ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
387
-                : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css';
387
+                : EE_GLOBAL_ASSETS_URL.'css/espresso_default.css';
388 388
             wp_register_style(
389 389
                 'espresso_default',
390 390
                 $default_stylesheet_path,
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
             if ($this->template_config->custom_style_sheet !== null) {
396 396
                 wp_register_style(
397 397
                     'espresso_custom_css',
398
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
398
+                    EVENT_ESPRESSO_UPLOAD_URL.'css/'.$this->template_config->custom_style_sheet,
399 399
                     array('espresso_default'),
400 400
                     EVENT_ESPRESSO_VERSION
401 401
                 );
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
         // load core js
414 414
         wp_register_script(
415 415
             'espresso_core',
416
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
416
+            EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js',
417 417
             array('jquery'),
418 418
             EVENT_ESPRESSO_VERSION,
419 419
             true
@@ -430,14 +430,14 @@  discard block
 block discarded – undo
430 430
         // register jQuery Validate and additional methods
431 431
         wp_register_script(
432 432
             'jquery-validate',
433
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
433
+            EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.min.js',
434 434
             array('jquery'),
435 435
             '1.15.0',
436 436
             true
437 437
         );
438 438
         wp_register_script(
439 439
             'jquery-validate-extra-methods',
440
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
440
+            EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.additional-methods.min.js',
441 441
             array('jquery', 'jquery-validate'),
442 442
             '1.15.0',
443 443
             true
@@ -455,14 +455,14 @@  discard block
 block discarded – undo
455 455
         // @link http://josscrowcroft.github.io/accounting.js/
456 456
         wp_register_script(
457 457
             'ee-accounting-core',
458
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
458
+            EE_THIRD_PARTY_URL.'accounting/accounting.js',
459 459
             array('underscore'),
460 460
             '0.3.2',
461 461
             true
462 462
         );
463 463
         wp_register_script(
464 464
             'ee-accounting',
465
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
465
+            EE_GLOBAL_ASSETS_URL.'scripts/ee-accounting-config.js',
466 466
             array('ee-accounting-core'),
467 467
             EVENT_ESPRESSO_VERSION,
468 468
             true
Please login to merge, or discard this patch.