Completed
Branch Gutenberg/event-attendees-bloc... (76b12a)
by
unknown
78:26 queued 65:41
created
core/domain/values/assets/BrowserAsset.php 1 patch
Indentation   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -16,136 +16,136 @@
 block discarded – undo
16 16
 abstract class BrowserAsset extends Asset
17 17
 {
18 18
 
19
-    /**
20
-     * @var string $source
21
-     */
22
-    private $source;
23
-
24
-    /**
25
-     * @var array $dependencies
26
-     */
27
-    private $dependencies;
28
-
29
-    /**
30
-     * @var string $version
31
-     */
32
-    private $version;
33
-
34
-
35
-    /**
36
-     * Asset constructor.
37
-     *
38
-     * @param string          $type
39
-     * @param string          $handle
40
-     * @param string          $source
41
-     * @param array           $dependencies
42
-     * @param DomainInterface $domain
43
-     * @throws InvalidDataTypeException
44
-     */
45
-    public function __construct($type, $handle, $source, array $dependencies, DomainInterface $domain)
46
-    {
47
-        parent::__construct($type, $handle, $domain);
48
-        $this->setSource($source);
49
-        $this->setDependencies($dependencies);
50
-    }
51
-
52
-
53
-    /**
54
-     * @since 4.9.62.p
55
-     */
56
-    abstract public function enqueueAsset();
57
-
58
-
59
-    /**
60
-     * @return array
61
-     */
62
-    public function dependencies()
63
-    {
64
-        return $this->dependencies;
65
-    }
66
-
67
-
68
-    /**
69
-     * @param array $dependencies
70
-     */
71
-    private function setDependencies(array $dependencies)
72
-    {
73
-        $this->dependencies = $dependencies;
74
-    }
75
-
76
-
77
-    /**
78
-     * @since 4.9.62.p
79
-     * @return bool
80
-     */
81
-    public function hasDependencies()
82
-    {
83
-        return count($this->dependencies) > 0;
84
-    }
85
-
86
-
87
-    /**
88
-     * @return string
89
-     */
90
-    public function source()
91
-    {
92
-        return $this->source;
93
-    }
94
-
95
-
96
-    /**
97
-     * @param string $source
98
-     * @throws InvalidDataTypeException
99
-     */
100
-    private function setSource($source)
101
-    {
102
-        if (! is_string($source)) {
103
-            throw new InvalidDataTypeException(
104
-                '$source',
105
-                $source,
106
-                'string'
107
-            );
108
-        }
109
-        $this->source = $source;
110
-    }
111
-
112
-
113
-    /**
114
-     * @return string
115
-     * @throws InvalidDataTypeException
116
-     */
117
-    public function version()
118
-    {
119
-        // if version is NOT set and this asset was NOT built for distribution,
120
-        // then set the version equal to the EE core plugin version
121
-        if (
122
-            $this->version === null
123
-            && (
124
-                substr($this->source, -8) !== Asset::FILE_EXTENSION_DISTRIBUTION_JS
125
-                || substr($this->source, -9) !== Asset::FILE_EXTENSION_DISTRIBUTION_CSS
126
-            )
127
-        ) {
128
-            $this->setVersion();
129
-        }
130
-        return $this->version;
131
-    }
132
-
133
-
134
-    /**
135
-     * @param string $version
136
-     * @return BrowserAsset
137
-     * @throws InvalidDataTypeException
138
-     */
139
-    public function setVersion($version = EVENT_ESPRESSO_VERSION)
140
-    {
141
-        if (! is_string($version)) {
142
-            throw new InvalidDataTypeException(
143
-                '$version',
144
-                $version,
145
-                'string'
146
-            );
147
-        }
148
-        $this->version = $version;
149
-        return $this;
150
-    }
19
+	/**
20
+	 * @var string $source
21
+	 */
22
+	private $source;
23
+
24
+	/**
25
+	 * @var array $dependencies
26
+	 */
27
+	private $dependencies;
28
+
29
+	/**
30
+	 * @var string $version
31
+	 */
32
+	private $version;
33
+
34
+
35
+	/**
36
+	 * Asset constructor.
37
+	 *
38
+	 * @param string          $type
39
+	 * @param string          $handle
40
+	 * @param string          $source
41
+	 * @param array           $dependencies
42
+	 * @param DomainInterface $domain
43
+	 * @throws InvalidDataTypeException
44
+	 */
45
+	public function __construct($type, $handle, $source, array $dependencies, DomainInterface $domain)
46
+	{
47
+		parent::__construct($type, $handle, $domain);
48
+		$this->setSource($source);
49
+		$this->setDependencies($dependencies);
50
+	}
51
+
52
+
53
+	/**
54
+	 * @since 4.9.62.p
55
+	 */
56
+	abstract public function enqueueAsset();
57
+
58
+
59
+	/**
60
+	 * @return array
61
+	 */
62
+	public function dependencies()
63
+	{
64
+		return $this->dependencies;
65
+	}
66
+
67
+
68
+	/**
69
+	 * @param array $dependencies
70
+	 */
71
+	private function setDependencies(array $dependencies)
72
+	{
73
+		$this->dependencies = $dependencies;
74
+	}
75
+
76
+
77
+	/**
78
+	 * @since 4.9.62.p
79
+	 * @return bool
80
+	 */
81
+	public function hasDependencies()
82
+	{
83
+		return count($this->dependencies) > 0;
84
+	}
85
+
86
+
87
+	/**
88
+	 * @return string
89
+	 */
90
+	public function source()
91
+	{
92
+		return $this->source;
93
+	}
94
+
95
+
96
+	/**
97
+	 * @param string $source
98
+	 * @throws InvalidDataTypeException
99
+	 */
100
+	private function setSource($source)
101
+	{
102
+		if (! is_string($source)) {
103
+			throw new InvalidDataTypeException(
104
+				'$source',
105
+				$source,
106
+				'string'
107
+			);
108
+		}
109
+		$this->source = $source;
110
+	}
111
+
112
+
113
+	/**
114
+	 * @return string
115
+	 * @throws InvalidDataTypeException
116
+	 */
117
+	public function version()
118
+	{
119
+		// if version is NOT set and this asset was NOT built for distribution,
120
+		// then set the version equal to the EE core plugin version
121
+		if (
122
+			$this->version === null
123
+			&& (
124
+				substr($this->source, -8) !== Asset::FILE_EXTENSION_DISTRIBUTION_JS
125
+				|| substr($this->source, -9) !== Asset::FILE_EXTENSION_DISTRIBUTION_CSS
126
+			)
127
+		) {
128
+			$this->setVersion();
129
+		}
130
+		return $this->version;
131
+	}
132
+
133
+
134
+	/**
135
+	 * @param string $version
136
+	 * @return BrowserAsset
137
+	 * @throws InvalidDataTypeException
138
+	 */
139
+	public function setVersion($version = EVENT_ESPRESSO_VERSION)
140
+	{
141
+		if (! is_string($version)) {
142
+			throw new InvalidDataTypeException(
143
+				'$version',
144
+				$version,
145
+				'string'
146
+			);
147
+		}
148
+		$this->version = $version;
149
+		return $this;
150
+	}
151 151
 }
Please login to merge, or discard this patch.
core/domain/services/custom_post_types/RegisterCustomTaxonomies.php 1 patch
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -17,97 +17,97 @@
 block discarded – undo
17 17
 class RegisterCustomTaxonomies
18 18
 {
19 19
 
20
-    /**
21
-     * @var CustomTaxonomyDefinitions $custom_taxonomies
22
-     */
23
-    public $custom_taxonomies;
20
+	/**
21
+	 * @var CustomTaxonomyDefinitions $custom_taxonomies
22
+	 */
23
+	public $custom_taxonomies;
24 24
 
25 25
 
26
-    /**
27
-     * RegisterCustomTaxonomies constructor.
28
-     *
29
-     * @param CustomTaxonomyDefinitions $custom_taxonomies
30
-     */
31
-    public function __construct(CustomTaxonomyDefinitions $custom_taxonomies)
32
-    {
33
-        $this->custom_taxonomies = $custom_taxonomies;
34
-    }
26
+	/**
27
+	 * RegisterCustomTaxonomies constructor.
28
+	 *
29
+	 * @param CustomTaxonomyDefinitions $custom_taxonomies
30
+	 */
31
+	public function __construct(CustomTaxonomyDefinitions $custom_taxonomies)
32
+	{
33
+		$this->custom_taxonomies = $custom_taxonomies;
34
+	}
35 35
 
36 36
 
37
-    /**
38
-     * @return void
39
-     * @throws DomainException
40
-     */
41
-    public function registerCustomTaxonomies()
42
-    {
43
-        $custom_taxonomies = $this->custom_taxonomies->getCustomTaxonomyDefinitions();
44
-        foreach ($custom_taxonomies as $taxonomy => $tax) {
45
-            $this->registerCustomTaxonomy(
46
-                $taxonomy,
47
-                $tax['singular_name'],
48
-                $tax['plural_name'],
49
-                $tax['args']
50
-            );
51
-        }
52
-    }
37
+	/**
38
+	 * @return void
39
+	 * @throws DomainException
40
+	 */
41
+	public function registerCustomTaxonomies()
42
+	{
43
+		$custom_taxonomies = $this->custom_taxonomies->getCustomTaxonomyDefinitions();
44
+		foreach ($custom_taxonomies as $taxonomy => $tax) {
45
+			$this->registerCustomTaxonomy(
46
+				$taxonomy,
47
+				$tax['singular_name'],
48
+				$tax['plural_name'],
49
+				$tax['args']
50
+			);
51
+		}
52
+	}
53 53
 
54 54
 
55
-    /**
56
-     * Registers a custom taxonomy. Should be called before registering custom post types,
57
-     * otherwise you should link the taxonomy to the custom post type using 'register_taxonomy_for_object_type'.
58
-     *
59
-     * @param string $taxonomy_name      , eg 'books'
60
-     * @param string $singular_name      internationalized singular name
61
-     * @param string $plural_name        internationalized plural name
62
-     * @param array  $override_arguments like $args on http://codex.wordpress.org/Function_Reference/register_taxonomy
63
-     * @throws DomainException
64
-     */
65
-    public function registerCustomTaxonomy($taxonomy_name, $singular_name, $plural_name, array $override_arguments)
66
-    {
67
-        $result = register_taxonomy(
68
-            $taxonomy_name,
69
-            null,
70
-            $this->prepareArguments(
71
-                $singular_name,
72
-                $plural_name,
73
-                $override_arguments
74
-            )
75
-        );
76
-        if ($result instanceof WP_Error) {
77
-            throw new DomainException($result->get_error_message());
78
-        }
79
-    }
55
+	/**
56
+	 * Registers a custom taxonomy. Should be called before registering custom post types,
57
+	 * otherwise you should link the taxonomy to the custom post type using 'register_taxonomy_for_object_type'.
58
+	 *
59
+	 * @param string $taxonomy_name      , eg 'books'
60
+	 * @param string $singular_name      internationalized singular name
61
+	 * @param string $plural_name        internationalized plural name
62
+	 * @param array  $override_arguments like $args on http://codex.wordpress.org/Function_Reference/register_taxonomy
63
+	 * @throws DomainException
64
+	 */
65
+	public function registerCustomTaxonomy($taxonomy_name, $singular_name, $plural_name, array $override_arguments)
66
+	{
67
+		$result = register_taxonomy(
68
+			$taxonomy_name,
69
+			null,
70
+			$this->prepareArguments(
71
+				$singular_name,
72
+				$plural_name,
73
+				$override_arguments
74
+			)
75
+		);
76
+		if ($result instanceof WP_Error) {
77
+			throw new DomainException($result->get_error_message());
78
+		}
79
+	}
80 80
 
81 81
 
82
-    /**
83
-     * @param string $singular_name
84
-     * @param string $plural_name
85
-     * @param array  $override_arguments
86
-     * @since 4.9.62.p
87
-     * @return array
88
-     */
89
-    protected function prepareArguments($singular_name, $plural_name, array $override_arguments)
90
-    {
91
-        $arguments = array(
92
-            'hierarchical'      => true,
93
-            'labels'            => array(
94
-                'name'          => $plural_name,
95
-                'singular_name' => $singular_name,
96
-            ),
97
-            'show_ui'           => true,
98
-            'show_ee_ui'        => true,
99
-            'show_admin_column' => true,
100
-            'query_var'         => true,
101
-            'show_in_nav_menus' => false,
102
-            'map_meta_cap'      => true,
103
-        );
104
-        if ($override_arguments) {
105
-            if (isset($override_args['labels'])) {
106
-                $labels = array_merge($arguments['labels'], $override_arguments['labels']);
107
-                $arguments['labels'] = $labels;
108
-            }
109
-            $arguments = array_merge($arguments, $override_arguments);
110
-        }
111
-        return $arguments;
112
-    }
82
+	/**
83
+	 * @param string $singular_name
84
+	 * @param string $plural_name
85
+	 * @param array  $override_arguments
86
+	 * @since 4.9.62.p
87
+	 * @return array
88
+	 */
89
+	protected function prepareArguments($singular_name, $plural_name, array $override_arguments)
90
+	{
91
+		$arguments = array(
92
+			'hierarchical'      => true,
93
+			'labels'            => array(
94
+				'name'          => $plural_name,
95
+				'singular_name' => $singular_name,
96
+			),
97
+			'show_ui'           => true,
98
+			'show_ee_ui'        => true,
99
+			'show_admin_column' => true,
100
+			'query_var'         => true,
101
+			'show_in_nav_menus' => false,
102
+			'map_meta_cap'      => true,
103
+		);
104
+		if ($override_arguments) {
105
+			if (isset($override_args['labels'])) {
106
+				$labels = array_merge($arguments['labels'], $override_arguments['labels']);
107
+				$arguments['labels'] = $labels;
108
+			}
109
+			$arguments = array_merge($arguments, $override_arguments);
110
+		}
111
+		return $arguments;
112
+	}
113 113
 }
Please login to merge, or discard this patch.
core/CPTs/EE_Register_CPTs.core.php 1 patch
Indentation   +313 added lines, -313 removed lines patch added patch discarded remove patch
@@ -19,303 +19,303 @@  discard block
 block discarded – undo
19 19
 {
20 20
 
21 21
 
22
-    /**
23
-     * instantiated at init priority 5
24
-     *
25
-     * @deprecated 4.9.62.p
26
-     */
27
-    public function __construct()
28
-    {
29
-        do_action('AHEE__EE_Register_CPTs__construct_end', $this);
30
-    }
31
-
32
-
33
-    /**
34
-     * This will flush rewrite rules on demand.  This actually gets called around wp init priority level 100.
35
-     *
36
-     * @deprecated 4.9.62.p
37
-     * @return void
38
-     * @throws InvalidInterfaceException
39
-     * @throws InvalidDataTypeException
40
-     * @throws InvalidArgumentException
41
-     */
42
-    public static function maybe_flush_rewrite_rules()
43
-    {
44
-        /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
45
-        $rewrite_rules = LoaderFactory::getLoader()->getShared(
46
-            'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
47
-        );
48
-        $rewrite_rules->flushRewriteRules();
49
-    }
50
-
51
-
52
-    /**
53
-     * @return CustomTaxonomyDefinitions
54
-     * @throws InvalidArgumentException
55
-     * @throws InvalidDataTypeException
56
-     * @throws InvalidInterfaceException
57
-     */
58
-    public static function getTaxonomyDefinitions()
59
-    {
60
-        return LoaderFactory::getLoader()->getShared(
61
-            'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions'
62
-        );
63
-    }
64
-
65
-
66
-    /**
67
-     * @deprecated 4.9.62.p
68
-     * @param string $description The description content.
69
-     * @param string $taxonomy    The taxonomy name for the taxonomy being filtered.
70
-     * @return string
71
-     * @throws InvalidArgumentException
72
-     * @throws InvalidDataTypeException
73
-     * @throws InvalidInterfaceException
74
-     */
75
-    public function ee_filter_ee_term_description_not_wp($description, $taxonomy)
76
-    {
77
-        $taxonomies = EE_Register_CPTs::getTaxonomyDefinitions();
78
-        return $taxonomies->filterCustomTermDescription($description, $taxonomy);
79
-    }
80
-
81
-
82
-    /**
83
-     * @deprecated 4.9.62.p
84
-     * @return array
85
-     * @throws InvalidArgumentException
86
-     * @throws InvalidDataTypeException
87
-     * @throws InvalidInterfaceException
88
-     */
89
-    public static function get_taxonomies()
90
-    {
91
-        $taxonomies = EE_Register_CPTs::getTaxonomyDefinitions();
92
-        return $taxonomies->getCustomTaxonomyDefinitions();
93
-    }
94
-
95
-
96
-    /**
97
-     * @return CustomPostTypeDefinitions
98
-     * @throws InvalidArgumentException
99
-     * @throws InvalidDataTypeException
100
-     * @throws InvalidInterfaceException
101
-     */
102
-    public static function getCustomPostTypeDefinitions()
103
-    {
104
-        return LoaderFactory::getLoader()->getShared(
105
-            'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
106
-        );
107
-    }
108
-
109
-
110
-    /**
111
-     * @deprecated 4.9.62.p
112
-     * @return array
113
-     * @throws InvalidArgumentException
114
-     * @throws InvalidDataTypeException
115
-     * @throws InvalidInterfaceException
116
-     */
117
-    public static function get_CPTs()
118
-    {
119
-        $custom_post_types = EE_Register_CPTs::getCustomPostTypeDefinitions();
120
-        return $custom_post_types->getDefinitions();
121
-    }
122
-
123
-
124
-    /**
125
-     * @deprecated 4.9.62.p
126
-     * @return array
127
-     * @throws InvalidArgumentException
128
-     * @throws InvalidDataTypeException
129
-     * @throws InvalidInterfaceException
130
-     */
131
-    public static function get_private_CPTs()
132
-    {
133
-        $custom_post_types = EE_Register_CPTs::getCustomPostTypeDefinitions();
134
-        return $custom_post_types->getPrivateCustomPostTypes();
135
-    }
136
-
137
-
138
-    /**
139
-     * @deprecated 4.9.62.p
140
-     * @param string $post_type_slug              If a slug is included, then attempt to retrieve the model name for
141
-     *                                            the given cpt slug.  Otherwise if empty, then we'll return all cpt
142
-     *                                            model names for cpts registered in EE.
143
-     * @return array           Empty array if no matching model names for the given slug or an array of model
144
-     *                                            names indexed by post type slug.
145
-     * @throws InvalidArgumentException
146
-     * @throws InvalidDataTypeException
147
-     * @throws InvalidInterfaceException
148
-     */
149
-    public static function get_cpt_model_names($post_type_slug = '')
150
-    {
151
-        $custom_post_types = EE_Register_CPTs::getCustomPostTypeDefinitions();
152
-        return $custom_post_types->getCustomPostTypeModelNames($post_type_slug);
153
-    }
154
-
155
-
156
-    /**
157
-     * @deprecated 4.9.62.p
158
-     * @param string $post_type_slug If valid slug is provided, then will instantiate the model only for
159
-     *                               the cpt matching the given slug.  Otherwise all cpt models will be
160
-     *                               instantiated (if possible).
161
-     * @return EEM_CPT_Base[]        successful instantiation will return an array of successfully instantiated
162
-     *                               EEM models indexed by post slug.
163
-     * @throws InvalidArgumentException
164
-     * @throws InvalidDataTypeException
165
-     * @throws InvalidInterfaceException
166
-     */
167
-    public static function instantiate_cpt_models($post_type_slug = '')
168
-    {
169
-        $custom_post_types = EE_Register_CPTs::getCustomPostTypeDefinitions();
170
-        return $custom_post_types->getCustomPostTypeModels($post_type_slug);
171
-    }
172
-
173
-
174
-    /**
175
-     * @deprecated 4.9.62.p
176
-     * @param string $taxonomy_name , eg 'books'
177
-     * @param string $singular_name internationalized singular name
178
-     * @param string $plural_name   internationalized plural name
179
-     * @param array  $override_args like $args on http://codex.wordpress.org/Function_Reference/register_taxonomy
180
-     * @throws InvalidArgumentException
181
-     * @throws InvalidDataTypeException
182
-     * @throws InvalidInterfaceException
183
-     * @throws DomainException
184
-     */
185
-    public function register_taxonomy($taxonomy_name, $singular_name, $plural_name, $override_args = array())
186
-    {
187
-        /** @var \EventEspresso\core\domain\services\custom_post_types\registerCustomTaxonomies $taxonomies */
188
-        $taxonomies = LoaderFactory::getLoader()->getShared(
189
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'
190
-        );
191
-        $taxonomies->registerCustomTaxonomy(
192
-            $taxonomy_name,
193
-            $singular_name,
194
-            $plural_name,
195
-            $override_args
196
-        );
197
-    }
198
-
199
-
200
-    /**
201
-     * @deprecated 4.9.62.p
202
-     * @param string $post_type     the actual post type name
203
-     *                              (VERY IMPORTANT: this much match what the slug is for admin pages related to this
204
-     *                              cpt Also any models must use this slug as well)
205
-     * @param string $singular_name a pre-internationalized string for the singular name of the objects
206
-     * @param string $plural_name   a pre-internalized string for the plural name of the objects
207
-     * @param array  $override_args exactly like $args as described in
208
-     *                              http://codex.wordpress.org/Function_Reference/register_post_type The default values
209
-     *                              set in this function will be overridden by whatever you set in $override_args
210
-     * @param string $singular_slug
211
-     * @param string $plural_slug
212
-     * @return void , but registers the custom post type
213
-     * @throws InvalidArgumentException
214
-     * @throws InvalidDataTypeException
215
-     * @throws InvalidInterfaceException
216
-     * @throws DomainException
217
-     */
218
-    public function register_CPT(
219
-        $post_type,
220
-        $singular_name,
221
-        $plural_name,
222
-        $override_args = array(),
223
-        $singular_slug = '',
224
-        $plural_slug = ''
225
-    ) {
226
-        /** @var \EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes $register_custom_post_types */
227
-        $register_custom_post_types = LoaderFactory::getLoader()->getShared(
228
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'
229
-        );
230
-        $register_custom_post_types->registerCustomPostType(
231
-            $post_type,
232
-            $singular_name,
233
-            $plural_name,
234
-            $singular_slug,
235
-            $plural_slug,
236
-            $override_args
237
-        );
238
-    }
239
-
240
-
241
-    /**
242
-     * @return RegisterCustomTaxonomyTerms
243
-     * @throws InvalidArgumentException
244
-     * @throws InvalidDataTypeException
245
-     * @throws InvalidInterfaceException
246
-     */
247
-    public static function getRegisterCustomTaxonomyTerms()
248
-    {
249
-        return LoaderFactory::getLoader()->getShared(
250
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms'
251
-        );
252
-    }
253
-
254
-
255
-    /**
256
-     * @deprecated 4.9.62.p
257
-     * @throws InvalidArgumentException
258
-     * @throws InvalidDataTypeException
259
-     * @throws InvalidInterfaceException
260
-     */
261
-    public function set_must_use_event_types()
262
-    {
263
-        $register_custom_taxonomy_terms = EE_Register_CPTs::getRegisterCustomTaxonomyTerms();
264
-        $register_custom_taxonomy_terms->setMustUseEventTypes();
265
-    }
266
-
267
-
268
-    /**
269
-     * @deprecated 4.9.62.p
270
-     * @param string $taxonomy     The name of the taxonomy
271
-     * @param array  $term_details An array of term details indexed by slug and containing Name of term, and
272
-     *                             description as the elements in the array
273
-     * @return void
274
-     * @throws InvalidArgumentException
275
-     * @throws InvalidDataTypeException
276
-     * @throws InvalidInterfaceException
277
-     */
278
-    public function set_must_use_terms($taxonomy, $term_details)
279
-    {
280
-        $register_custom_taxonomy_terms = EE_Register_CPTs::getRegisterCustomTaxonomyTerms();
281
-        $register_custom_taxonomy_terms->setMustUseTerms($taxonomy, $term_details);
282
-    }
283
-
284
-
285
-    /**
286
-     * @deprecated 4.9.62.p
287
-     * @param string $taxonomy  The taxonomy we're using for the default term
288
-     * @param string $term_slug The slug of the term that will be the default.
289
-     * @param array  $cpt_slugs An array of custom post types we want the default assigned to
290
-     * @throws InvalidArgumentException
291
-     * @throws InvalidDataTypeException
292
-     * @throws InvalidInterfaceException
293
-     */
294
-    public function set_default_term($taxonomy, $term_slug, $cpt_slugs = array())
295
-    {
296
-        $register_custom_taxonomy_terms = EE_Register_CPTs::getRegisterCustomTaxonomyTerms();
297
-        $register_custom_taxonomy_terms->registerCustomTaxonomyTerm(
298
-            $taxonomy,
299
-            $term_slug,
300
-            $cpt_slugs
301
-        );
302
-    }
303
-
304
-
305
-    /**
306
-     * @deprecated 4.9.62.p
307
-     * @param  int     $post_id ID of CPT being saved
308
-     * @param  WP_Post $post    Post object
309
-     * @return void
310
-     * @throws InvalidArgumentException
311
-     * @throws InvalidDataTypeException
312
-     * @throws InvalidInterfaceException
313
-     */
314
-    public function save_default_term($post_id, $post)
315
-    {
316
-        $register_custom_taxonomy_terms = EE_Register_CPTs::getRegisterCustomTaxonomyTerms();
317
-        $register_custom_taxonomy_terms->saveDefaultTerm($post_id, $post);
318
-    }
22
+	/**
23
+	 * instantiated at init priority 5
24
+	 *
25
+	 * @deprecated 4.9.62.p
26
+	 */
27
+	public function __construct()
28
+	{
29
+		do_action('AHEE__EE_Register_CPTs__construct_end', $this);
30
+	}
31
+
32
+
33
+	/**
34
+	 * This will flush rewrite rules on demand.  This actually gets called around wp init priority level 100.
35
+	 *
36
+	 * @deprecated 4.9.62.p
37
+	 * @return void
38
+	 * @throws InvalidInterfaceException
39
+	 * @throws InvalidDataTypeException
40
+	 * @throws InvalidArgumentException
41
+	 */
42
+	public static function maybe_flush_rewrite_rules()
43
+	{
44
+		/** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */
45
+		$rewrite_rules = LoaderFactory::getLoader()->getShared(
46
+			'EventEspresso\core\domain\services\custom_post_types\RewriteRules'
47
+		);
48
+		$rewrite_rules->flushRewriteRules();
49
+	}
50
+
51
+
52
+	/**
53
+	 * @return CustomTaxonomyDefinitions
54
+	 * @throws InvalidArgumentException
55
+	 * @throws InvalidDataTypeException
56
+	 * @throws InvalidInterfaceException
57
+	 */
58
+	public static function getTaxonomyDefinitions()
59
+	{
60
+		return LoaderFactory::getLoader()->getShared(
61
+			'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions'
62
+		);
63
+	}
64
+
65
+
66
+	/**
67
+	 * @deprecated 4.9.62.p
68
+	 * @param string $description The description content.
69
+	 * @param string $taxonomy    The taxonomy name for the taxonomy being filtered.
70
+	 * @return string
71
+	 * @throws InvalidArgumentException
72
+	 * @throws InvalidDataTypeException
73
+	 * @throws InvalidInterfaceException
74
+	 */
75
+	public function ee_filter_ee_term_description_not_wp($description, $taxonomy)
76
+	{
77
+		$taxonomies = EE_Register_CPTs::getTaxonomyDefinitions();
78
+		return $taxonomies->filterCustomTermDescription($description, $taxonomy);
79
+	}
80
+
81
+
82
+	/**
83
+	 * @deprecated 4.9.62.p
84
+	 * @return array
85
+	 * @throws InvalidArgumentException
86
+	 * @throws InvalidDataTypeException
87
+	 * @throws InvalidInterfaceException
88
+	 */
89
+	public static function get_taxonomies()
90
+	{
91
+		$taxonomies = EE_Register_CPTs::getTaxonomyDefinitions();
92
+		return $taxonomies->getCustomTaxonomyDefinitions();
93
+	}
94
+
95
+
96
+	/**
97
+	 * @return CustomPostTypeDefinitions
98
+	 * @throws InvalidArgumentException
99
+	 * @throws InvalidDataTypeException
100
+	 * @throws InvalidInterfaceException
101
+	 */
102
+	public static function getCustomPostTypeDefinitions()
103
+	{
104
+		return LoaderFactory::getLoader()->getShared(
105
+			'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'
106
+		);
107
+	}
108
+
109
+
110
+	/**
111
+	 * @deprecated 4.9.62.p
112
+	 * @return array
113
+	 * @throws InvalidArgumentException
114
+	 * @throws InvalidDataTypeException
115
+	 * @throws InvalidInterfaceException
116
+	 */
117
+	public static function get_CPTs()
118
+	{
119
+		$custom_post_types = EE_Register_CPTs::getCustomPostTypeDefinitions();
120
+		return $custom_post_types->getDefinitions();
121
+	}
122
+
123
+
124
+	/**
125
+	 * @deprecated 4.9.62.p
126
+	 * @return array
127
+	 * @throws InvalidArgumentException
128
+	 * @throws InvalidDataTypeException
129
+	 * @throws InvalidInterfaceException
130
+	 */
131
+	public static function get_private_CPTs()
132
+	{
133
+		$custom_post_types = EE_Register_CPTs::getCustomPostTypeDefinitions();
134
+		return $custom_post_types->getPrivateCustomPostTypes();
135
+	}
136
+
137
+
138
+	/**
139
+	 * @deprecated 4.9.62.p
140
+	 * @param string $post_type_slug              If a slug is included, then attempt to retrieve the model name for
141
+	 *                                            the given cpt slug.  Otherwise if empty, then we'll return all cpt
142
+	 *                                            model names for cpts registered in EE.
143
+	 * @return array           Empty array if no matching model names for the given slug or an array of model
144
+	 *                                            names indexed by post type slug.
145
+	 * @throws InvalidArgumentException
146
+	 * @throws InvalidDataTypeException
147
+	 * @throws InvalidInterfaceException
148
+	 */
149
+	public static function get_cpt_model_names($post_type_slug = '')
150
+	{
151
+		$custom_post_types = EE_Register_CPTs::getCustomPostTypeDefinitions();
152
+		return $custom_post_types->getCustomPostTypeModelNames($post_type_slug);
153
+	}
154
+
155
+
156
+	/**
157
+	 * @deprecated 4.9.62.p
158
+	 * @param string $post_type_slug If valid slug is provided, then will instantiate the model only for
159
+	 *                               the cpt matching the given slug.  Otherwise all cpt models will be
160
+	 *                               instantiated (if possible).
161
+	 * @return EEM_CPT_Base[]        successful instantiation will return an array of successfully instantiated
162
+	 *                               EEM models indexed by post slug.
163
+	 * @throws InvalidArgumentException
164
+	 * @throws InvalidDataTypeException
165
+	 * @throws InvalidInterfaceException
166
+	 */
167
+	public static function instantiate_cpt_models($post_type_slug = '')
168
+	{
169
+		$custom_post_types = EE_Register_CPTs::getCustomPostTypeDefinitions();
170
+		return $custom_post_types->getCustomPostTypeModels($post_type_slug);
171
+	}
172
+
173
+
174
+	/**
175
+	 * @deprecated 4.9.62.p
176
+	 * @param string $taxonomy_name , eg 'books'
177
+	 * @param string $singular_name internationalized singular name
178
+	 * @param string $plural_name   internationalized plural name
179
+	 * @param array  $override_args like $args on http://codex.wordpress.org/Function_Reference/register_taxonomy
180
+	 * @throws InvalidArgumentException
181
+	 * @throws InvalidDataTypeException
182
+	 * @throws InvalidInterfaceException
183
+	 * @throws DomainException
184
+	 */
185
+	public function register_taxonomy($taxonomy_name, $singular_name, $plural_name, $override_args = array())
186
+	{
187
+		/** @var \EventEspresso\core\domain\services\custom_post_types\registerCustomTaxonomies $taxonomies */
188
+		$taxonomies = LoaderFactory::getLoader()->getShared(
189
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'
190
+		);
191
+		$taxonomies->registerCustomTaxonomy(
192
+			$taxonomy_name,
193
+			$singular_name,
194
+			$plural_name,
195
+			$override_args
196
+		);
197
+	}
198
+
199
+
200
+	/**
201
+	 * @deprecated 4.9.62.p
202
+	 * @param string $post_type     the actual post type name
203
+	 *                              (VERY IMPORTANT: this much match what the slug is for admin pages related to this
204
+	 *                              cpt Also any models must use this slug as well)
205
+	 * @param string $singular_name a pre-internationalized string for the singular name of the objects
206
+	 * @param string $plural_name   a pre-internalized string for the plural name of the objects
207
+	 * @param array  $override_args exactly like $args as described in
208
+	 *                              http://codex.wordpress.org/Function_Reference/register_post_type The default values
209
+	 *                              set in this function will be overridden by whatever you set in $override_args
210
+	 * @param string $singular_slug
211
+	 * @param string $plural_slug
212
+	 * @return void , but registers the custom post type
213
+	 * @throws InvalidArgumentException
214
+	 * @throws InvalidDataTypeException
215
+	 * @throws InvalidInterfaceException
216
+	 * @throws DomainException
217
+	 */
218
+	public function register_CPT(
219
+		$post_type,
220
+		$singular_name,
221
+		$plural_name,
222
+		$override_args = array(),
223
+		$singular_slug = '',
224
+		$plural_slug = ''
225
+	) {
226
+		/** @var \EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes $register_custom_post_types */
227
+		$register_custom_post_types = LoaderFactory::getLoader()->getShared(
228
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'
229
+		);
230
+		$register_custom_post_types->registerCustomPostType(
231
+			$post_type,
232
+			$singular_name,
233
+			$plural_name,
234
+			$singular_slug,
235
+			$plural_slug,
236
+			$override_args
237
+		);
238
+	}
239
+
240
+
241
+	/**
242
+	 * @return RegisterCustomTaxonomyTerms
243
+	 * @throws InvalidArgumentException
244
+	 * @throws InvalidDataTypeException
245
+	 * @throws InvalidInterfaceException
246
+	 */
247
+	public static function getRegisterCustomTaxonomyTerms()
248
+	{
249
+		return LoaderFactory::getLoader()->getShared(
250
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms'
251
+		);
252
+	}
253
+
254
+
255
+	/**
256
+	 * @deprecated 4.9.62.p
257
+	 * @throws InvalidArgumentException
258
+	 * @throws InvalidDataTypeException
259
+	 * @throws InvalidInterfaceException
260
+	 */
261
+	public function set_must_use_event_types()
262
+	{
263
+		$register_custom_taxonomy_terms = EE_Register_CPTs::getRegisterCustomTaxonomyTerms();
264
+		$register_custom_taxonomy_terms->setMustUseEventTypes();
265
+	}
266
+
267
+
268
+	/**
269
+	 * @deprecated 4.9.62.p
270
+	 * @param string $taxonomy     The name of the taxonomy
271
+	 * @param array  $term_details An array of term details indexed by slug and containing Name of term, and
272
+	 *                             description as the elements in the array
273
+	 * @return void
274
+	 * @throws InvalidArgumentException
275
+	 * @throws InvalidDataTypeException
276
+	 * @throws InvalidInterfaceException
277
+	 */
278
+	public function set_must_use_terms($taxonomy, $term_details)
279
+	{
280
+		$register_custom_taxonomy_terms = EE_Register_CPTs::getRegisterCustomTaxonomyTerms();
281
+		$register_custom_taxonomy_terms->setMustUseTerms($taxonomy, $term_details);
282
+	}
283
+
284
+
285
+	/**
286
+	 * @deprecated 4.9.62.p
287
+	 * @param string $taxonomy  The taxonomy we're using for the default term
288
+	 * @param string $term_slug The slug of the term that will be the default.
289
+	 * @param array  $cpt_slugs An array of custom post types we want the default assigned to
290
+	 * @throws InvalidArgumentException
291
+	 * @throws InvalidDataTypeException
292
+	 * @throws InvalidInterfaceException
293
+	 */
294
+	public function set_default_term($taxonomy, $term_slug, $cpt_slugs = array())
295
+	{
296
+		$register_custom_taxonomy_terms = EE_Register_CPTs::getRegisterCustomTaxonomyTerms();
297
+		$register_custom_taxonomy_terms->registerCustomTaxonomyTerm(
298
+			$taxonomy,
299
+			$term_slug,
300
+			$cpt_slugs
301
+		);
302
+	}
303
+
304
+
305
+	/**
306
+	 * @deprecated 4.9.62.p
307
+	 * @param  int     $post_id ID of CPT being saved
308
+	 * @param  WP_Post $post    Post object
309
+	 * @return void
310
+	 * @throws InvalidArgumentException
311
+	 * @throws InvalidDataTypeException
312
+	 * @throws InvalidInterfaceException
313
+	 */
314
+	public function save_default_term($post_id, $post)
315
+	{
316
+		$register_custom_taxonomy_terms = EE_Register_CPTs::getRegisterCustomTaxonomyTerms();
317
+		$register_custom_taxonomy_terms->saveDefaultTerm($post_id, $post);
318
+	}
319 319
 }
320 320
 
321 321
 /**
@@ -327,24 +327,24 @@  discard block
 block discarded – undo
327 327
 class EE_Default_Term
328 328
 {
329 329
 
330
-    // props holding the items
331
-    public $taxonomy = '';
330
+	// props holding the items
331
+	public $taxonomy = '';
332 332
 
333
-    public $cpt_slugs = array();
333
+	public $cpt_slugs = array();
334 334
 
335
-    public $term_slug = '';
335
+	public $term_slug = '';
336 336
 
337 337
 
338
-    /**
339
-     * @deprecated 4.9.62.p
340
-     * @param string $taxonomy  The taxonomy the default term belongs to
341
-     * @param string $term_slug The slug of the term that will be the default.
342
-     * @param array  $cpt_slugs The custom post type the default term gets saved with
343
-     */
344
-    public function __construct($taxonomy, $term_slug, $cpt_slugs = array())
345
-    {
346
-        $this->taxonomy = $taxonomy;
347
-        $this->cpt_slugs = (array) $cpt_slugs;
348
-        $this->term_slug = $term_slug;
349
-    }
338
+	/**
339
+	 * @deprecated 4.9.62.p
340
+	 * @param string $taxonomy  The taxonomy the default term belongs to
341
+	 * @param string $term_slug The slug of the term that will be the default.
342
+	 * @param array  $cpt_slugs The custom post type the default term gets saved with
343
+	 */
344
+	public function __construct($taxonomy, $term_slug, $cpt_slugs = array())
345
+	{
346
+		$this->taxonomy = $taxonomy;
347
+		$this->cpt_slugs = (array) $cpt_slugs;
348
+		$this->term_slug = $term_slug;
349
+	}
350 350
 }
Please login to merge, or discard this patch.
core/services/assets/I18nRegistry.php 2 patches
Indentation   +234 added lines, -234 removed lines patch added patch discarded remove patch
@@ -14,238 +14,238 @@
 block discarded – undo
14 14
  */
15 15
 class I18nRegistry
16 16
 {
17
-    /**
18
-     * @var DomainInterface
19
-     */
20
-    private $domain;
21
-
22
-    /**
23
-     * Will hold all registered i18n scripts.  Prevents script handles from being registered more than once.
24
-     *
25
-     * @var array
26
-     */
27
-    private $registered_i18n = array();
28
-
29
-
30
-    /**
31
-     * Used to hold queued translations for the chunks loading in a view.
32
-     *
33
-     * @var array
34
-     */
35
-    private $queued_handle_translations = array();
36
-
37
-    /**
38
-     * Used to track script handles queued for adding translation strings as inline data in the dom.
39
-     *
40
-     * @var array
41
-     */
42
-    private $queued_scripts = array();
43
-
44
-
45
-    /**
46
-     * Obtained from the generated json file from the all javascript using wp.i18n with a map of script handle names to
47
-     * translation strings.
48
-     *
49
-     * @var array
50
-     */
51
-    private $i18n_map;
52
-
53
-
54
-    /**
55
-     * I18nRegistry constructor.
56
-     *
57
-     * @param array() $i18n_map  An array of script handle names and the strings translated for those handles.  If not
58
-     *                            provided, the class will look for map in root of plugin with filename of
59
-     *                            'translation-map.json'.
60
-     * @param DomainInterface $domain
61
-     */
62
-    public function __construct(array $i18n_map = array(), DomainInterface $domain)
63
-    {
64
-        $this->domain = $domain;
65
-        $this->setI18nMap($i18n_map);
66
-        add_filter('print_scripts_array', array($this, 'queueI18n'));
67
-    }
68
-
69
-
70
-    /**
71
-     * Used to register a script that has i18n strings for its $handle
72
-     *
73
-     * @param string $handle The script handle reference.
74
-     * @param string $domain The i18n domain for the strings.
75
-     */
76
-    public function registerScriptI18n($handle, $domain = 'event_espresso')
77
-    {
78
-        if(! isset($this->registered_i18n[$handle])) {
79
-            $this->registered_i18n[ $handle ] = 1;
80
-            $this->queued_scripts[ $handle ] = $domain;
81
-        }
82
-    }
83
-
84
-
85
-
86
-    /**
87
-     * Callback on print_scripts_array to listen for scripts enqueued and handle setting up the localized data.
88
-     *
89
-     * @param array $handles Array of registered script handles.
90
-     * @return array
91
-     */
92
-    public function queueI18n(array $handles)
93
-    {
94
-        if (empty($this->queued_scripts) || empty($this->i18n_map)) {
95
-            return $handles;
96
-        }
97
-        foreach ($handles as $handle) {
98
-            $this->queueI18nTranslationsForHandle($handle);
99
-        }
100
-        if ($this->queued_handle_translations) {
101
-            foreach ($this->queued_handle_translations as $handle => $translations_for_domain) {
102
-                $this->registerInlineScript(
103
-                    $handle,
104
-                    $translations_for_domain['translations'],
105
-                    $translations_for_domain['domain']
106
-                );
107
-            }
108
-        }
109
-        return $handles;
110
-    }
111
-
112
-
113
-    /**
114
-     * Registers inline script with translations for given handle and domain.
115
-     *
116
-     * @param string $handle       Handle used to register javascript file containing translations.
117
-     * @param array  $translations Array of string translations.
118
-     * @param string $domain       Domain for translations.  If left empty then strings are registered with the default
119
-     *                             domain for the javascript.
120
-     */
121
-    protected function registerInlineScript($handle, array $translations, $domain)
122
-    {
123
-        $script = $domain ?
124
-            'eejs.i18n.setLocaleData( ' . wp_json_encode($translations) . ', "' . $domain . '" );' :
125
-            'eejs.i18n.setLocaleData( ' . wp_json_encode($translations) . ' );';
126
-        wp_add_inline_script($handle, $script, 'before');
127
-    }
128
-
129
-
130
-    /**
131
-     * Queues up the translation strings for the given handle.
132
-     *
133
-     * @param string $handle The script handle being queued up.
134
-     */
135
-    private function queueI18nTranslationsForHandle($handle)
136
-    {
137
-        if (isset($this->queued_scripts[$handle])) {
138
-            $domain = $this->queued_scripts[$handle];
139
-            $translations = $this->getJedLocaleDataForDomainAndChunk($handle, $domain);
140
-            if (count($translations) > 0) {
141
-                $this->queued_handle_translations[$handle] = array(
142
-                    'domain'       => $domain,
143
-                    'translations' => $translations,
144
-                );
145
-            }
146
-            unset($this->queued_scripts[$handle]);
147
-        }
148
-    }
149
-
150
-
151
-    /**
152
-     * Sets the internal i18n_map property.
153
-     * If $chunk_map is empty or not an array, will attempt to load a chunk map from a default named map.
154
-     *
155
-     * @param array $i18n_map  If provided, an array of translation strings indexed by script handle names they
156
-     *                         correspond to.
157
-     */
158
-    private function setI18nMap(array $i18n_map)
159
-    {
160
-        if (empty($i18n_map)) {
161
-            $i18n_map = file_exists($this->domain->pluginPath() . 'translation-map.json')
162
-                ? json_decode(
163
-                        file_get_contents($this->domain->pluginPath() . 'translation-map.json'),
164
-                        true
165
-                    )
166
-                : array();
167
-        }
168
-        $this->i18n_map = $i18n_map;
169
-    }
170
-
171
-
172
-    /**
173
-     * Get the jed locale data for a given $handle and domain
174
-     *
175
-     * @param string $handle The name for the script handle we want strings returned for.
176
-     * @param string $domain The i18n domain.
177
-     * @return array
178
-     */
179
-    protected function getJedLocaleDataForDomainAndChunk($handle, $domain)
180
-    {
181
-        $translations = $this->getJedLocaleData($domain);
182
-        // get index for adding back after extracting strings for this $chunk.
183
-        $index = $translations[''];
184
-        $translations = $this->getLocaleDataMatchingMap(
185
-            $this->getOriginalStringsForHandleFromMap($handle),
186
-            $translations
187
-        );
188
-        $translations[''] = $index;
189
-        return $translations;
190
-    }
191
-
192
-
193
-    /**
194
-     * Get locale data for given strings from given translations
195
-     *
196
-     * @param array $string_set   This is the subset of strings (msgIds) we want to extract from the translations array.
197
-     * @param array $translations Translation data to extra strings from.
198
-     * @return array
199
-     */
200
-    protected function getLocaleDataMatchingMap(array $string_set, array $translations)
201
-    {
202
-        if (empty($string_set)) {
203
-            return array();
204
-        }
205
-        // some strings with quotes in them will break on the array_flip, so making sure quotes in the string are
206
-        // slashed also filter falsey values.
207
-        $string_set = array_unique(array_filter(wp_slash($string_set)));
208
-        return array_intersect_key($translations, array_flip($string_set));
209
-    }
210
-
211
-
212
-    /**
213
-     * Get original strings to translate for the given chunk from the map
214
-     *
215
-     * @param string $handle The script handle name to get strings from the map for.
216
-     * @return array
217
-     */
218
-    protected function getOriginalStringsForHandleFromMap($handle)
219
-    {
220
-        return isset($this->i18n_map[$handle]) ? $this->i18n_map[$handle] : array();
221
-    }
222
-
223
-
224
-    /**
225
-     * Returns Jed-formatted localization data.
226
-     *
227
-     * @param  string $domain Translation domain.
228
-     * @return array
229
-     */
230
-    private function getJedLocaleData($domain)
231
-    {
232
-        $translations = get_translations_for_domain($domain);
233
-
234
-        $locale = array(
235
-            '' => array(
236
-                'domain' => $domain,
237
-                'lang'   => is_admin() ? get_user_locale() : get_locale(),
238
-            ),
239
-        );
240
-
241
-        if (! empty($translations->headers['Plural-Forms'])) {
242
-            $locale['']['plural_forms'] = $translations->headers['Plural-Forms'];
243
-        }
244
-
245
-        foreach ($translations->entries as $msgid => $entry) {
246
-            $locale[$msgid] = $entry->translations;
247
-        }
248
-
249
-        return $locale;
250
-    }
17
+	/**
18
+	 * @var DomainInterface
19
+	 */
20
+	private $domain;
21
+
22
+	/**
23
+	 * Will hold all registered i18n scripts.  Prevents script handles from being registered more than once.
24
+	 *
25
+	 * @var array
26
+	 */
27
+	private $registered_i18n = array();
28
+
29
+
30
+	/**
31
+	 * Used to hold queued translations for the chunks loading in a view.
32
+	 *
33
+	 * @var array
34
+	 */
35
+	private $queued_handle_translations = array();
36
+
37
+	/**
38
+	 * Used to track script handles queued for adding translation strings as inline data in the dom.
39
+	 *
40
+	 * @var array
41
+	 */
42
+	private $queued_scripts = array();
43
+
44
+
45
+	/**
46
+	 * Obtained from the generated json file from the all javascript using wp.i18n with a map of script handle names to
47
+	 * translation strings.
48
+	 *
49
+	 * @var array
50
+	 */
51
+	private $i18n_map;
52
+
53
+
54
+	/**
55
+	 * I18nRegistry constructor.
56
+	 *
57
+	 * @param array() $i18n_map  An array of script handle names and the strings translated for those handles.  If not
58
+	 *                            provided, the class will look for map in root of plugin with filename of
59
+	 *                            'translation-map.json'.
60
+	 * @param DomainInterface $domain
61
+	 */
62
+	public function __construct(array $i18n_map = array(), DomainInterface $domain)
63
+	{
64
+		$this->domain = $domain;
65
+		$this->setI18nMap($i18n_map);
66
+		add_filter('print_scripts_array', array($this, 'queueI18n'));
67
+	}
68
+
69
+
70
+	/**
71
+	 * Used to register a script that has i18n strings for its $handle
72
+	 *
73
+	 * @param string $handle The script handle reference.
74
+	 * @param string $domain The i18n domain for the strings.
75
+	 */
76
+	public function registerScriptI18n($handle, $domain = 'event_espresso')
77
+	{
78
+		if(! isset($this->registered_i18n[$handle])) {
79
+			$this->registered_i18n[ $handle ] = 1;
80
+			$this->queued_scripts[ $handle ] = $domain;
81
+		}
82
+	}
83
+
84
+
85
+
86
+	/**
87
+	 * Callback on print_scripts_array to listen for scripts enqueued and handle setting up the localized data.
88
+	 *
89
+	 * @param array $handles Array of registered script handles.
90
+	 * @return array
91
+	 */
92
+	public function queueI18n(array $handles)
93
+	{
94
+		if (empty($this->queued_scripts) || empty($this->i18n_map)) {
95
+			return $handles;
96
+		}
97
+		foreach ($handles as $handle) {
98
+			$this->queueI18nTranslationsForHandle($handle);
99
+		}
100
+		if ($this->queued_handle_translations) {
101
+			foreach ($this->queued_handle_translations as $handle => $translations_for_domain) {
102
+				$this->registerInlineScript(
103
+					$handle,
104
+					$translations_for_domain['translations'],
105
+					$translations_for_domain['domain']
106
+				);
107
+			}
108
+		}
109
+		return $handles;
110
+	}
111
+
112
+
113
+	/**
114
+	 * Registers inline script with translations for given handle and domain.
115
+	 *
116
+	 * @param string $handle       Handle used to register javascript file containing translations.
117
+	 * @param array  $translations Array of string translations.
118
+	 * @param string $domain       Domain for translations.  If left empty then strings are registered with the default
119
+	 *                             domain for the javascript.
120
+	 */
121
+	protected function registerInlineScript($handle, array $translations, $domain)
122
+	{
123
+		$script = $domain ?
124
+			'eejs.i18n.setLocaleData( ' . wp_json_encode($translations) . ', "' . $domain . '" );' :
125
+			'eejs.i18n.setLocaleData( ' . wp_json_encode($translations) . ' );';
126
+		wp_add_inline_script($handle, $script, 'before');
127
+	}
128
+
129
+
130
+	/**
131
+	 * Queues up the translation strings for the given handle.
132
+	 *
133
+	 * @param string $handle The script handle being queued up.
134
+	 */
135
+	private function queueI18nTranslationsForHandle($handle)
136
+	{
137
+		if (isset($this->queued_scripts[$handle])) {
138
+			$domain = $this->queued_scripts[$handle];
139
+			$translations = $this->getJedLocaleDataForDomainAndChunk($handle, $domain);
140
+			if (count($translations) > 0) {
141
+				$this->queued_handle_translations[$handle] = array(
142
+					'domain'       => $domain,
143
+					'translations' => $translations,
144
+				);
145
+			}
146
+			unset($this->queued_scripts[$handle]);
147
+		}
148
+	}
149
+
150
+
151
+	/**
152
+	 * Sets the internal i18n_map property.
153
+	 * If $chunk_map is empty or not an array, will attempt to load a chunk map from a default named map.
154
+	 *
155
+	 * @param array $i18n_map  If provided, an array of translation strings indexed by script handle names they
156
+	 *                         correspond to.
157
+	 */
158
+	private function setI18nMap(array $i18n_map)
159
+	{
160
+		if (empty($i18n_map)) {
161
+			$i18n_map = file_exists($this->domain->pluginPath() . 'translation-map.json')
162
+				? json_decode(
163
+						file_get_contents($this->domain->pluginPath() . 'translation-map.json'),
164
+						true
165
+					)
166
+				: array();
167
+		}
168
+		$this->i18n_map = $i18n_map;
169
+	}
170
+
171
+
172
+	/**
173
+	 * Get the jed locale data for a given $handle and domain
174
+	 *
175
+	 * @param string $handle The name for the script handle we want strings returned for.
176
+	 * @param string $domain The i18n domain.
177
+	 * @return array
178
+	 */
179
+	protected function getJedLocaleDataForDomainAndChunk($handle, $domain)
180
+	{
181
+		$translations = $this->getJedLocaleData($domain);
182
+		// get index for adding back after extracting strings for this $chunk.
183
+		$index = $translations[''];
184
+		$translations = $this->getLocaleDataMatchingMap(
185
+			$this->getOriginalStringsForHandleFromMap($handle),
186
+			$translations
187
+		);
188
+		$translations[''] = $index;
189
+		return $translations;
190
+	}
191
+
192
+
193
+	/**
194
+	 * Get locale data for given strings from given translations
195
+	 *
196
+	 * @param array $string_set   This is the subset of strings (msgIds) we want to extract from the translations array.
197
+	 * @param array $translations Translation data to extra strings from.
198
+	 * @return array
199
+	 */
200
+	protected function getLocaleDataMatchingMap(array $string_set, array $translations)
201
+	{
202
+		if (empty($string_set)) {
203
+			return array();
204
+		}
205
+		// some strings with quotes in them will break on the array_flip, so making sure quotes in the string are
206
+		// slashed also filter falsey values.
207
+		$string_set = array_unique(array_filter(wp_slash($string_set)));
208
+		return array_intersect_key($translations, array_flip($string_set));
209
+	}
210
+
211
+
212
+	/**
213
+	 * Get original strings to translate for the given chunk from the map
214
+	 *
215
+	 * @param string $handle The script handle name to get strings from the map for.
216
+	 * @return array
217
+	 */
218
+	protected function getOriginalStringsForHandleFromMap($handle)
219
+	{
220
+		return isset($this->i18n_map[$handle]) ? $this->i18n_map[$handle] : array();
221
+	}
222
+
223
+
224
+	/**
225
+	 * Returns Jed-formatted localization data.
226
+	 *
227
+	 * @param  string $domain Translation domain.
228
+	 * @return array
229
+	 */
230
+	private function getJedLocaleData($domain)
231
+	{
232
+		$translations = get_translations_for_domain($domain);
233
+
234
+		$locale = array(
235
+			'' => array(
236
+				'domain' => $domain,
237
+				'lang'   => is_admin() ? get_user_locale() : get_locale(),
238
+			),
239
+		);
240
+
241
+		if (! empty($translations->headers['Plural-Forms'])) {
242
+			$locale['']['plural_forms'] = $translations->headers['Plural-Forms'];
243
+		}
244
+
245
+		foreach ($translations->entries as $msgid => $entry) {
246
+			$locale[$msgid] = $entry->translations;
247
+		}
248
+
249
+		return $locale;
250
+	}
251 251
 }
252 252
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +7 added lines, -8 removed lines patch added patch discarded remove patch
@@ -75,9 +75,9 @@  discard block
 block discarded – undo
75 75
      */
76 76
     public function registerScriptI18n($handle, $domain = 'event_espresso')
77 77
     {
78
-        if(! isset($this->registered_i18n[$handle])) {
79
-            $this->registered_i18n[ $handle ] = 1;
80
-            $this->queued_scripts[ $handle ] = $domain;
78
+        if ( ! isset($this->registered_i18n[$handle])) {
79
+            $this->registered_i18n[$handle] = 1;
80
+            $this->queued_scripts[$handle] = $domain;
81 81
         }
82 82
     }
83 83
 
@@ -121,8 +121,7 @@  discard block
 block discarded – undo
121 121
     protected function registerInlineScript($handle, array $translations, $domain)
122 122
     {
123 123
         $script = $domain ?
124
-            'eejs.i18n.setLocaleData( ' . wp_json_encode($translations) . ', "' . $domain . '" );' :
125
-            'eejs.i18n.setLocaleData( ' . wp_json_encode($translations) . ' );';
124
+            'eejs.i18n.setLocaleData( '.wp_json_encode($translations).', "'.$domain.'" );' : 'eejs.i18n.setLocaleData( '.wp_json_encode($translations).' );';
126 125
         wp_add_inline_script($handle, $script, 'before');
127 126
     }
128 127
 
@@ -158,9 +157,9 @@  discard block
 block discarded – undo
158 157
     private function setI18nMap(array $i18n_map)
159 158
     {
160 159
         if (empty($i18n_map)) {
161
-            $i18n_map = file_exists($this->domain->pluginPath() . 'translation-map.json')
160
+            $i18n_map = file_exists($this->domain->pluginPath().'translation-map.json')
162 161
                 ? json_decode(
163
-                        file_get_contents($this->domain->pluginPath() . 'translation-map.json'),
162
+                        file_get_contents($this->domain->pluginPath().'translation-map.json'),
164 163
                         true
165 164
                     )
166 165
                 : array();
@@ -238,7 +237,7 @@  discard block
 block discarded – undo
238 237
             ),
239 238
         );
240 239
 
241
-        if (! empty($translations->headers['Plural-Forms'])) {
240
+        if ( ! empty($translations->headers['Plural-Forms'])) {
242 241
             $locale['']['plural_forms'] = $translations->headers['Plural-Forms'];
243 242
         }
244 243
 
Please login to merge, or discard this patch.
core/services/assets/AssetCollection.php 2 patches
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -21,86 +21,86 @@
 block discarded – undo
21 21
 {
22 22
 
23 23
 
24
-    /**
25
-     * AssetCollection constructor
26
-     *
27
-     * @throws InvalidInterfaceException
28
-     */
29
-    public function __construct()
30
-    {
31
-        parent::__construct('EventEspresso\core\domain\values\assets\Asset');
32
-    }
24
+	/**
25
+	 * AssetCollection constructor
26
+	 *
27
+	 * @throws InvalidInterfaceException
28
+	 */
29
+	public function __construct()
30
+	{
31
+		parent::__construct('EventEspresso\core\domain\values\assets\Asset');
32
+	}
33 33
 
34 34
 
35
-    /**
36
-     * @return StylesheetAsset[]
37
-     * @since 4.9.62.p
38
-     */
39
-    public function getStylesheetAssets()
40
-    {
41
-        return $this->getAssetsOfType(Asset::TYPE_CSS);
42
-    }
35
+	/**
36
+	 * @return StylesheetAsset[]
37
+	 * @since 4.9.62.p
38
+	 */
39
+	public function getStylesheetAssets()
40
+	{
41
+		return $this->getAssetsOfType(Asset::TYPE_CSS);
42
+	}
43 43
 
44 44
 
45
-    /**
46
-     * @return JavascriptAsset[]
47
-     * @since 4.9.62.p
48
-     */
49
-    public function getJavascriptAssets()
50
-    {
51
-        return $this->getAssetsOfType(Asset::TYPE_JS);
52
-    }
45
+	/**
46
+	 * @return JavascriptAsset[]
47
+	 * @since 4.9.62.p
48
+	 */
49
+	public function getJavascriptAssets()
50
+	{
51
+		return $this->getAssetsOfType(Asset::TYPE_JS);
52
+	}
53 53
 
54 54
 
55
-    /**
56
-     * @return ManifestFile[]
57
-     * @since 4.9.62.p
58
-     */
59
-    public function getManifestFiles()
60
-    {
61
-        return $this->getAssetsOfType(Asset::TYPE_MANIFEST);
62
-    }
55
+	/**
56
+	 * @return ManifestFile[]
57
+	 * @since 4.9.62.p
58
+	 */
59
+	public function getManifestFiles()
60
+	{
61
+		return $this->getAssetsOfType(Asset::TYPE_MANIFEST);
62
+	}
63 63
 
64 64
 
65
-    /**
66
-     * @param $type
67
-     * @return array
68
-     * @since 4.9.62.p
69
-     */
70
-    protected function getAssetsOfType($type)
71
-    {
72
-        $files = array();
73
-        $this->rewind();
74
-        while ($this->valid()) {
75
-            /** @var \EventEspresso\core\domain\values\assets\Asset $asset */
76
-            $asset = $this->current();
77
-            if ($asset->type() === $type) {
78
-                $files[ $asset->handle() ] = $asset;
79
-            }
80
-            $this->next();
81
-        }
82
-        $this->rewind();
83
-        return $files;
84
-    }
65
+	/**
66
+	 * @param $type
67
+	 * @return array
68
+	 * @since 4.9.62.p
69
+	 */
70
+	protected function getAssetsOfType($type)
71
+	{
72
+		$files = array();
73
+		$this->rewind();
74
+		while ($this->valid()) {
75
+			/** @var \EventEspresso\core\domain\values\assets\Asset $asset */
76
+			$asset = $this->current();
77
+			if ($asset->type() === $type) {
78
+				$files[ $asset->handle() ] = $asset;
79
+			}
80
+			$this->next();
81
+		}
82
+		$this->rewind();
83
+		return $files;
84
+	}
85 85
 
86 86
 
87
-    /**
88
-     * @return JavascriptAsset[]
89
-     * @since 4.9.62.p
90
-     */
91
-    public function getJavascriptAssetsWithData()
92
-    {
93
-        $files = array();
94
-        $this->rewind();
95
-        while ($this->valid()) {
96
-            /** @var \EventEspresso\core\domain\values\assets\JavascriptAsset $asset */
97
-            $asset = $this->current();
98
-            if ($asset->type() === Asset::TYPE_JS && $asset->hasInlineData()) {
99
-                $files[ $asset->handle() ] = $asset;
100
-            }
101
-            $this->next();
102
-        }
103
-        $this->rewind();
104
-        return $files;
105
-    }
87
+	/**
88
+	 * @return JavascriptAsset[]
89
+	 * @since 4.9.62.p
90
+	 */
91
+	public function getJavascriptAssetsWithData()
92
+	{
93
+		$files = array();
94
+		$this->rewind();
95
+		while ($this->valid()) {
96
+			/** @var \EventEspresso\core\domain\values\assets\JavascriptAsset $asset */
97
+			$asset = $this->current();
98
+			if ($asset->type() === Asset::TYPE_JS && $asset->hasInlineData()) {
99
+				$files[ $asset->handle() ] = $asset;
100
+			}
101
+			$this->next();
102
+		}
103
+		$this->rewind();
104
+		return $files;
105
+	}
106 106
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
             /** @var \EventEspresso\core\domain\values\assets\Asset $asset */
76 76
             $asset = $this->current();
77 77
             if ($asset->type() === $type) {
78
-                $files[ $asset->handle() ] = $asset;
78
+                $files[$asset->handle()] = $asset;
79 79
             }
80 80
             $this->next();
81 81
         }
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
             /** @var \EventEspresso\core\domain\values\assets\JavascriptAsset $asset */
97 97
             $asset = $this->current();
98 98
             if ($asset->type() === Asset::TYPE_JS && $asset->hasInlineData()) {
99
-                $files[ $asset->handle() ] = $asset;
99
+                $files[$asset->handle()] = $asset;
100 100
             }
101 101
             $this->next();
102 102
         }
Please login to merge, or discard this patch.
core/services/assets/Registry.php 2 patches
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
                 $script->version(),
147 147
                 $script->loadInFooter()
148 148
             );
149
-            if (! $registered && defined('EE_DEBUG') && EE_DEBUG) {
149
+            if ( ! $registered && defined('EE_DEBUG') && EE_DEBUG) {
150 150
                 throw new AssetRegistrationException($script->handle());
151 151
             }
152 152
             $script->setRegistered($registered);
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
         $this->removeAlreadyRegisteredDataForScriptHandles();
207 207
         wp_add_inline_script(
208 208
             'eejs-core',
209
-            'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)),
209
+            'var eejsdata='.wp_json_encode(array('data' => $this->jsdata)),
210 210
             'before'
211 211
         );
212 212
         $scripts = $this->assets->getJavascriptAssetsWithData();
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
     public function addData($key, $value)
237 237
     {
238 238
         if ($this->verifyDataNotExisting($key)) {
239
-            $this->jsdata[ $key ] = $value;
239
+            $this->jsdata[$key] = $value;
240 240
         }
241 241
     }
242 242
 
@@ -257,8 +257,8 @@  discard block
 block discarded – undo
257 257
      */
258 258
     public function pushData($key, $value)
259 259
     {
260
-        if (isset($this->jsdata[ $key ])
261
-            && ! is_array($this->jsdata[ $key ])
260
+        if (isset($this->jsdata[$key])
261
+            && ! is_array($this->jsdata[$key])
262 262
         ) {
263 263
             throw new InvalidArgumentException(
264 264
                 sprintf(
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
                 )
273 273
             );
274 274
         }
275
-        $this->jsdata[ $key ][] = $value;
275
+        $this->jsdata[$key][] = $value;
276 276
     }
277 277
 
278 278
 
@@ -286,11 +286,11 @@  discard block
 block discarded – undo
286 286
      */
287 287
     public function addTemplate($template_reference, $template_content)
288 288
     {
289
-        if (! isset($this->jsdata['templates'])) {
289
+        if ( ! isset($this->jsdata['templates'])) {
290 290
             $this->jsdata['templates'] = array();
291 291
         }
292 292
         //no overrides allowed.
293
-        if (isset($this->jsdata['templates'][ $template_reference ])) {
293
+        if (isset($this->jsdata['templates'][$template_reference])) {
294 294
             throw new InvalidArgumentException(
295 295
                 sprintf(
296 296
                     __(
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
                 )
302 302
             );
303 303
         }
304
-        $this->jsdata['templates'][ $template_reference ] = $template_content;
304
+        $this->jsdata['templates'][$template_reference] = $template_content;
305 305
     }
306 306
 
307 307
 
@@ -313,8 +313,8 @@  discard block
 block discarded – undo
313 313
      */
314 314
     public function getTemplate($template_reference)
315 315
     {
316
-        return isset($this->jsdata['templates'][ $template_reference ])
317
-            ? $this->jsdata['templates'][ $template_reference ]
316
+        return isset($this->jsdata['templates'][$template_reference])
317
+            ? $this->jsdata['templates'][$template_reference]
318 318
             : '';
319 319
     }
320 320
 
@@ -327,8 +327,8 @@  discard block
 block discarded – undo
327 327
      */
328 328
     public function getData($key)
329 329
     {
330
-        return isset($this->jsdata[ $key ])
331
-            ? $this->jsdata[ $key ]
330
+        return isset($this->jsdata[$key])
331
+            ? $this->jsdata[$key]
332 332
             : false;
333 333
     }
334 334
 
@@ -343,8 +343,8 @@  discard block
 block discarded – undo
343 343
      */
344 344
     protected function verifyDataNotExisting($key)
345 345
     {
346
-        if (isset($this->jsdata[ $key ])) {
347
-            if (is_array($this->jsdata[ $key ])) {
346
+        if (isset($this->jsdata[$key])) {
347
+            if (is_array($this->jsdata[$key])) {
348 348
                 throw new InvalidArgumentException(
349 349
                     sprintf(
350 350
                         __(
@@ -387,11 +387,11 @@  discard block
 block discarded – undo
387 387
     public function getAssetUrl($namespace, $chunk_name, $asset_type)
388 388
     {
389 389
         $url = isset(
390
-            $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ],
391
-            $this->manifest_data[ $namespace ]['url_base']
390
+            $this->manifest_data[$namespace][$chunk_name.'.'.$asset_type],
391
+            $this->manifest_data[$namespace]['url_base']
392 392
         )
393
-            ? $this->manifest_data[ $namespace ]['url_base']
394
-              . $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ]
393
+            ? $this->manifest_data[$namespace]['url_base']
394
+              . $this->manifest_data[$namespace][$chunk_name.'.'.$asset_type]
395 395
             : $chunk_name;
396 396
         return apply_filters(
397 397
             'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl',
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
             $this->registerManifestFile(
442 442
                 $manifest_file->assetNamespace(),
443 443
                 $manifest_file->urlBase(),
444
-                $manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST
444
+                $manifest_file->filepath().Registry::FILE_NAME_BUILD_MANIFEST
445 445
             );
446 446
         }
447 447
     }
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
      */
460 460
     public function registerManifestFile($namespace, $url_base, $manifest_file)
461 461
     {
462
-        if (isset($this->manifest_data[ $namespace ])) {
462
+        if (isset($this->manifest_data[$namespace])) {
463 463
             throw new InvalidArgumentException(
464 464
                 sprintf(
465 465
                     esc_html__(
@@ -490,9 +490,9 @@  discard block
 block discarded – undo
490 490
             }
491 491
             return;
492 492
         }
493
-        $this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file);
494
-        if (! isset($this->manifest_data[ $namespace ]['url_base'])) {
495
-            $this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base);
493
+        $this->manifest_data[$namespace] = $this->decodeManifestFile($manifest_file);
494
+        if ( ! isset($this->manifest_data[$namespace]['url_base'])) {
495
+            $this->manifest_data[$namespace]['url_base'] = trailingslashit($url_base);
496 496
         }
497 497
     }
498 498
 
@@ -507,7 +507,7 @@  discard block
 block discarded – undo
507 507
      */
508 508
     private function decodeManifestFile($manifest_file)
509 509
     {
510
-        if (! file_exists($manifest_file)) {
510
+        if ( ! file_exists($manifest_file)) {
511 511
             throw new InvalidFilePathException($manifest_file);
512 512
         }
513 513
         return json_decode(file_get_contents($manifest_file), true);
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
      */
522 522
     private function addRegisteredScriptHandlesWithData($script_handle)
523 523
     {
524
-        $this->script_handles_with_data[ $script_handle ] = $script_handle;
524
+        $this->script_handles_with_data[$script_handle] = $script_handle;
525 525
     }
526 526
 
527 527
 
@@ -547,23 +547,23 @@  discard block
 block discarded – undo
547 547
      */
548 548
     private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
549 549
     {
550
-        if (isset($this->script_handles_with_data[ $script_handle ])) {
550
+        if (isset($this->script_handles_with_data[$script_handle])) {
551 551
             global $wp_scripts;
552 552
             $unset_handle = false;
553 553
             if ($wp_scripts->get_data($script_handle, 'data')) {
554
-                unset($wp_scripts->registered[ $script_handle ]->extra['data']);
554
+                unset($wp_scripts->registered[$script_handle]->extra['data']);
555 555
                 $unset_handle = true;
556 556
             }
557 557
             //deal with inline_scripts
558 558
             if ($wp_scripts->get_data($script_handle, 'before')) {
559
-                unset($wp_scripts->registered[ $script_handle ]->extra['before']);
559
+                unset($wp_scripts->registered[$script_handle]->extra['before']);
560 560
                 $unset_handle = true;
561 561
             }
562 562
             if ($wp_scripts->get_data($script_handle, 'after')) {
563
-                unset($wp_scripts->registered[ $script_handle ]->extra['after']);
563
+                unset($wp_scripts->registered[$script_handle]->extra['after']);
564 564
             }
565 565
             if ($unset_handle) {
566
-                unset($this->script_handles_with_data[ $script_handle ]);
566
+                unset($this->script_handles_with_data[$script_handle]);
567 567
             }
568 568
         }
569 569
     }
Please login to merge, or discard this patch.
Indentation   +550 added lines, -550 removed lines patch added patch discarded remove patch
@@ -23,561 +23,561 @@
 block discarded – undo
23 23
 class Registry
24 24
 {
25 25
 
26
-    const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json';
27
-
28
-    /**
29
-     * @var AssetCollection $assets
30
-     */
31
-    protected $assets;
32
-
33
-    /**
34
-     * @var I18nRegistry
35
-     */
36
-    private $i18n_registry;
37
-
38
-    /**
39
-     * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
40
-     *
41
-     * @var array
42
-     */
43
-    protected $jsdata = array();
44
-
45
-    /**
46
-     * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
47
-     * page source.
48
-     *
49
-     * @var array
50
-     */
51
-    private $script_handles_with_data = array();
52
-
53
-
54
-    /**
55
-     * Holds the manifest data obtained from registered manifest files.
56
-     * Manifests are maps of asset chunk name to actual built asset file names.
57
-     * Shape of this array is:
58
-     * array(
59
-     *  'some_namespace_slug' => array(
60
-     *      'some_chunk_name' => array(
61
-     *          'js' => 'filename.js'
62
-     *          'css' => 'filename.js'
63
-     *      ),
64
-     *      'url_base' => 'https://baseurl.com/to/assets
65
-     *  )
66
-     * )
67
-     *
68
-     * @var array
69
-     */
70
-    private $manifest_data = array();
71
-
72
-
73
-    /**
74
-     * Registry constructor.
75
-     * Hooking into WP actions for script registry.
76
-     *
77
-     * @param AssetCollection $assets
78
-     * @param I18nRegistry    $i18n_registry
79
-     */
80
-    public function __construct(AssetCollection $assets, I18nRegistry $i18n_registry)
81
-    {
82
-        $this->assets = $assets;
83
-        $this->i18n_registry = $i18n_registry;
84
-        add_action('wp_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
85
-        add_action('admin_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
86
-        add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
87
-        add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
88
-        add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 4);
89
-        add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 4);
90
-        add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
91
-        add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
92
-    }
93
-
94
-
95
-    /**
96
-     * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n
97
-     * translation handling.
98
-     *
99
-     * @return I18nRegistry
100
-     */
101
-    public function getI18nRegistry()
102
-    {
103
-        return $this->i18n_registry;
104
-    }
105
-
106
-
107
-    /**
108
-     * Callback for the wp_enqueue_scripts actions used to register assets.
109
-     *
110
-     * @since 4.9.62.p
111
-     * @throws Exception
112
-     */
113
-    public function registerScriptsAndStyles()
114
-    {
115
-        try {
116
-            $this->registerScripts($this->assets->getJavascriptAssets());
117
-            $this->registerStyles($this->assets->getStylesheetAssets());
118
-        } catch (Exception $exception) {
119
-            new ExceptionStackTraceDisplay($exception);
120
-        }
121
-    }
122
-
123
-
124
-    /**
125
-     * Registers JS assets with WP core
126
-     *
127
-     * @since 4.9.62.p
128
-     * @param JavascriptAsset[] $scripts
129
-     * @throws AssetRegistrationException
130
-     * @throws InvalidDataTypeException
131
-     */
132
-    public function registerScripts(array $scripts)
133
-    {
134
-        foreach ($scripts as $script) {
135
-            // skip to next script if this has already been done
136
-            if ($script->isRegistered()) {
137
-                continue;
138
-            }
139
-            do_action(
140
-                'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
141
-                $script
142
-            );
143
-            $registered = wp_register_script(
144
-                $script->handle(),
145
-                $script->source(),
146
-                $script->dependencies(),
147
-                $script->version(),
148
-                $script->loadInFooter()
149
-            );
150
-            if (! $registered && defined('EE_DEBUG') && EE_DEBUG) {
151
-                throw new AssetRegistrationException($script->handle());
152
-            }
153
-            $script->setRegistered($registered);
154
-            if ($script->requiresTranslation()) {
155
-                $this->registerTranslation($script->handle());
156
-            }
157
-            do_action(
158
-                'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script',
159
-                $script
160
-            );
161
-        }
162
-    }
163
-
164
-
165
-    /**
166
-     * Registers CSS assets with WP core
167
-     *
168
-     * @since 4.9.62.p
169
-     * @param StylesheetAsset[] $styles
170
-     * @throws InvalidDataTypeException
171
-     */
172
-    public function registerStyles(array $styles)
173
-    {
174
-        foreach ($styles as $style) {
175
-            // skip to next style if this has already been done
176
-            if ($style->isRegistered()) {
177
-                continue;
178
-            }
179
-            do_action(
180
-                'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style',
181
-                $style
182
-            );
183
-            wp_enqueue_style(
184
-                $style->handle(),
185
-                $style->source(),
186
-                $style->dependencies(),
187
-                $style->version(),
188
-                $style->media()
189
-            );
190
-            $style->setRegistered();
191
-            do_action(
192
-                'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style',
193
-                $style
194
-            );
195
-        }
196
-    }
197
-
198
-
199
-    /**
200
-     * Call back for the script print in frontend and backend.
201
-     * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
202
-     *
203
-     * @since 4.9.31.rc.015
204
-     */
205
-    public function enqueueData()
206
-    {
207
-        $this->removeAlreadyRegisteredDataForScriptHandles();
208
-        wp_add_inline_script(
209
-            'eejs-core',
210
-            'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)),
211
-            'before'
212
-        );
213
-        $scripts = $this->assets->getJavascriptAssetsWithData();
214
-        foreach ($scripts as $script) {
215
-            $this->addRegisteredScriptHandlesWithData($script->handle());
216
-            if ($script->hasInlineDataCallback()) {
217
-                $localize = $script->inlineDataCallback();
218
-                $localize();
219
-            }
220
-        }
221
-    }
222
-
223
-
224
-    /**
225
-     * Used to add data to eejs.data object.
226
-     * Note:  Overriding existing data is not allowed.
227
-     * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
228
-     * If the data you add is something like this:
229
-     *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
230
-     * It will be exposed in the page source as:
231
-     *  eejs.data.my_plugin_data.foo == gar
232
-     *
233
-     * @param string       $key   Key used to access your data
234
-     * @param string|array $value Value to attach to key
235
-     * @throws InvalidArgumentException
236
-     */
237
-    public function addData($key, $value)
238
-    {
239
-        if ($this->verifyDataNotExisting($key)) {
240
-            $this->jsdata[ $key ] = $value;
241
-        }
242
-    }
243
-
244
-
245
-    /**
246
-     * Similar to addData except this allows for users to push values to an existing key where the values on key are
247
-     * elements in an array.
248
-     * When you use this method, the value you include will be appended to the end of an array on $key.
249
-     * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript
250
-     * object like this, eejs.data.test = [ my_data,
251
-     * ]
252
-     * If there has already been a scalar value attached to the data object given key, then
253
-     * this will throw an exception.
254
-     *
255
-     * @param string       $key   Key to attach data to.
256
-     * @param string|array $value Value being registered.
257
-     * @throws InvalidArgumentException
258
-     */
259
-    public function pushData($key, $value)
260
-    {
261
-        if (isset($this->jsdata[ $key ])
262
-            && ! is_array($this->jsdata[ $key ])
263
-        ) {
264
-            throw new InvalidArgumentException(
265
-                sprintf(
266
-                    __(
267
-                        'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
26
+	const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json';
27
+
28
+	/**
29
+	 * @var AssetCollection $assets
30
+	 */
31
+	protected $assets;
32
+
33
+	/**
34
+	 * @var I18nRegistry
35
+	 */
36
+	private $i18n_registry;
37
+
38
+	/**
39
+	 * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
40
+	 *
41
+	 * @var array
42
+	 */
43
+	protected $jsdata = array();
44
+
45
+	/**
46
+	 * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
47
+	 * page source.
48
+	 *
49
+	 * @var array
50
+	 */
51
+	private $script_handles_with_data = array();
52
+
53
+
54
+	/**
55
+	 * Holds the manifest data obtained from registered manifest files.
56
+	 * Manifests are maps of asset chunk name to actual built asset file names.
57
+	 * Shape of this array is:
58
+	 * array(
59
+	 *  'some_namespace_slug' => array(
60
+	 *      'some_chunk_name' => array(
61
+	 *          'js' => 'filename.js'
62
+	 *          'css' => 'filename.js'
63
+	 *      ),
64
+	 *      'url_base' => 'https://baseurl.com/to/assets
65
+	 *  )
66
+	 * )
67
+	 *
68
+	 * @var array
69
+	 */
70
+	private $manifest_data = array();
71
+
72
+
73
+	/**
74
+	 * Registry constructor.
75
+	 * Hooking into WP actions for script registry.
76
+	 *
77
+	 * @param AssetCollection $assets
78
+	 * @param I18nRegistry    $i18n_registry
79
+	 */
80
+	public function __construct(AssetCollection $assets, I18nRegistry $i18n_registry)
81
+	{
82
+		$this->assets = $assets;
83
+		$this->i18n_registry = $i18n_registry;
84
+		add_action('wp_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
85
+		add_action('admin_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
86
+		add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
87
+		add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
88
+		add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 4);
89
+		add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 4);
90
+		add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
91
+		add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
92
+	}
93
+
94
+
95
+	/**
96
+	 * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n
97
+	 * translation handling.
98
+	 *
99
+	 * @return I18nRegistry
100
+	 */
101
+	public function getI18nRegistry()
102
+	{
103
+		return $this->i18n_registry;
104
+	}
105
+
106
+
107
+	/**
108
+	 * Callback for the wp_enqueue_scripts actions used to register assets.
109
+	 *
110
+	 * @since 4.9.62.p
111
+	 * @throws Exception
112
+	 */
113
+	public function registerScriptsAndStyles()
114
+	{
115
+		try {
116
+			$this->registerScripts($this->assets->getJavascriptAssets());
117
+			$this->registerStyles($this->assets->getStylesheetAssets());
118
+		} catch (Exception $exception) {
119
+			new ExceptionStackTraceDisplay($exception);
120
+		}
121
+	}
122
+
123
+
124
+	/**
125
+	 * Registers JS assets with WP core
126
+	 *
127
+	 * @since 4.9.62.p
128
+	 * @param JavascriptAsset[] $scripts
129
+	 * @throws AssetRegistrationException
130
+	 * @throws InvalidDataTypeException
131
+	 */
132
+	public function registerScripts(array $scripts)
133
+	{
134
+		foreach ($scripts as $script) {
135
+			// skip to next script if this has already been done
136
+			if ($script->isRegistered()) {
137
+				continue;
138
+			}
139
+			do_action(
140
+				'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
141
+				$script
142
+			);
143
+			$registered = wp_register_script(
144
+				$script->handle(),
145
+				$script->source(),
146
+				$script->dependencies(),
147
+				$script->version(),
148
+				$script->loadInFooter()
149
+			);
150
+			if (! $registered && defined('EE_DEBUG') && EE_DEBUG) {
151
+				throw new AssetRegistrationException($script->handle());
152
+			}
153
+			$script->setRegistered($registered);
154
+			if ($script->requiresTranslation()) {
155
+				$this->registerTranslation($script->handle());
156
+			}
157
+			do_action(
158
+				'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script',
159
+				$script
160
+			);
161
+		}
162
+	}
163
+
164
+
165
+	/**
166
+	 * Registers CSS assets with WP core
167
+	 *
168
+	 * @since 4.9.62.p
169
+	 * @param StylesheetAsset[] $styles
170
+	 * @throws InvalidDataTypeException
171
+	 */
172
+	public function registerStyles(array $styles)
173
+	{
174
+		foreach ($styles as $style) {
175
+			// skip to next style if this has already been done
176
+			if ($style->isRegistered()) {
177
+				continue;
178
+			}
179
+			do_action(
180
+				'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style',
181
+				$style
182
+			);
183
+			wp_enqueue_style(
184
+				$style->handle(),
185
+				$style->source(),
186
+				$style->dependencies(),
187
+				$style->version(),
188
+				$style->media()
189
+			);
190
+			$style->setRegistered();
191
+			do_action(
192
+				'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style',
193
+				$style
194
+			);
195
+		}
196
+	}
197
+
198
+
199
+	/**
200
+	 * Call back for the script print in frontend and backend.
201
+	 * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
202
+	 *
203
+	 * @since 4.9.31.rc.015
204
+	 */
205
+	public function enqueueData()
206
+	{
207
+		$this->removeAlreadyRegisteredDataForScriptHandles();
208
+		wp_add_inline_script(
209
+			'eejs-core',
210
+			'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)),
211
+			'before'
212
+		);
213
+		$scripts = $this->assets->getJavascriptAssetsWithData();
214
+		foreach ($scripts as $script) {
215
+			$this->addRegisteredScriptHandlesWithData($script->handle());
216
+			if ($script->hasInlineDataCallback()) {
217
+				$localize = $script->inlineDataCallback();
218
+				$localize();
219
+			}
220
+		}
221
+	}
222
+
223
+
224
+	/**
225
+	 * Used to add data to eejs.data object.
226
+	 * Note:  Overriding existing data is not allowed.
227
+	 * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
228
+	 * If the data you add is something like this:
229
+	 *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
230
+	 * It will be exposed in the page source as:
231
+	 *  eejs.data.my_plugin_data.foo == gar
232
+	 *
233
+	 * @param string       $key   Key used to access your data
234
+	 * @param string|array $value Value to attach to key
235
+	 * @throws InvalidArgumentException
236
+	 */
237
+	public function addData($key, $value)
238
+	{
239
+		if ($this->verifyDataNotExisting($key)) {
240
+			$this->jsdata[ $key ] = $value;
241
+		}
242
+	}
243
+
244
+
245
+	/**
246
+	 * Similar to addData except this allows for users to push values to an existing key where the values on key are
247
+	 * elements in an array.
248
+	 * When you use this method, the value you include will be appended to the end of an array on $key.
249
+	 * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript
250
+	 * object like this, eejs.data.test = [ my_data,
251
+	 * ]
252
+	 * If there has already been a scalar value attached to the data object given key, then
253
+	 * this will throw an exception.
254
+	 *
255
+	 * @param string       $key   Key to attach data to.
256
+	 * @param string|array $value Value being registered.
257
+	 * @throws InvalidArgumentException
258
+	 */
259
+	public function pushData($key, $value)
260
+	{
261
+		if (isset($this->jsdata[ $key ])
262
+			&& ! is_array($this->jsdata[ $key ])
263
+		) {
264
+			throw new InvalidArgumentException(
265
+				sprintf(
266
+					__(
267
+						'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
268 268
                          push values to this data element when it is an array.',
269
-                        'event_espresso'
270
-                    ),
271
-                    $key,
272
-                    __METHOD__
273
-                )
274
-            );
275
-        }
276
-        $this->jsdata[ $key ][] = $value;
277
-    }
278
-
279
-
280
-    /**
281
-     * Used to set content used by javascript for a template.
282
-     * Note: Overrides of existing registered templates are not allowed.
283
-     *
284
-     * @param string $template_reference
285
-     * @param string $template_content
286
-     * @throws InvalidArgumentException
287
-     */
288
-    public function addTemplate($template_reference, $template_content)
289
-    {
290
-        if (! isset($this->jsdata['templates'])) {
291
-            $this->jsdata['templates'] = array();
292
-        }
293
-        //no overrides allowed.
294
-        if (isset($this->jsdata['templates'][ $template_reference ])) {
295
-            throw new InvalidArgumentException(
296
-                sprintf(
297
-                    __(
298
-                        'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
299
-                        'event_espresso'
300
-                    ),
301
-                    $template_reference
302
-                )
303
-            );
304
-        }
305
-        $this->jsdata['templates'][ $template_reference ] = $template_content;
306
-    }
307
-
308
-
309
-    /**
310
-     * Retrieve the template content already registered for the given reference.
311
-     *
312
-     * @param string $template_reference
313
-     * @return string
314
-     */
315
-    public function getTemplate($template_reference)
316
-    {
317
-        return isset($this->jsdata['templates'][ $template_reference ])
318
-            ? $this->jsdata['templates'][ $template_reference ]
319
-            : '';
320
-    }
321
-
322
-
323
-    /**
324
-     * Retrieve registered data.
325
-     *
326
-     * @param string $key Name of key to attach data to.
327
-     * @return mixed                If there is no for the given key, then false is returned.
328
-     */
329
-    public function getData($key)
330
-    {
331
-        return isset($this->jsdata[ $key ])
332
-            ? $this->jsdata[ $key ]
333
-            : false;
334
-    }
335
-
336
-
337
-    /**
338
-     * Verifies whether the given data exists already on the jsdata array.
339
-     * Overriding data is not allowed.
340
-     *
341
-     * @param string $key Index for data.
342
-     * @return bool        If valid then return true.
343
-     * @throws InvalidArgumentException if data already exists.
344
-     */
345
-    protected function verifyDataNotExisting($key)
346
-    {
347
-        if (isset($this->jsdata[ $key ])) {
348
-            if (is_array($this->jsdata[ $key ])) {
349
-                throw new InvalidArgumentException(
350
-                    sprintf(
351
-                        __(
352
-                            'The value for %1$s already exists in the Registry::eejs object.
269
+						'event_espresso'
270
+					),
271
+					$key,
272
+					__METHOD__
273
+				)
274
+			);
275
+		}
276
+		$this->jsdata[ $key ][] = $value;
277
+	}
278
+
279
+
280
+	/**
281
+	 * Used to set content used by javascript for a template.
282
+	 * Note: Overrides of existing registered templates are not allowed.
283
+	 *
284
+	 * @param string $template_reference
285
+	 * @param string $template_content
286
+	 * @throws InvalidArgumentException
287
+	 */
288
+	public function addTemplate($template_reference, $template_content)
289
+	{
290
+		if (! isset($this->jsdata['templates'])) {
291
+			$this->jsdata['templates'] = array();
292
+		}
293
+		//no overrides allowed.
294
+		if (isset($this->jsdata['templates'][ $template_reference ])) {
295
+			throw new InvalidArgumentException(
296
+				sprintf(
297
+					__(
298
+						'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
299
+						'event_espresso'
300
+					),
301
+					$template_reference
302
+				)
303
+			);
304
+		}
305
+		$this->jsdata['templates'][ $template_reference ] = $template_content;
306
+	}
307
+
308
+
309
+	/**
310
+	 * Retrieve the template content already registered for the given reference.
311
+	 *
312
+	 * @param string $template_reference
313
+	 * @return string
314
+	 */
315
+	public function getTemplate($template_reference)
316
+	{
317
+		return isset($this->jsdata['templates'][ $template_reference ])
318
+			? $this->jsdata['templates'][ $template_reference ]
319
+			: '';
320
+	}
321
+
322
+
323
+	/**
324
+	 * Retrieve registered data.
325
+	 *
326
+	 * @param string $key Name of key to attach data to.
327
+	 * @return mixed                If there is no for the given key, then false is returned.
328
+	 */
329
+	public function getData($key)
330
+	{
331
+		return isset($this->jsdata[ $key ])
332
+			? $this->jsdata[ $key ]
333
+			: false;
334
+	}
335
+
336
+
337
+	/**
338
+	 * Verifies whether the given data exists already on the jsdata array.
339
+	 * Overriding data is not allowed.
340
+	 *
341
+	 * @param string $key Index for data.
342
+	 * @return bool        If valid then return true.
343
+	 * @throws InvalidArgumentException if data already exists.
344
+	 */
345
+	protected function verifyDataNotExisting($key)
346
+	{
347
+		if (isset($this->jsdata[ $key ])) {
348
+			if (is_array($this->jsdata[ $key ])) {
349
+				throw new InvalidArgumentException(
350
+					sprintf(
351
+						__(
352
+							'The value for %1$s already exists in the Registry::eejs object.
353 353
                             Overrides are not allowed. Since the value of this data is an array, you may want to use the
354 354
                             %2$s method to push your value to the array.',
355
-                            'event_espresso'
356
-                        ),
357
-                        $key,
358
-                        'pushData()'
359
-                    )
360
-                );
361
-            }
362
-            throw new InvalidArgumentException(
363
-                sprintf(
364
-                    __(
365
-                        'The value for %1$s already exists in the Registry::eejs object. Overrides are not
355
+							'event_espresso'
356
+						),
357
+						$key,
358
+						'pushData()'
359
+					)
360
+				);
361
+			}
362
+			throw new InvalidArgumentException(
363
+				sprintf(
364
+					__(
365
+						'The value for %1$s already exists in the Registry::eejs object. Overrides are not
366 366
                         allowed.  Consider attaching your value to a different key',
367
-                        'event_espresso'
368
-                    ),
369
-                    $key
370
-                )
371
-            );
372
-        }
373
-        return true;
374
-    }
375
-
376
-
377
-    /**
378
-     * Get the actual asset path for asset manifests.
379
-     * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
380
-     *
381
-     * @param string $namespace  The namespace associated with the manifest file hosting the map of chunk_name to actual
382
-     *                           asset file location.
383
-     * @param string $chunk_name
384
-     * @param string $asset_type
385
-     * @return string
386
-     * @since 4.9.59.p
387
-     */
388
-    public function getAssetUrl($namespace, $chunk_name, $asset_type)
389
-    {
390
-        $url = isset(
391
-            $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ],
392
-            $this->manifest_data[ $namespace ]['url_base']
393
-        )
394
-            ? $this->manifest_data[ $namespace ]['url_base']
395
-              . $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ]
396
-            : $chunk_name;
397
-        return apply_filters(
398
-            'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl',
399
-            $url,
400
-            $namespace,
401
-            $chunk_name,
402
-            $asset_type
403
-        );
404
-    }
405
-
406
-
407
-
408
-    /**
409
-     * Return the url to a js file for the given namespace and chunk name.
410
-     *
411
-     * @param string $namespace
412
-     * @param string $chunk_name
413
-     * @return string
414
-     */
415
-    public function getJsUrl($namespace, $chunk_name)
416
-    {
417
-        return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS);
418
-    }
419
-
420
-
421
-    /**
422
-     * Return the url to a css file for the given namespace and chunk name.
423
-     *
424
-     * @param string $namespace
425
-     * @param string $chunk_name
426
-     * @return string
427
-     */
428
-    public function getCssUrl($namespace, $chunk_name)
429
-    {
430
-        return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS);
431
-    }
432
-
433
-
434
-    /**
435
-     * @since 4.9.62.p
436
-     * @throws InvalidArgumentException
437
-     * @throws InvalidFilePathException
438
-     */
439
-    public function registerManifestFiles()
440
-    {
441
-        $manifest_files = $this->assets->getManifestFiles();
442
-        foreach ($manifest_files as $manifest_file) {
443
-            $this->registerManifestFile(
444
-                $manifest_file->assetNamespace(),
445
-                $manifest_file->urlBase(),
446
-                $manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST
447
-            );
448
-        }
449
-    }
450
-
451
-
452
-    /**
453
-     * Used to register a js/css manifest file with the registered_manifest_files property.
454
-     *
455
-     * @param string $namespace     Provided to associate the manifest file with a specific namespace.
456
-     * @param string $url_base      The url base for the manifest file location.
457
-     * @param string $manifest_file The absolute path to the manifest file.
458
-     * @throws InvalidArgumentException
459
-     * @throws InvalidFilePathException
460
-     * @since 4.9.59.p
461
-     */
462
-    public function registerManifestFile($namespace, $url_base, $manifest_file)
463
-    {
464
-        if (isset($this->manifest_data[ $namespace ])) {
465
-            throw new InvalidArgumentException(
466
-                sprintf(
467
-                    esc_html__(
468
-                        'The namespace for this manifest file has already been registered, choose a namespace other than %s',
469
-                        'event_espresso'
470
-                    ),
471
-                    $namespace
472
-                )
473
-            );
474
-        }
475
-        if (filter_var($url_base, FILTER_VALIDATE_URL) === false) {
476
-            if (is_admin()) {
477
-                EE_Error::add_error(
478
-                    sprintf(
479
-                        esc_html__(
480
-                            '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',
481
-                            'event_espresso'
482
-                        ),
483
-                        'Event Espresso',
484
-                        $url_base,
485
-                        'plugins_url',
486
-                        'WP_PLUGIN_URL'
487
-                    ),
488
-                    __FILE__,
489
-                    __FUNCTION__,
490
-                    __LINE__
491
-                );
492
-            }
493
-            return;
494
-        }
495
-        $this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file);
496
-        if (! isset($this->manifest_data[ $namespace ]['url_base'])) {
497
-            $this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base);
498
-        }
499
-    }
500
-
501
-
502
-    /**
503
-     * Decodes json from the provided manifest file.
504
-     *
505
-     * @since 4.9.59.p
506
-     * @param string $manifest_file Path to manifest file.
507
-     * @return array
508
-     * @throws InvalidFilePathException
509
-     */
510
-    private function decodeManifestFile($manifest_file)
511
-    {
512
-        if (! file_exists($manifest_file)) {
513
-            throw new InvalidFilePathException($manifest_file);
514
-        }
515
-        return json_decode(file_get_contents($manifest_file), true);
516
-    }
517
-
518
-
519
-    /**
520
-     * This is used to set registered script handles that have data.
521
-     *
522
-     * @param string $script_handle
523
-     */
524
-    private function addRegisteredScriptHandlesWithData($script_handle)
525
-    {
526
-        $this->script_handles_with_data[ $script_handle ] = $script_handle;
527
-    }
528
-
529
-
530
-    /**i
367
+						'event_espresso'
368
+					),
369
+					$key
370
+				)
371
+			);
372
+		}
373
+		return true;
374
+	}
375
+
376
+
377
+	/**
378
+	 * Get the actual asset path for asset manifests.
379
+	 * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
380
+	 *
381
+	 * @param string $namespace  The namespace associated with the manifest file hosting the map of chunk_name to actual
382
+	 *                           asset file location.
383
+	 * @param string $chunk_name
384
+	 * @param string $asset_type
385
+	 * @return string
386
+	 * @since 4.9.59.p
387
+	 */
388
+	public function getAssetUrl($namespace, $chunk_name, $asset_type)
389
+	{
390
+		$url = isset(
391
+			$this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ],
392
+			$this->manifest_data[ $namespace ]['url_base']
393
+		)
394
+			? $this->manifest_data[ $namespace ]['url_base']
395
+			  . $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ]
396
+			: $chunk_name;
397
+		return apply_filters(
398
+			'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl',
399
+			$url,
400
+			$namespace,
401
+			$chunk_name,
402
+			$asset_type
403
+		);
404
+	}
405
+
406
+
407
+
408
+	/**
409
+	 * Return the url to a js file for the given namespace and chunk name.
410
+	 *
411
+	 * @param string $namespace
412
+	 * @param string $chunk_name
413
+	 * @return string
414
+	 */
415
+	public function getJsUrl($namespace, $chunk_name)
416
+	{
417
+		return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS);
418
+	}
419
+
420
+
421
+	/**
422
+	 * Return the url to a css file for the given namespace and chunk name.
423
+	 *
424
+	 * @param string $namespace
425
+	 * @param string $chunk_name
426
+	 * @return string
427
+	 */
428
+	public function getCssUrl($namespace, $chunk_name)
429
+	{
430
+		return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS);
431
+	}
432
+
433
+
434
+	/**
435
+	 * @since 4.9.62.p
436
+	 * @throws InvalidArgumentException
437
+	 * @throws InvalidFilePathException
438
+	 */
439
+	public function registerManifestFiles()
440
+	{
441
+		$manifest_files = $this->assets->getManifestFiles();
442
+		foreach ($manifest_files as $manifest_file) {
443
+			$this->registerManifestFile(
444
+				$manifest_file->assetNamespace(),
445
+				$manifest_file->urlBase(),
446
+				$manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST
447
+			);
448
+		}
449
+	}
450
+
451
+
452
+	/**
453
+	 * Used to register a js/css manifest file with the registered_manifest_files property.
454
+	 *
455
+	 * @param string $namespace     Provided to associate the manifest file with a specific namespace.
456
+	 * @param string $url_base      The url base for the manifest file location.
457
+	 * @param string $manifest_file The absolute path to the manifest file.
458
+	 * @throws InvalidArgumentException
459
+	 * @throws InvalidFilePathException
460
+	 * @since 4.9.59.p
461
+	 */
462
+	public function registerManifestFile($namespace, $url_base, $manifest_file)
463
+	{
464
+		if (isset($this->manifest_data[ $namespace ])) {
465
+			throw new InvalidArgumentException(
466
+				sprintf(
467
+					esc_html__(
468
+						'The namespace for this manifest file has already been registered, choose a namespace other than %s',
469
+						'event_espresso'
470
+					),
471
+					$namespace
472
+				)
473
+			);
474
+		}
475
+		if (filter_var($url_base, FILTER_VALIDATE_URL) === false) {
476
+			if (is_admin()) {
477
+				EE_Error::add_error(
478
+					sprintf(
479
+						esc_html__(
480
+							'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',
481
+							'event_espresso'
482
+						),
483
+						'Event Espresso',
484
+						$url_base,
485
+						'plugins_url',
486
+						'WP_PLUGIN_URL'
487
+					),
488
+					__FILE__,
489
+					__FUNCTION__,
490
+					__LINE__
491
+				);
492
+			}
493
+			return;
494
+		}
495
+		$this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file);
496
+		if (! isset($this->manifest_data[ $namespace ]['url_base'])) {
497
+			$this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base);
498
+		}
499
+	}
500
+
501
+
502
+	/**
503
+	 * Decodes json from the provided manifest file.
504
+	 *
505
+	 * @since 4.9.59.p
506
+	 * @param string $manifest_file Path to manifest file.
507
+	 * @return array
508
+	 * @throws InvalidFilePathException
509
+	 */
510
+	private function decodeManifestFile($manifest_file)
511
+	{
512
+		if (! file_exists($manifest_file)) {
513
+			throw new InvalidFilePathException($manifest_file);
514
+		}
515
+		return json_decode(file_get_contents($manifest_file), true);
516
+	}
517
+
518
+
519
+	/**
520
+	 * This is used to set registered script handles that have data.
521
+	 *
522
+	 * @param string $script_handle
523
+	 */
524
+	private function addRegisteredScriptHandlesWithData($script_handle)
525
+	{
526
+		$this->script_handles_with_data[ $script_handle ] = $script_handle;
527
+	}
528
+
529
+
530
+	/**i
531 531
      * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the
532 532
      * Dependency stored in WP_Scripts if its set.
533 533
      */
534
-    private function removeAlreadyRegisteredDataForScriptHandles()
535
-    {
536
-        if (empty($this->script_handles_with_data)) {
537
-            return;
538
-        }
539
-        foreach ($this->script_handles_with_data as $script_handle) {
540
-            $this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
541
-        }
542
-    }
543
-
544
-
545
-    /**
546
-     * Removes any data dependency registered in WP_Scripts if its set.
547
-     *
548
-     * @param string $script_handle
549
-     */
550
-    private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
551
-    {
552
-        if (isset($this->script_handles_with_data[ $script_handle ])) {
553
-            global $wp_scripts;
554
-            $unset_handle = false;
555
-            if ($wp_scripts->get_data($script_handle, 'data')) {
556
-                unset($wp_scripts->registered[ $script_handle ]->extra['data']);
557
-                $unset_handle = true;
558
-            }
559
-            //deal with inline_scripts
560
-            if ($wp_scripts->get_data($script_handle, 'before')) {
561
-                unset($wp_scripts->registered[ $script_handle ]->extra['before']);
562
-                $unset_handle = true;
563
-            }
564
-            if ($wp_scripts->get_data($script_handle, 'after')) {
565
-                unset($wp_scripts->registered[ $script_handle ]->extra['after']);
566
-            }
567
-            if ($unset_handle) {
568
-                unset($this->script_handles_with_data[ $script_handle ]);
569
-            }
570
-        }
571
-    }
572
-
573
-
574
-    /**
575
-     * register translations for a registered script
576
-     *
577
-     * @param string $handle
578
-     */
579
-    public function registerTranslation($handle)
580
-    {
581
-        $this->i18n_registry->registerScriptI18n($handle);
582
-    }
534
+	private function removeAlreadyRegisteredDataForScriptHandles()
535
+	{
536
+		if (empty($this->script_handles_with_data)) {
537
+			return;
538
+		}
539
+		foreach ($this->script_handles_with_data as $script_handle) {
540
+			$this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
541
+		}
542
+	}
543
+
544
+
545
+	/**
546
+	 * Removes any data dependency registered in WP_Scripts if its set.
547
+	 *
548
+	 * @param string $script_handle
549
+	 */
550
+	private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
551
+	{
552
+		if (isset($this->script_handles_with_data[ $script_handle ])) {
553
+			global $wp_scripts;
554
+			$unset_handle = false;
555
+			if ($wp_scripts->get_data($script_handle, 'data')) {
556
+				unset($wp_scripts->registered[ $script_handle ]->extra['data']);
557
+				$unset_handle = true;
558
+			}
559
+			//deal with inline_scripts
560
+			if ($wp_scripts->get_data($script_handle, 'before')) {
561
+				unset($wp_scripts->registered[ $script_handle ]->extra['before']);
562
+				$unset_handle = true;
563
+			}
564
+			if ($wp_scripts->get_data($script_handle, 'after')) {
565
+				unset($wp_scripts->registered[ $script_handle ]->extra['after']);
566
+			}
567
+			if ($unset_handle) {
568
+				unset($this->script_handles_with_data[ $script_handle ]);
569
+			}
570
+		}
571
+	}
572
+
573
+
574
+	/**
575
+	 * register translations for a registered script
576
+	 *
577
+	 * @param string $handle
578
+	 */
579
+	public function registerTranslation($handle)
580
+	{
581
+		$this->i18n_registry->registerScriptI18n($handle);
582
+	}
583 583
 }
Please login to merge, or discard this patch.
core/domain/services/assets/CoreAssetManager.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
             //js.api
174 174
             $this->addJavascript(
175 175
                 CoreAssetManager::JS_HANDLE_EE_JS_API,
176
-                EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
176
+                EE_LIBRARIES_URL.'rest_api/assets/js/eejs-api.min.js',
177 177
                 array(
178 178
                     CoreAssetManager::JS_HANDLE_UNDERSCORE,
179 179
                     CoreAssetManager::JS_HANDLE_EE_JS_CORE
@@ -185,11 +185,11 @@  discard block
 block discarded – undo
185 185
 
186 186
         $this->addJavascript(
187 187
             CoreAssetManager::JS_HANDLE_EE_CORE,
188
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
188
+            EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js',
189 189
             array(CoreAssetManager::JS_HANDLE_JQUERY)
190 190
         )
191 191
         ->setInlineDataCallback(
192
-            function () {
192
+            function() {
193 193
                 wp_localize_script(
194 194
                     CoreAssetManager::JS_HANDLE_EE_CORE,
195 195
                     CoreAssetManager::JS_HANDLE_EE_I18N,
@@ -211,16 +211,16 @@  discard block
 block discarded – undo
211 211
         if ($this->template_config->enable_default_style && ! is_admin()) {
212 212
             $this->addStylesheet(
213 213
                 CoreAssetManager::CSS_HANDLE_EE_DEFAULT,
214
-                is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
214
+                is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/style.css')
215 215
                     ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
216
-                    : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
216
+                    : EE_GLOBAL_ASSETS_URL.'css/espresso_default.css',
217 217
                 array('dashicons')
218 218
             );
219 219
             //Load custom style sheet if available
220 220
             if ($this->template_config->custom_style_sheet !== null) {
221 221
                 $this->addStylesheet(
222 222
                     CoreAssetManager::CSS_HANDLE_EE_CUSTOM,
223
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
223
+                    EVENT_ESPRESSO_UPLOAD_URL.'css/'.$this->template_config->custom_style_sheet,
224 224
                     array(CoreAssetManager::CSS_HANDLE_EE_DEFAULT)
225 225
                 );
226 226
             }
@@ -240,14 +240,14 @@  discard block
 block discarded – undo
240 240
     {
241 241
         $this->addJavascript(
242 242
             CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
243
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
243
+            EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.min.js',
244 244
             array(CoreAssetManager::JS_HANDLE_JQUERY)
245 245
         )
246 246
         ->setVersion('1.15.0');
247 247
 
248 248
         $this->addJavascript(
249 249
             CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
250
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
250
+            EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.additional-methods.min.js',
251 251
             array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE)
252 252
         )
253 253
         ->setVersion('1.15.0');
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
         // @link http://josscrowcroft.github.io/accounting.js/
269 269
         $this->addJavascript(
270 270
             CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
271
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
271
+            EE_THIRD_PARTY_URL.'accounting/accounting.js',
272 272
             array(CoreAssetManager::JS_HANDLE_UNDERSCORE)
273 273
         )
274 274
         ->setVersion('0.3.2');
@@ -276,11 +276,11 @@  discard block
 block discarded – undo
276 276
         $currency_config = $this->currency_config;
277 277
         $this->addJavascript(
278 278
             CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
279
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
279
+            EE_GLOBAL_ASSETS_URL.'scripts/ee-accounting-config.js',
280 280
             array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
281 281
         )
282 282
         ->setInlineDataCallback(
283
-            function () use ($currency_config) {
283
+            function() use ($currency_config) {
284 284
                  wp_localize_script(
285 285
                      CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
286 286
                      'EE_ACCOUNTING_CFG',
Please login to merge, or discard this patch.
Indentation   +340 added lines, -340 removed lines patch added patch discarded remove patch
@@ -28,345 +28,345 @@
 block discarded – undo
28 28
 class CoreAssetManager extends AssetManager
29 29
 {
30 30
 
31
-    // WordPress core / Third party JS asset handles
32
-    const JS_HANDLE_JQUERY                = 'jquery';
31
+	// WordPress core / Third party JS asset handles
32
+	const JS_HANDLE_JQUERY                = 'jquery';
33 33
 
34
-    const JS_HANDLE_JQUERY_VALIDATE       = 'jquery-validate';
35
-
36
-    const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods';
37
-
38
-    const JS_HANDLE_UNDERSCORE            = 'underscore';
39
-
40
-    const JS_HANDLE_ACCOUNTING_CORE       = 'ee-accounting-core';
41
-
42
-    // EE JS assets handles
43
-    const JS_HANDLE_EE_MANIFEST        = 'ee-manifest';
44
-
45
-    const JS_HANDLE_EE_JS_CORE         = 'eejs-core';
46
-
47
-    const JS_HANDLE_EE_VENDOR_REACT    = 'ee-vendor-react';
48
-
49
-    const JS_HANDLE_EE_DATA_STORES     = 'eventespresso-data-stores';
50
-
51
-    const JS_HANDLE_EE_JS_API          = 'eejs-api';
52
-
53
-    const JS_HANDLE_EE_CORE            = 'espresso_core';
54
-
55
-    const JS_HANDLE_EE_I18N            = 'eei18n';
56
-
57
-    const JS_HANDLE_EE_ACCOUNTING      = 'ee-accounting';
58
-
59
-    const JS_HANDLE_EE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page';
60
-
61
-    // EE CSS assets handles
62
-    const CSS_HANDLE_EE_DEFAULT = 'espresso_default';
63
-
64
-    const CSS_HANDLE_EE_CUSTOM  = 'espresso_custom_css';
65
-
66
-    /**
67
-     * @var EE_Currency_Config $currency_config
68
-     */
69
-    protected $currency_config;
70
-
71
-    /**
72
-     * @var EE_Template_Config $template_config
73
-     */
74
-    protected $template_config;
75
-
76
-
77
-    /**
78
-     * CoreAssetRegister constructor.
79
-     *
80
-     * @param AssetCollection    $assets
81
-     * @param EE_Currency_Config $currency_config
82
-     * @param EE_Template_Config $template_config
83
-     * @param DomainInterface    $domain
84
-     * @param Registry           $registry
85
-     */
86
-    public function __construct(
87
-        AssetCollection $assets,
88
-        EE_Currency_Config $currency_config,
89
-        EE_Template_Config $template_config,
90
-        DomainInterface $domain,
91
-        Registry $registry
92
-    ) {
93
-        $this->currency_config = $currency_config;
94
-        $this->template_config = $template_config;
95
-        parent::__construct($domain, $assets, $registry);
96
-    }
97
-
98
-
99
-    /**
100
-     * @since 4.9.62.p
101
-     * @throws DuplicateCollectionIdentifierException
102
-     * @throws InvalidArgumentException
103
-     * @throws InvalidDataTypeException
104
-     * @throws InvalidEntityException
105
-     */
106
-    public function addAssets()
107
-    {
108
-        $this->addJavascriptFiles();
109
-        $this->addStylesheetFiles();
110
-    }
111
-
112
-
113
-    /**
114
-     * @since 4.9.62.p
115
-     * @throws DuplicateCollectionIdentifierException
116
-     * @throws InvalidArgumentException
117
-     * @throws InvalidDataTypeException
118
-     * @throws InvalidEntityException
119
-     */
120
-    public function addJavascriptFiles()
121
-    {
122
-        $this->loadCoreJs();
123
-        $this->loadJqueryValidate();
124
-        $this->loadAccountingJs();
125
-        add_action(
126
-            'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
127
-            array($this, 'loadQtipJs')
128
-        );
129
-        $this->registerAdminAssets();
130
-    }
131
-
132
-
133
-    /**
134
-     * @since 4.9.62.p
135
-     * @throws DuplicateCollectionIdentifierException
136
-     * @throws InvalidDataTypeException
137
-     * @throws InvalidEntityException
138
-     */
139
-    public function addStylesheetFiles()
140
-    {
141
-        $this->loadCoreCss();
142
-    }
143
-
144
-
145
-    /**
146
-     * core default javascript
147
-     *
148
-     * @since 4.9.62.p
149
-     * @throws DuplicateCollectionIdentifierException
150
-     * @throws InvalidArgumentException
151
-     * @throws InvalidDataTypeException
152
-     * @throws InvalidEntityException
153
-     */
154
-    private function loadCoreJs()
155
-    {
156
-        $this->addJavascript(
157
-            CoreAssetManager::JS_HANDLE_EE_MANIFEST,
158
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'manifest')
159
-        );
160
-
161
-        $this->addJavascript(
162
-            CoreAssetManager::JS_HANDLE_EE_JS_CORE,
163
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'eejs'),
164
-            array(CoreAssetManager::JS_HANDLE_EE_MANIFEST)
165
-        )
166
-        ->setHasInlineData();
167
-
168
-        $this->addJavascript(
169
-            CoreAssetManager::JS_HANDLE_EE_VENDOR_REACT,
170
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'reactVendor'),
171
-            array(CoreAssetManager::JS_HANDLE_EE_JS_CORE)
172
-        );
173
-
174
-        $this->addJavascript(
175
-            CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
176
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'data-stores'),
177
-            array(CoreAssetManager::JS_HANDLE_EE_VENDOR_REACT, 'wp-data')
178
-        )
179
-        ->setRequiresTranslation();
180
-
181
-        global $wp_version;
182
-        if (version_compare($wp_version, '4.4.0', '>')) {
183
-            //js.api
184
-            $this->addJavascript(
185
-                CoreAssetManager::JS_HANDLE_EE_JS_API,
186
-                EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
187
-                array(
188
-                    CoreAssetManager::JS_HANDLE_UNDERSCORE,
189
-                    CoreAssetManager::JS_HANDLE_EE_JS_CORE
190
-                )
191
-            );
192
-            $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest'));
193
-            $this->registry->addData(
194
-                'paths',
195
-                array(
196
-                    'rest_route' => rest_url('ee/v4.8.36/'),
197
-                    'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(),
198
-                    'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName()
199
-                )
200
-            );
201
-        }
202
-
203
-        $this->addJavascript(
204
-            CoreAssetManager::JS_HANDLE_EE_CORE,
205
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
206
-            array(CoreAssetManager::JS_HANDLE_JQUERY)
207
-        )
208
-        ->setInlineDataCallback(
209
-            function () {
210
-                wp_localize_script(
211
-                    CoreAssetManager::JS_HANDLE_EE_CORE,
212
-                    CoreAssetManager::JS_HANDLE_EE_I18N,
213
-                    EE_Registry::$i18n_js_strings
214
-                );
215
-            }
216
-        );
217
-    }
218
-
219
-
220
-    /**
221
-     * @since 4.9.62.p
222
-     * @throws DuplicateCollectionIdentifierException
223
-     * @throws InvalidDataTypeException
224
-     * @throws InvalidEntityException
225
-     */
226
-    private function loadCoreCss()
227
-    {
228
-        if ($this->template_config->enable_default_style && ! is_admin()) {
229
-            $this->addStylesheet(
230
-                CoreAssetManager::CSS_HANDLE_EE_DEFAULT,
231
-                is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
232
-                    ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
233
-                    : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
234
-                array('dashicons')
235
-            );
236
-            //Load custom style sheet if available
237
-            if ($this->template_config->custom_style_sheet !== null) {
238
-                $this->addStylesheet(
239
-                    CoreAssetManager::CSS_HANDLE_EE_CUSTOM,
240
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
241
-                    array(CoreAssetManager::CSS_HANDLE_EE_DEFAULT)
242
-                );
243
-            }
244
-        }
245
-    }
246
-
247
-
248
-    /**
249
-     * jQuery Validate for form validation
250
-     *
251
-     * @since 4.9.62.p
252
-     * @throws DuplicateCollectionIdentifierException
253
-     * @throws InvalidDataTypeException
254
-     * @throws InvalidEntityException
255
-     */
256
-    private function loadJqueryValidate()
257
-    {
258
-        $this->addJavascript(
259
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
260
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
261
-            array(CoreAssetManager::JS_HANDLE_JQUERY)
262
-        )
263
-        ->setVersion('1.15.0');
264
-
265
-        $this->addJavascript(
266
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
267
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
268
-            array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE)
269
-        )
270
-        ->setVersion('1.15.0');
271
-    }
272
-
273
-
274
-    /**
275
-     * accounting.js for performing client-side calculations
276
-     *
277
-     * @since 4.9.62.p
278
-     * @throws DuplicateCollectionIdentifierException
279
-     * @throws InvalidDataTypeException
280
-     * @throws InvalidEntityException
281
-     */
282
-    private function loadAccountingJs()
283
-    {
284
-        //accounting.js library
285
-        // @link http://josscrowcroft.github.io/accounting.js/
286
-        $this->addJavascript(
287
-            CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
288
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
289
-            array(CoreAssetManager::JS_HANDLE_UNDERSCORE)
290
-        )
291
-        ->setVersion('0.3.2');
292
-
293
-        $currency_config = $this->currency_config;
294
-        $this->addJavascript(
295
-            CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
296
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
297
-            array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
298
-        )
299
-        ->setInlineDataCallback(
300
-            function () use ($currency_config) {
301
-                 wp_localize_script(
302
-                     CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
303
-                     'EE_ACCOUNTING_CFG',
304
-                     array(
305
-                         'currency' => array(
306
-                             'symbol'    => $currency_config->sign,
307
-                             'format'    => array(
308
-                                 'pos'  => $currency_config->sign_b4 ? '%s%v' : '%v%s',
309
-                                 'neg'  => $currency_config->sign_b4 ? '- %s%v' : '- %v%s',
310
-                                 'zero' => $currency_config->sign_b4 ? '%s--' : '--%s',
311
-                             ),
312
-                             'decimal'   => $currency_config->dec_mrk,
313
-                             'thousand'  => $currency_config->thsnds,
314
-                             'precision' => $currency_config->dec_plc,
315
-                         ),
316
-                         'number'   => array(
317
-                             'precision' => $currency_config->dec_plc,
318
-                             'thousand'  => $currency_config->thsnds,
319
-                             'decimal'   => $currency_config->dec_mrk,
320
-                         ),
321
-                     )
322
-                 );
323
-            }
324
-        )
325
-        ->setVersion();
326
-    }
327
-
328
-
329
-    /**
330
-     * registers assets for cleaning your ears
331
-     *
332
-     * @param JavascriptAsset $script
333
-     */
334
-    public function loadQtipJs(JavascriptAsset $script)
335
-    {
336
-        // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
337
-        // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
338
-        if (
339
-            $script->handle() === CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE
340
-            && apply_filters('FHEE_load_qtip', false)
341
-        ) {
342
-            EEH_Qtip_Loader::instance()->register_and_enqueue();
343
-        }
344
-    }
345
-
346
-
347
-    /**
348
-     * assets that are used in the WordPress admin
349
-     *
350
-     * @since 4.9.62.p
351
-     * @throws DuplicateCollectionIdentifierException
352
-     * @throws InvalidDataTypeException
353
-     * @throws InvalidEntityException
354
-     */
355
-    private function registerAdminAssets()
356
-    {
357
-        $this->addJavascript(
358
-            CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE,
359
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'),
360
-            array(
361
-                CoreAssetManager::JS_HANDLE_JQUERY,
362
-                CoreAssetManager::JS_HANDLE_EE_VENDOR_REACT,
363
-            )
364
-        )
365
-        ->setRequiresTranslation();
366
-
367
-        $this->addStylesheet(
368
-            CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE,
369
-            $this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page')
370
-        );
371
-    }
34
+	const JS_HANDLE_JQUERY_VALIDATE       = 'jquery-validate';
35
+
36
+	const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods';
37
+
38
+	const JS_HANDLE_UNDERSCORE            = 'underscore';
39
+
40
+	const JS_HANDLE_ACCOUNTING_CORE       = 'ee-accounting-core';
41
+
42
+	// EE JS assets handles
43
+	const JS_HANDLE_EE_MANIFEST        = 'ee-manifest';
44
+
45
+	const JS_HANDLE_EE_JS_CORE         = 'eejs-core';
46
+
47
+	const JS_HANDLE_EE_VENDOR_REACT    = 'ee-vendor-react';
48
+
49
+	const JS_HANDLE_EE_DATA_STORES     = 'eventespresso-data-stores';
50
+
51
+	const JS_HANDLE_EE_JS_API          = 'eejs-api';
52
+
53
+	const JS_HANDLE_EE_CORE            = 'espresso_core';
54
+
55
+	const JS_HANDLE_EE_I18N            = 'eei18n';
56
+
57
+	const JS_HANDLE_EE_ACCOUNTING      = 'ee-accounting';
58
+
59
+	const JS_HANDLE_EE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page';
60
+
61
+	// EE CSS assets handles
62
+	const CSS_HANDLE_EE_DEFAULT = 'espresso_default';
63
+
64
+	const CSS_HANDLE_EE_CUSTOM  = 'espresso_custom_css';
65
+
66
+	/**
67
+	 * @var EE_Currency_Config $currency_config
68
+	 */
69
+	protected $currency_config;
70
+
71
+	/**
72
+	 * @var EE_Template_Config $template_config
73
+	 */
74
+	protected $template_config;
75
+
76
+
77
+	/**
78
+	 * CoreAssetRegister constructor.
79
+	 *
80
+	 * @param AssetCollection    $assets
81
+	 * @param EE_Currency_Config $currency_config
82
+	 * @param EE_Template_Config $template_config
83
+	 * @param DomainInterface    $domain
84
+	 * @param Registry           $registry
85
+	 */
86
+	public function __construct(
87
+		AssetCollection $assets,
88
+		EE_Currency_Config $currency_config,
89
+		EE_Template_Config $template_config,
90
+		DomainInterface $domain,
91
+		Registry $registry
92
+	) {
93
+		$this->currency_config = $currency_config;
94
+		$this->template_config = $template_config;
95
+		parent::__construct($domain, $assets, $registry);
96
+	}
97
+
98
+
99
+	/**
100
+	 * @since 4.9.62.p
101
+	 * @throws DuplicateCollectionIdentifierException
102
+	 * @throws InvalidArgumentException
103
+	 * @throws InvalidDataTypeException
104
+	 * @throws InvalidEntityException
105
+	 */
106
+	public function addAssets()
107
+	{
108
+		$this->addJavascriptFiles();
109
+		$this->addStylesheetFiles();
110
+	}
111
+
112
+
113
+	/**
114
+	 * @since 4.9.62.p
115
+	 * @throws DuplicateCollectionIdentifierException
116
+	 * @throws InvalidArgumentException
117
+	 * @throws InvalidDataTypeException
118
+	 * @throws InvalidEntityException
119
+	 */
120
+	public function addJavascriptFiles()
121
+	{
122
+		$this->loadCoreJs();
123
+		$this->loadJqueryValidate();
124
+		$this->loadAccountingJs();
125
+		add_action(
126
+			'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
127
+			array($this, 'loadQtipJs')
128
+		);
129
+		$this->registerAdminAssets();
130
+	}
131
+
132
+
133
+	/**
134
+	 * @since 4.9.62.p
135
+	 * @throws DuplicateCollectionIdentifierException
136
+	 * @throws InvalidDataTypeException
137
+	 * @throws InvalidEntityException
138
+	 */
139
+	public function addStylesheetFiles()
140
+	{
141
+		$this->loadCoreCss();
142
+	}
143
+
144
+
145
+	/**
146
+	 * core default javascript
147
+	 *
148
+	 * @since 4.9.62.p
149
+	 * @throws DuplicateCollectionIdentifierException
150
+	 * @throws InvalidArgumentException
151
+	 * @throws InvalidDataTypeException
152
+	 * @throws InvalidEntityException
153
+	 */
154
+	private function loadCoreJs()
155
+	{
156
+		$this->addJavascript(
157
+			CoreAssetManager::JS_HANDLE_EE_MANIFEST,
158
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'manifest')
159
+		);
160
+
161
+		$this->addJavascript(
162
+			CoreAssetManager::JS_HANDLE_EE_JS_CORE,
163
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'eejs'),
164
+			array(CoreAssetManager::JS_HANDLE_EE_MANIFEST)
165
+		)
166
+		->setHasInlineData();
167
+
168
+		$this->addJavascript(
169
+			CoreAssetManager::JS_HANDLE_EE_VENDOR_REACT,
170
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'reactVendor'),
171
+			array(CoreAssetManager::JS_HANDLE_EE_JS_CORE)
172
+		);
173
+
174
+		$this->addJavascript(
175
+			CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
176
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'data-stores'),
177
+			array(CoreAssetManager::JS_HANDLE_EE_VENDOR_REACT, 'wp-data')
178
+		)
179
+		->setRequiresTranslation();
180
+
181
+		global $wp_version;
182
+		if (version_compare($wp_version, '4.4.0', '>')) {
183
+			//js.api
184
+			$this->addJavascript(
185
+				CoreAssetManager::JS_HANDLE_EE_JS_API,
186
+				EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
187
+				array(
188
+					CoreAssetManager::JS_HANDLE_UNDERSCORE,
189
+					CoreAssetManager::JS_HANDLE_EE_JS_CORE
190
+				)
191
+			);
192
+			$this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest'));
193
+			$this->registry->addData(
194
+				'paths',
195
+				array(
196
+					'rest_route' => rest_url('ee/v4.8.36/'),
197
+					'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(),
198
+					'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName()
199
+				)
200
+			);
201
+		}
202
+
203
+		$this->addJavascript(
204
+			CoreAssetManager::JS_HANDLE_EE_CORE,
205
+			EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
206
+			array(CoreAssetManager::JS_HANDLE_JQUERY)
207
+		)
208
+		->setInlineDataCallback(
209
+			function () {
210
+				wp_localize_script(
211
+					CoreAssetManager::JS_HANDLE_EE_CORE,
212
+					CoreAssetManager::JS_HANDLE_EE_I18N,
213
+					EE_Registry::$i18n_js_strings
214
+				);
215
+			}
216
+		);
217
+	}
218
+
219
+
220
+	/**
221
+	 * @since 4.9.62.p
222
+	 * @throws DuplicateCollectionIdentifierException
223
+	 * @throws InvalidDataTypeException
224
+	 * @throws InvalidEntityException
225
+	 */
226
+	private function loadCoreCss()
227
+	{
228
+		if ($this->template_config->enable_default_style && ! is_admin()) {
229
+			$this->addStylesheet(
230
+				CoreAssetManager::CSS_HANDLE_EE_DEFAULT,
231
+				is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
232
+					? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
233
+					: EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
234
+				array('dashicons')
235
+			);
236
+			//Load custom style sheet if available
237
+			if ($this->template_config->custom_style_sheet !== null) {
238
+				$this->addStylesheet(
239
+					CoreAssetManager::CSS_HANDLE_EE_CUSTOM,
240
+					EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
241
+					array(CoreAssetManager::CSS_HANDLE_EE_DEFAULT)
242
+				);
243
+			}
244
+		}
245
+	}
246
+
247
+
248
+	/**
249
+	 * jQuery Validate for form validation
250
+	 *
251
+	 * @since 4.9.62.p
252
+	 * @throws DuplicateCollectionIdentifierException
253
+	 * @throws InvalidDataTypeException
254
+	 * @throws InvalidEntityException
255
+	 */
256
+	private function loadJqueryValidate()
257
+	{
258
+		$this->addJavascript(
259
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
260
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
261
+			array(CoreAssetManager::JS_HANDLE_JQUERY)
262
+		)
263
+		->setVersion('1.15.0');
264
+
265
+		$this->addJavascript(
266
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
267
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
268
+			array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE)
269
+		)
270
+		->setVersion('1.15.0');
271
+	}
272
+
273
+
274
+	/**
275
+	 * accounting.js for performing client-side calculations
276
+	 *
277
+	 * @since 4.9.62.p
278
+	 * @throws DuplicateCollectionIdentifierException
279
+	 * @throws InvalidDataTypeException
280
+	 * @throws InvalidEntityException
281
+	 */
282
+	private function loadAccountingJs()
283
+	{
284
+		//accounting.js library
285
+		// @link http://josscrowcroft.github.io/accounting.js/
286
+		$this->addJavascript(
287
+			CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
288
+			EE_THIRD_PARTY_URL . 'accounting/accounting.js',
289
+			array(CoreAssetManager::JS_HANDLE_UNDERSCORE)
290
+		)
291
+		->setVersion('0.3.2');
292
+
293
+		$currency_config = $this->currency_config;
294
+		$this->addJavascript(
295
+			CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
296
+			EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
297
+			array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
298
+		)
299
+		->setInlineDataCallback(
300
+			function () use ($currency_config) {
301
+				 wp_localize_script(
302
+					 CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
303
+					 'EE_ACCOUNTING_CFG',
304
+					 array(
305
+						 'currency' => array(
306
+							 'symbol'    => $currency_config->sign,
307
+							 'format'    => array(
308
+								 'pos'  => $currency_config->sign_b4 ? '%s%v' : '%v%s',
309
+								 'neg'  => $currency_config->sign_b4 ? '- %s%v' : '- %v%s',
310
+								 'zero' => $currency_config->sign_b4 ? '%s--' : '--%s',
311
+							 ),
312
+							 'decimal'   => $currency_config->dec_mrk,
313
+							 'thousand'  => $currency_config->thsnds,
314
+							 'precision' => $currency_config->dec_plc,
315
+						 ),
316
+						 'number'   => array(
317
+							 'precision' => $currency_config->dec_plc,
318
+							 'thousand'  => $currency_config->thsnds,
319
+							 'decimal'   => $currency_config->dec_mrk,
320
+						 ),
321
+					 )
322
+				 );
323
+			}
324
+		)
325
+		->setVersion();
326
+	}
327
+
328
+
329
+	/**
330
+	 * registers assets for cleaning your ears
331
+	 *
332
+	 * @param JavascriptAsset $script
333
+	 */
334
+	public function loadQtipJs(JavascriptAsset $script)
335
+	{
336
+		// qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
337
+		// can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
338
+		if (
339
+			$script->handle() === CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE
340
+			&& apply_filters('FHEE_load_qtip', false)
341
+		) {
342
+			EEH_Qtip_Loader::instance()->register_and_enqueue();
343
+		}
344
+	}
345
+
346
+
347
+	/**
348
+	 * assets that are used in the WordPress admin
349
+	 *
350
+	 * @since 4.9.62.p
351
+	 * @throws DuplicateCollectionIdentifierException
352
+	 * @throws InvalidDataTypeException
353
+	 * @throws InvalidEntityException
354
+	 */
355
+	private function registerAdminAssets()
356
+	{
357
+		$this->addJavascript(
358
+			CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE,
359
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'),
360
+			array(
361
+				CoreAssetManager::JS_HANDLE_JQUERY,
362
+				CoreAssetManager::JS_HANDLE_EE_VENDOR_REACT,
363
+			)
364
+		)
365
+		->setRequiresTranslation();
366
+
367
+		$this->addStylesheet(
368
+			CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE,
369
+			$this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page')
370
+		);
371
+	}
372 372
 }
Please login to merge, or discard this patch.
core/domain/values/assets/JavascriptAsset.php 1 patch
Indentation   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -17,142 +17,142 @@
 block discarded – undo
17 17
 class JavascriptAsset extends BrowserAsset
18 18
 {
19 19
 
20
-    /**
21
-     * @var boolean $load_in_footer
22
-     */
23
-    private $load_in_footer = false;
24
-
25
-    /**
26
-     * @var boolean $requires_translation
27
-     */
28
-    private $requires_translation = false;
29
-
30
-    /**
31
-     * @var boolean $has_inline_data
32
-     */
33
-    private $has_inline_data = false;
34
-
35
-    /**
36
-     * @var Closure $inline_data_callback
37
-     */
38
-    private $inline_data_callback;
39
-
40
-
41
-    /**
42
-     * Asset constructor.
43
-     *
44
-     * @param string          $handle
45
-     * @param string          $source
46
-     * @param array           $dependencies
47
-     * @param bool            $load_in_footer
48
-     * @param DomainInterface $domain
49
-     * @throws InvalidDataTypeException
50
-     */
51
-    public function __construct(
52
-        $handle,
53
-        $source,
54
-        array $dependencies,
55
-        $load_in_footer,
56
-        DomainInterface $domain
57
-    ) {
58
-        parent::__construct(Asset::TYPE_JS, $handle, $source, $dependencies, $domain);
59
-        $this->setLoadInFooter($load_in_footer);
60
-    }
61
-
62
-
63
-    /**
64
-     * @return bool
65
-     */
66
-    public function loadInFooter()
67
-    {
68
-        return $this->load_in_footer;
69
-    }
70
-
71
-
72
-    /**
73
-     * @param bool $load_in_footer
74
-     */
75
-    private function setLoadInFooter($load_in_footer = true)
76
-    {
77
-        $this->load_in_footer = filter_var($load_in_footer, FILTER_VALIDATE_BOOLEAN);
78
-    }
79
-
80
-
81
-    /**
82
-     * @return bool
83
-     */
84
-    public function requiresTranslation()
85
-    {
86
-        return $this->requires_translation;
87
-    }
88
-
89
-
90
-    /**
91
-     * @param bool $requires_translation
92
-     * @return JavascriptAsset
93
-     */
94
-    public function setRequiresTranslation($requires_translation = true)
95
-    {
96
-        $this->requires_translation = filter_var($requires_translation, FILTER_VALIDATE_BOOLEAN);
97
-        return $this;
98
-    }
99
-
100
-
101
-    /**
102
-     * @return bool
103
-     */
104
-    public function hasInlineData()
105
-    {
106
-        return $this->has_inline_data;
107
-    }
108
-
109
-
110
-    /**
111
-     * @param bool $has_inline_data
112
-     * @return JavascriptAsset
113
-     */
114
-    public function setHasInlineData($has_inline_data = true)
115
-    {
116
-        $this->has_inline_data = filter_var($has_inline_data, FILTER_VALIDATE_BOOLEAN);
117
-        return $this;
118
-    }
119
-
120
-
121
-    /**
122
-     * @return Closure
123
-     */
124
-    public function inlineDataCallback()
125
-    {
126
-        return $this->inline_data_callback;
127
-    }
128
-
129
-
130
-    /**
131
-     * @return bool
132
-     */
133
-    public function hasInlineDataCallback()
134
-    {
135
-        return $this->inline_data_callback instanceof Closure;
136
-    }
137
-
138
-
139
-    /**
140
-     * @param Closure $inline_data_callback
141
-     * @return JavascriptAsset
142
-     */
143
-    public function setInlineDataCallback(Closure $inline_data_callback)
144
-    {
145
-        $this->inline_data_callback = $inline_data_callback;
146
-        $this->setHasInlineData();
147
-        return $this;
148
-    }
149
-
150
-
151
-    /**
152
-     * @since 4.9.62.p
153
-     */
154
-    public function enqueueAsset()
155
-    {
156
-        wp_enqueue_script($this->handle());
157
-    }
20
+	/**
21
+	 * @var boolean $load_in_footer
22
+	 */
23
+	private $load_in_footer = false;
24
+
25
+	/**
26
+	 * @var boolean $requires_translation
27
+	 */
28
+	private $requires_translation = false;
29
+
30
+	/**
31
+	 * @var boolean $has_inline_data
32
+	 */
33
+	private $has_inline_data = false;
34
+
35
+	/**
36
+	 * @var Closure $inline_data_callback
37
+	 */
38
+	private $inline_data_callback;
39
+
40
+
41
+	/**
42
+	 * Asset constructor.
43
+	 *
44
+	 * @param string          $handle
45
+	 * @param string          $source
46
+	 * @param array           $dependencies
47
+	 * @param bool            $load_in_footer
48
+	 * @param DomainInterface $domain
49
+	 * @throws InvalidDataTypeException
50
+	 */
51
+	public function __construct(
52
+		$handle,
53
+		$source,
54
+		array $dependencies,
55
+		$load_in_footer,
56
+		DomainInterface $domain
57
+	) {
58
+		parent::__construct(Asset::TYPE_JS, $handle, $source, $dependencies, $domain);
59
+		$this->setLoadInFooter($load_in_footer);
60
+	}
61
+
62
+
63
+	/**
64
+	 * @return bool
65
+	 */
66
+	public function loadInFooter()
67
+	{
68
+		return $this->load_in_footer;
69
+	}
70
+
71
+
72
+	/**
73
+	 * @param bool $load_in_footer
74
+	 */
75
+	private function setLoadInFooter($load_in_footer = true)
76
+	{
77
+		$this->load_in_footer = filter_var($load_in_footer, FILTER_VALIDATE_BOOLEAN);
78
+	}
79
+
80
+
81
+	/**
82
+	 * @return bool
83
+	 */
84
+	public function requiresTranslation()
85
+	{
86
+		return $this->requires_translation;
87
+	}
88
+
89
+
90
+	/**
91
+	 * @param bool $requires_translation
92
+	 * @return JavascriptAsset
93
+	 */
94
+	public function setRequiresTranslation($requires_translation = true)
95
+	{
96
+		$this->requires_translation = filter_var($requires_translation, FILTER_VALIDATE_BOOLEAN);
97
+		return $this;
98
+	}
99
+
100
+
101
+	/**
102
+	 * @return bool
103
+	 */
104
+	public function hasInlineData()
105
+	{
106
+		return $this->has_inline_data;
107
+	}
108
+
109
+
110
+	/**
111
+	 * @param bool $has_inline_data
112
+	 * @return JavascriptAsset
113
+	 */
114
+	public function setHasInlineData($has_inline_data = true)
115
+	{
116
+		$this->has_inline_data = filter_var($has_inline_data, FILTER_VALIDATE_BOOLEAN);
117
+		return $this;
118
+	}
119
+
120
+
121
+	/**
122
+	 * @return Closure
123
+	 */
124
+	public function inlineDataCallback()
125
+	{
126
+		return $this->inline_data_callback;
127
+	}
128
+
129
+
130
+	/**
131
+	 * @return bool
132
+	 */
133
+	public function hasInlineDataCallback()
134
+	{
135
+		return $this->inline_data_callback instanceof Closure;
136
+	}
137
+
138
+
139
+	/**
140
+	 * @param Closure $inline_data_callback
141
+	 * @return JavascriptAsset
142
+	 */
143
+	public function setInlineDataCallback(Closure $inline_data_callback)
144
+	{
145
+		$this->inline_data_callback = $inline_data_callback;
146
+		$this->setHasInlineData();
147
+		return $this;
148
+	}
149
+
150
+
151
+	/**
152
+	 * @since 4.9.62.p
153
+	 */
154
+	public function enqueueAsset()
155
+	{
156
+		wp_enqueue_script($this->handle());
157
+	}
158 158
 }
Please login to merge, or discard this patch.
core/services/assets/BlockAssetManager.php 2 patches
Indentation   +305 added lines, -305 removed lines patch added patch discarded remove patch
@@ -22,310 +22,310 @@
 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 $VID:$
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->setScriptHandle($this->getScriptHandle());
140
-        $this->setStyleHandle($this->getStyleHandle());
141
-    }
142
-
143
-
144
-    /**
145
-     * @param       $handle
146
-     * @param array $dependencies
147
-     * @since $VID:$
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->has($handle)){
156
-            return $this->assets->get($handle);
157
-        }
158
-        return parent::addJavascript(
159
-            $handle,
160
-            $this->registry->getJsUrl(
161
-                $this->domain->assetNamespace(),
162
-                $handle
163
-            ),
164
-            $this->addDefaultBlockScriptDependencies($dependencies)
165
-        )
166
-        ->setRequiresTranslation();
167
-    }
168
-
169
-
170
-    /**
171
-     * @param        $handle
172
-     * @param array  $dependencies
173
-     * @since $VID:$
174
-     * @return StylesheetAsset
175
-     * @throws InvalidDataTypeException
176
-     * @throws InvalidEntityException
177
-     * @throws DuplicateCollectionIdentifierException
178
-     */
179
-    public function addEditorStyle($handle, array $dependencies = array())
180
-    {
181
-        if ($this->assets->has($handle)) {
182
-            return $this->assets->get($handle);
183
-        }
184
-        return parent::addStylesheet(
185
-            $handle,
186
-            $this->registry->getCssUrl(
187
-                $this->domain->assetNamespace(),
188
-                $handle
189
-            ),
190
-            $dependencies
191
-        );
192
-    }
193
-
194
-
195
-    /**
196
-     * @param       $handle
197
-     * @param array $dependencies
198
-     * @since $VID:$
199
-     * @return JavascriptAsset
200
-     * @throws InvalidDataTypeException
201
-     * @throws InvalidEntityException
202
-     * @throws DuplicateCollectionIdentifierException
203
-     */
204
-    public function addScript($handle, array $dependencies = array())
205
-    {
206
-        if ($this->assets->has($handle)) {
207
-            return $this->assets->get($handle);
208
-        }
209
-        return parent::addJavascript(
210
-            $handle,
211
-            $this->registry->getJsUrl(
212
-                $this->domain->assetNamespace(),
213
-                $handle
214
-            ),
215
-            $this->addDefaultBlockScriptDependencies($dependencies)
216
-        )
217
-        ->setRequiresTranslation();
218
-    }
219
-
220
-
221
-    /**
222
-     * @param        $handle
223
-     * @param array  $dependencies
224
-     * @since $VID:$
225
-     * @return StylesheetAsset
226
-     * @throws InvalidDataTypeException
227
-     * @throws InvalidEntityException
228
-     * @throws DuplicateCollectionIdentifierException
229
-     */
230
-    public function addStyle($handle, array $dependencies = array())
231
-    {
232
-        if ($this->assets->has($handle)) {
233
-            return $this->assets->get($handle);
234
-        }
235
-        return parent::addStylesheet(
236
-            $handle,
237
-            $this->registry->getCssUrl(
238
-                $this->domain->assetNamespace(),
239
-                $handle
240
-            ),
241
-            $dependencies
242
-        );
243
-    }
244
-
245
-
246
-    /**
247
-     * @param array $dependencies
248
-     * @return array
249
-     */
250
-    protected function addDefaultBlockScriptDependencies(array $dependencies)
251
-    {
252
-        $dependencies += array(
253
-                CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
254
-                'wp-blocks',    // Provides useful functions and components for extending the editor
255
-                'wp-i18n',      // Provides localization functions
256
-                'wp-element',   // Provides React.Component
257
-                'wp-components' // Provides many prebuilt components and controls
258
-            );
259
-        return $dependencies;
260
-    }
261
-
262
-
263
-    /**
264
-     * @param string $handle
265
-     * @since $VID:$
266
-     * @return mixed|null
267
-     */
268
-    public function getAsset($handle)
269
-    {
270
-        if ($this->assets->has($handle)) {
271
-            return $this->assets->get($handle);
272
-        }
273
-        return null;
274
-    }
275
-
276
-
277
-    /**
278
-     * @return JavascriptAsset|null
279
-     */
280
-    public function getEditorScript()
281
-    {
282
-        return $this->getAsset($this->editor_script_handle);
283
-    }
284
-
285
-
286
-    /**
287
-     * @return StylesheetAsset|null
288
-     */
289
-    public function getEditorStyle()
290
-    {
291
-        return $this->getAsset($this->editor_style_handle);
292
-    }
293
-
294
-
295
-    /**
296
-     * @return JavascriptAsset|null
297
-     */
298
-    public function getScript()
299
-    {
300
-        return $this->getAsset($this->script_handle);
301
-    }
302
-
303
-
304
-    /**
305
-     * @return StylesheetAsset|null
306
-     */
307
-    public function getStyle()
308
-    {
309
-        return $this->getAsset($this->style_handle);
310
-    }
311
-
312
-
313
-    /**
314
-     * @return  void
315
-     */
316
-    public function enqueueAssets()
317
-    {
318
-        $assets = array(
319
-            $this->getEditorScript(),
320
-            $this->getEditorStyle(),
321
-            $this->getScript(),
322
-            $this->getStyle(),
323
-        );
324
-        foreach ($assets as $asset) {
325
-            if ($asset instanceof BrowserAsset && $asset->isRegistered()) {
326
-                $asset->enqueueAsset();
327
-            }
328
-        }
329
-    }
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 $VID:$
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->setScriptHandle($this->getScriptHandle());
140
+		$this->setStyleHandle($this->getStyleHandle());
141
+	}
142
+
143
+
144
+	/**
145
+	 * @param       $handle
146
+	 * @param array $dependencies
147
+	 * @since $VID:$
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->has($handle)){
156
+			return $this->assets->get($handle);
157
+		}
158
+		return parent::addJavascript(
159
+			$handle,
160
+			$this->registry->getJsUrl(
161
+				$this->domain->assetNamespace(),
162
+				$handle
163
+			),
164
+			$this->addDefaultBlockScriptDependencies($dependencies)
165
+		)
166
+		->setRequiresTranslation();
167
+	}
168
+
169
+
170
+	/**
171
+	 * @param        $handle
172
+	 * @param array  $dependencies
173
+	 * @since $VID:$
174
+	 * @return StylesheetAsset
175
+	 * @throws InvalidDataTypeException
176
+	 * @throws InvalidEntityException
177
+	 * @throws DuplicateCollectionIdentifierException
178
+	 */
179
+	public function addEditorStyle($handle, array $dependencies = array())
180
+	{
181
+		if ($this->assets->has($handle)) {
182
+			return $this->assets->get($handle);
183
+		}
184
+		return parent::addStylesheet(
185
+			$handle,
186
+			$this->registry->getCssUrl(
187
+				$this->domain->assetNamespace(),
188
+				$handle
189
+			),
190
+			$dependencies
191
+		);
192
+	}
193
+
194
+
195
+	/**
196
+	 * @param       $handle
197
+	 * @param array $dependencies
198
+	 * @since $VID:$
199
+	 * @return JavascriptAsset
200
+	 * @throws InvalidDataTypeException
201
+	 * @throws InvalidEntityException
202
+	 * @throws DuplicateCollectionIdentifierException
203
+	 */
204
+	public function addScript($handle, array $dependencies = array())
205
+	{
206
+		if ($this->assets->has($handle)) {
207
+			return $this->assets->get($handle);
208
+		}
209
+		return parent::addJavascript(
210
+			$handle,
211
+			$this->registry->getJsUrl(
212
+				$this->domain->assetNamespace(),
213
+				$handle
214
+			),
215
+			$this->addDefaultBlockScriptDependencies($dependencies)
216
+		)
217
+		->setRequiresTranslation();
218
+	}
219
+
220
+
221
+	/**
222
+	 * @param        $handle
223
+	 * @param array  $dependencies
224
+	 * @since $VID:$
225
+	 * @return StylesheetAsset
226
+	 * @throws InvalidDataTypeException
227
+	 * @throws InvalidEntityException
228
+	 * @throws DuplicateCollectionIdentifierException
229
+	 */
230
+	public function addStyle($handle, array $dependencies = array())
231
+	{
232
+		if ($this->assets->has($handle)) {
233
+			return $this->assets->get($handle);
234
+		}
235
+		return parent::addStylesheet(
236
+			$handle,
237
+			$this->registry->getCssUrl(
238
+				$this->domain->assetNamespace(),
239
+				$handle
240
+			),
241
+			$dependencies
242
+		);
243
+	}
244
+
245
+
246
+	/**
247
+	 * @param array $dependencies
248
+	 * @return array
249
+	 */
250
+	protected function addDefaultBlockScriptDependencies(array $dependencies)
251
+	{
252
+		$dependencies += array(
253
+				CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
254
+				'wp-blocks',    // Provides useful functions and components for extending the editor
255
+				'wp-i18n',      // Provides localization functions
256
+				'wp-element',   // Provides React.Component
257
+				'wp-components' // Provides many prebuilt components and controls
258
+			);
259
+		return $dependencies;
260
+	}
261
+
262
+
263
+	/**
264
+	 * @param string $handle
265
+	 * @since $VID:$
266
+	 * @return mixed|null
267
+	 */
268
+	public function getAsset($handle)
269
+	{
270
+		if ($this->assets->has($handle)) {
271
+			return $this->assets->get($handle);
272
+		}
273
+		return null;
274
+	}
275
+
276
+
277
+	/**
278
+	 * @return JavascriptAsset|null
279
+	 */
280
+	public function getEditorScript()
281
+	{
282
+		return $this->getAsset($this->editor_script_handle);
283
+	}
284
+
285
+
286
+	/**
287
+	 * @return StylesheetAsset|null
288
+	 */
289
+	public function getEditorStyle()
290
+	{
291
+		return $this->getAsset($this->editor_style_handle);
292
+	}
293
+
294
+
295
+	/**
296
+	 * @return JavascriptAsset|null
297
+	 */
298
+	public function getScript()
299
+	{
300
+		return $this->getAsset($this->script_handle);
301
+	}
302
+
303
+
304
+	/**
305
+	 * @return StylesheetAsset|null
306
+	 */
307
+	public function getStyle()
308
+	{
309
+		return $this->getAsset($this->style_handle);
310
+	}
311
+
312
+
313
+	/**
314
+	 * @return  void
315
+	 */
316
+	public function enqueueAssets()
317
+	{
318
+		$assets = array(
319
+			$this->getEditorScript(),
320
+			$this->getEditorStyle(),
321
+			$this->getScript(),
322
+			$this->getStyle(),
323
+		);
324
+		foreach ($assets as $asset) {
325
+			if ($asset instanceof BrowserAsset && $asset->isRegistered()) {
326
+				$asset->enqueueAsset();
327
+			}
328
+		}
329
+	}
330 330
 
331 331
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 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->has($handle)){
155
+        if ($this->assets->has($handle)) {
156 156
             return $this->assets->get($handle);
157 157
         }
158 158
         return parent::addJavascript(
@@ -251,9 +251,9 @@  discard block
 block discarded – undo
251 251
     {
252 252
         $dependencies += array(
253 253
                 CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
254
-                'wp-blocks',    // Provides useful functions and components for extending the editor
255
-                'wp-i18n',      // Provides localization functions
256
-                'wp-element',   // Provides React.Component
254
+                'wp-blocks', // Provides useful functions and components for extending the editor
255
+                'wp-i18n', // Provides localization functions
256
+                'wp-element', // Provides React.Component
257 257
                 'wp-components' // Provides many prebuilt components and controls
258 258
             );
259 259
         return $dependencies;
Please login to merge, or discard this patch.