@@ -21,161 +21,161 @@ |
||
21 | 21 | abstract class AssetManager implements AssetManagerInterface |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * @var AssetCollection $assets |
|
26 | - */ |
|
27 | - protected $assets; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var DomainInterface |
|
31 | - */ |
|
32 | - protected $domain; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var Registry $registry |
|
36 | - */ |
|
37 | - protected $registry; |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * AssetRegister constructor. |
|
42 | - * |
|
43 | - * @param DomainInterface $domain |
|
44 | - * @param AssetCollection $assets |
|
45 | - * @param Registry $registry |
|
46 | - */ |
|
47 | - public function __construct(DomainInterface $domain, AssetCollection $assets, Registry $registry) |
|
48 | - { |
|
49 | - $this->domain = $domain; |
|
50 | - $this->assets = $assets; |
|
51 | - $this->registry = $registry; |
|
52 | - add_action('wp_enqueue_scripts', array($this, 'addManifestFile'), 0); |
|
53 | - add_action('admin_enqueue_scripts', array($this, 'addManifestFile'), 0); |
|
54 | - add_action('wp_enqueue_scripts', array($this, 'addAssets'), 2); |
|
55 | - add_action('admin_enqueue_scripts', array($this, 'addAssets'), 2); |
|
56 | - } |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * @return void |
|
61 | - * @throws DuplicateCollectionIdentifierException |
|
62 | - * @throws InvalidDataTypeException |
|
63 | - * @throws InvalidEntityException |
|
64 | - * @since 4.9.62.p |
|
65 | - */ |
|
66 | - public function addManifestFile() |
|
67 | - { |
|
68 | - // if a manifest file has already been added for this domain, then just return that one |
|
69 | - if ($this->assets->has($this->domain->assetNamespace())) { |
|
70 | - return; |
|
71 | - } |
|
72 | - $asset = new ManifestFile($this->domain); |
|
73 | - $this->assets->add($asset, $this->domain->assetNamespace()); |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * @return ManifestFile[] |
|
79 | - * @since 4.9.62.p |
|
80 | - */ |
|
81 | - public function getManifestFile() |
|
82 | - { |
|
83 | - return $this->assets->getManifestFiles(); |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * @param string $handle |
|
89 | - * @param string $source |
|
90 | - * @param array $dependencies |
|
91 | - * @param bool $load_in_footer |
|
92 | - * @return JavascriptAsset |
|
93 | - * @throws DuplicateCollectionIdentifierException |
|
94 | - * @throws InvalidDataTypeException |
|
95 | - * @throws InvalidEntityException |
|
96 | - * @since 4.9.62.p |
|
97 | - */ |
|
98 | - public function addJavascript( |
|
99 | - $handle, |
|
100 | - $source, |
|
101 | - array $dependencies = array(), |
|
102 | - $load_in_footer = true |
|
103 | - ) { |
|
104 | - $asset = new JavascriptAsset( |
|
105 | - $handle, |
|
106 | - $source, |
|
107 | - $dependencies, |
|
108 | - $load_in_footer, |
|
109 | - $this->domain |
|
110 | - ); |
|
111 | - $this->assets->add($asset, $handle); |
|
112 | - return $asset; |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * @return JavascriptAsset[] |
|
118 | - * @since 4.9.62.p |
|
119 | - */ |
|
120 | - public function getJavascriptAssets() |
|
121 | - { |
|
122 | - return $this->assets->getJavascriptAssets(); |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * @param string $handle |
|
128 | - * @param string $source |
|
129 | - * @param array $dependencies |
|
130 | - * @param string $media |
|
131 | - * @return StylesheetAsset |
|
132 | - * @throws DuplicateCollectionIdentifierException |
|
133 | - * @throws InvalidDataTypeException |
|
134 | - * @throws InvalidEntityException |
|
135 | - * @since 4.9.62.p |
|
136 | - */ |
|
137 | - public function addStylesheet( |
|
138 | - $handle, |
|
139 | - $source, |
|
140 | - array $dependencies = array(), |
|
141 | - $media = 'all' |
|
142 | - ) { |
|
143 | - $asset = new StylesheetAsset( |
|
144 | - $handle, |
|
145 | - $source, |
|
146 | - $dependencies, |
|
147 | - $this->domain, |
|
148 | - $media |
|
149 | - ); |
|
150 | - $this->assets->add($asset, $handle); |
|
151 | - return $asset; |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * @return StylesheetAsset[] |
|
157 | - * @since 4.9.62.p |
|
158 | - */ |
|
159 | - public function getStylesheetAssets() |
|
160 | - { |
|
161 | - return $this->assets->getStylesheetAssets(); |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * @param string $handle |
|
167 | - * @return bool |
|
168 | - * @since 4.9.62.p |
|
169 | - */ |
|
170 | - public function enqueueAsset($handle) |
|
171 | - { |
|
172 | - if ($this->assets->has($handle)) { |
|
173 | - $asset = $this->assets->get($handle); |
|
174 | - if ($asset->isRegistered()) { |
|
175 | - $asset->enqueueAsset(); |
|
176 | - return true; |
|
177 | - } |
|
178 | - } |
|
179 | - return false; |
|
180 | - } |
|
24 | + /** |
|
25 | + * @var AssetCollection $assets |
|
26 | + */ |
|
27 | + protected $assets; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var DomainInterface |
|
31 | + */ |
|
32 | + protected $domain; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var Registry $registry |
|
36 | + */ |
|
37 | + protected $registry; |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * AssetRegister constructor. |
|
42 | + * |
|
43 | + * @param DomainInterface $domain |
|
44 | + * @param AssetCollection $assets |
|
45 | + * @param Registry $registry |
|
46 | + */ |
|
47 | + public function __construct(DomainInterface $domain, AssetCollection $assets, Registry $registry) |
|
48 | + { |
|
49 | + $this->domain = $domain; |
|
50 | + $this->assets = $assets; |
|
51 | + $this->registry = $registry; |
|
52 | + add_action('wp_enqueue_scripts', array($this, 'addManifestFile'), 0); |
|
53 | + add_action('admin_enqueue_scripts', array($this, 'addManifestFile'), 0); |
|
54 | + add_action('wp_enqueue_scripts', array($this, 'addAssets'), 2); |
|
55 | + add_action('admin_enqueue_scripts', array($this, 'addAssets'), 2); |
|
56 | + } |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * @return void |
|
61 | + * @throws DuplicateCollectionIdentifierException |
|
62 | + * @throws InvalidDataTypeException |
|
63 | + * @throws InvalidEntityException |
|
64 | + * @since 4.9.62.p |
|
65 | + */ |
|
66 | + public function addManifestFile() |
|
67 | + { |
|
68 | + // if a manifest file has already been added for this domain, then just return that one |
|
69 | + if ($this->assets->has($this->domain->assetNamespace())) { |
|
70 | + return; |
|
71 | + } |
|
72 | + $asset = new ManifestFile($this->domain); |
|
73 | + $this->assets->add($asset, $this->domain->assetNamespace()); |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * @return ManifestFile[] |
|
79 | + * @since 4.9.62.p |
|
80 | + */ |
|
81 | + public function getManifestFile() |
|
82 | + { |
|
83 | + return $this->assets->getManifestFiles(); |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * @param string $handle |
|
89 | + * @param string $source |
|
90 | + * @param array $dependencies |
|
91 | + * @param bool $load_in_footer |
|
92 | + * @return JavascriptAsset |
|
93 | + * @throws DuplicateCollectionIdentifierException |
|
94 | + * @throws InvalidDataTypeException |
|
95 | + * @throws InvalidEntityException |
|
96 | + * @since 4.9.62.p |
|
97 | + */ |
|
98 | + public function addJavascript( |
|
99 | + $handle, |
|
100 | + $source, |
|
101 | + array $dependencies = array(), |
|
102 | + $load_in_footer = true |
|
103 | + ) { |
|
104 | + $asset = new JavascriptAsset( |
|
105 | + $handle, |
|
106 | + $source, |
|
107 | + $dependencies, |
|
108 | + $load_in_footer, |
|
109 | + $this->domain |
|
110 | + ); |
|
111 | + $this->assets->add($asset, $handle); |
|
112 | + return $asset; |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * @return JavascriptAsset[] |
|
118 | + * @since 4.9.62.p |
|
119 | + */ |
|
120 | + public function getJavascriptAssets() |
|
121 | + { |
|
122 | + return $this->assets->getJavascriptAssets(); |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * @param string $handle |
|
128 | + * @param string $source |
|
129 | + * @param array $dependencies |
|
130 | + * @param string $media |
|
131 | + * @return StylesheetAsset |
|
132 | + * @throws DuplicateCollectionIdentifierException |
|
133 | + * @throws InvalidDataTypeException |
|
134 | + * @throws InvalidEntityException |
|
135 | + * @since 4.9.62.p |
|
136 | + */ |
|
137 | + public function addStylesheet( |
|
138 | + $handle, |
|
139 | + $source, |
|
140 | + array $dependencies = array(), |
|
141 | + $media = 'all' |
|
142 | + ) { |
|
143 | + $asset = new StylesheetAsset( |
|
144 | + $handle, |
|
145 | + $source, |
|
146 | + $dependencies, |
|
147 | + $this->domain, |
|
148 | + $media |
|
149 | + ); |
|
150 | + $this->assets->add($asset, $handle); |
|
151 | + return $asset; |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * @return StylesheetAsset[] |
|
157 | + * @since 4.9.62.p |
|
158 | + */ |
|
159 | + public function getStylesheetAssets() |
|
160 | + { |
|
161 | + return $this->assets->getStylesheetAssets(); |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * @param string $handle |
|
167 | + * @return bool |
|
168 | + * @since 4.9.62.p |
|
169 | + */ |
|
170 | + public function enqueueAsset($handle) |
|
171 | + { |
|
172 | + if ($this->assets->has($handle)) { |
|
173 | + $asset = $this->assets->get($handle); |
|
174 | + if ($asset->isRegistered()) { |
|
175 | + $asset->enqueueAsset(); |
|
176 | + return true; |
|
177 | + } |
|
178 | + } |
|
179 | + return false; |
|
180 | + } |
|
181 | 181 | } |
@@ -17,154 +17,154 @@ |
||
17 | 17 | class CachingLoader extends CachingLoaderDecorator |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var string $identifier |
|
22 | - */ |
|
23 | - protected $identifier; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var CollectionInterface $cache |
|
27 | - */ |
|
28 | - protected $cache; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var ObjectIdentifier |
|
32 | - */ |
|
33 | - private $object_identifier; |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * CachingLoader constructor. |
|
38 | - * |
|
39 | - * @param LoaderDecoratorInterface $loader |
|
40 | - * @param CollectionInterface $cache |
|
41 | - * @param ObjectIdentifier $object_identifier |
|
42 | - * @param string $identifier |
|
43 | - * @throws InvalidDataTypeException |
|
44 | - */ |
|
45 | - public function __construct( |
|
46 | - LoaderDecoratorInterface $loader, |
|
47 | - CollectionInterface $cache, |
|
48 | - ObjectIdentifier $object_identifier, |
|
49 | - $identifier = '' |
|
50 | - ) { |
|
51 | - parent::__construct($loader); |
|
52 | - $this->cache = $cache; |
|
53 | - $this->object_identifier = $object_identifier; |
|
54 | - $this->setIdentifier($identifier); |
|
55 | - if ($this->identifier !== '') { |
|
56 | - // to only clear this cache, and assuming an identifier has been set, simply do the following: |
|
57 | - // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER'); |
|
58 | - // where "IDENTIFIER" = the string that was set during construction |
|
59 | - add_action( |
|
60 | - "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}", |
|
61 | - array($this, 'reset') |
|
62 | - ); |
|
63 | - } |
|
64 | - // to clear ALL caches, simply do the following: |
|
65 | - // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache'); |
|
66 | - add_action( |
|
67 | - 'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache', |
|
68 | - array($this, 'reset') |
|
69 | - ); |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * @return string |
|
75 | - */ |
|
76 | - public function identifier() |
|
77 | - { |
|
78 | - return $this->identifier; |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @param string $identifier |
|
84 | - * @throws InvalidDataTypeException |
|
85 | - */ |
|
86 | - private function setIdentifier($identifier) |
|
87 | - { |
|
88 | - if (! is_string($identifier)) { |
|
89 | - throw new InvalidDataTypeException('$identifier', $identifier, 'string'); |
|
90 | - } |
|
91 | - $this->identifier = $identifier; |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * @param FullyQualifiedName|string $fqcn |
|
97 | - * @param mixed $object |
|
98 | - * @return bool |
|
99 | - * @throws InvalidArgumentException |
|
100 | - */ |
|
101 | - public function share($fqcn, $object) |
|
102 | - { |
|
103 | - if ($object instanceof $fqcn) { |
|
104 | - return $this->cache->add($object, md5($fqcn)); |
|
105 | - } |
|
106 | - throw new InvalidArgumentException( |
|
107 | - sprintf( |
|
108 | - esc_html__( |
|
109 | - 'The supplied class name "%1$s" must match the class of the supplied object.', |
|
110 | - 'event_espresso' |
|
111 | - ), |
|
112 | - $fqcn |
|
113 | - ) |
|
114 | - ); |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * @param FullyQualifiedName|string $fqcn |
|
120 | - * @param array $arguments |
|
121 | - * @param bool $shared |
|
122 | - * @param array $interfaces |
|
123 | - * @return mixed |
|
124 | - */ |
|
125 | - public function load($fqcn, $arguments = array(), $shared = true, array $interfaces = array()) |
|
126 | - { |
|
127 | - $fqcn = ltrim($fqcn, '\\'); |
|
128 | - // caching can be turned off via the following code: |
|
129 | - // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
|
130 | - if (apply_filters( |
|
131 | - 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
|
132 | - false, |
|
133 | - $this |
|
134 | - )) { |
|
135 | - // even though $shared might be true, caching could be bypassed for whatever reason, |
|
136 | - // so we don't want the core loader to cache anything, therefore caching is turned off |
|
137 | - return $this->loader->load($fqcn, $arguments, false); |
|
138 | - } |
|
139 | - $object_identifier = $this->object_identifier->getIdentifier($fqcn, $arguments); |
|
140 | - if ($this->cache->has($object_identifier)) { |
|
141 | - return $this->cache->get($object_identifier); |
|
142 | - } |
|
143 | - $object = $this->loader->load($fqcn, $arguments, $shared); |
|
144 | - if ($object instanceof $fqcn) { |
|
145 | - $this->cache->add($object, $object_identifier); |
|
146 | - } |
|
147 | - return $object; |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * empties cache and calls reset() on loader if method exists |
|
153 | - */ |
|
154 | - public function reset() |
|
155 | - { |
|
156 | - $this->clearCache(); |
|
157 | - $this->loader->reset(); |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * unsets and detaches ALL objects from the cache |
|
163 | - * |
|
164 | - * @since 4.9.62.p |
|
165 | - */ |
|
166 | - public function clearCache() |
|
167 | - { |
|
168 | - $this->cache->trashAndDetachAll(); |
|
169 | - } |
|
20 | + /** |
|
21 | + * @var string $identifier |
|
22 | + */ |
|
23 | + protected $identifier; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var CollectionInterface $cache |
|
27 | + */ |
|
28 | + protected $cache; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var ObjectIdentifier |
|
32 | + */ |
|
33 | + private $object_identifier; |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * CachingLoader constructor. |
|
38 | + * |
|
39 | + * @param LoaderDecoratorInterface $loader |
|
40 | + * @param CollectionInterface $cache |
|
41 | + * @param ObjectIdentifier $object_identifier |
|
42 | + * @param string $identifier |
|
43 | + * @throws InvalidDataTypeException |
|
44 | + */ |
|
45 | + public function __construct( |
|
46 | + LoaderDecoratorInterface $loader, |
|
47 | + CollectionInterface $cache, |
|
48 | + ObjectIdentifier $object_identifier, |
|
49 | + $identifier = '' |
|
50 | + ) { |
|
51 | + parent::__construct($loader); |
|
52 | + $this->cache = $cache; |
|
53 | + $this->object_identifier = $object_identifier; |
|
54 | + $this->setIdentifier($identifier); |
|
55 | + if ($this->identifier !== '') { |
|
56 | + // to only clear this cache, and assuming an identifier has been set, simply do the following: |
|
57 | + // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER'); |
|
58 | + // where "IDENTIFIER" = the string that was set during construction |
|
59 | + add_action( |
|
60 | + "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}", |
|
61 | + array($this, 'reset') |
|
62 | + ); |
|
63 | + } |
|
64 | + // to clear ALL caches, simply do the following: |
|
65 | + // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache'); |
|
66 | + add_action( |
|
67 | + 'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache', |
|
68 | + array($this, 'reset') |
|
69 | + ); |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * @return string |
|
75 | + */ |
|
76 | + public function identifier() |
|
77 | + { |
|
78 | + return $this->identifier; |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @param string $identifier |
|
84 | + * @throws InvalidDataTypeException |
|
85 | + */ |
|
86 | + private function setIdentifier($identifier) |
|
87 | + { |
|
88 | + if (! is_string($identifier)) { |
|
89 | + throw new InvalidDataTypeException('$identifier', $identifier, 'string'); |
|
90 | + } |
|
91 | + $this->identifier = $identifier; |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * @param FullyQualifiedName|string $fqcn |
|
97 | + * @param mixed $object |
|
98 | + * @return bool |
|
99 | + * @throws InvalidArgumentException |
|
100 | + */ |
|
101 | + public function share($fqcn, $object) |
|
102 | + { |
|
103 | + if ($object instanceof $fqcn) { |
|
104 | + return $this->cache->add($object, md5($fqcn)); |
|
105 | + } |
|
106 | + throw new InvalidArgumentException( |
|
107 | + sprintf( |
|
108 | + esc_html__( |
|
109 | + 'The supplied class name "%1$s" must match the class of the supplied object.', |
|
110 | + 'event_espresso' |
|
111 | + ), |
|
112 | + $fqcn |
|
113 | + ) |
|
114 | + ); |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * @param FullyQualifiedName|string $fqcn |
|
120 | + * @param array $arguments |
|
121 | + * @param bool $shared |
|
122 | + * @param array $interfaces |
|
123 | + * @return mixed |
|
124 | + */ |
|
125 | + public function load($fqcn, $arguments = array(), $shared = true, array $interfaces = array()) |
|
126 | + { |
|
127 | + $fqcn = ltrim($fqcn, '\\'); |
|
128 | + // caching can be turned off via the following code: |
|
129 | + // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
|
130 | + if (apply_filters( |
|
131 | + 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
|
132 | + false, |
|
133 | + $this |
|
134 | + )) { |
|
135 | + // even though $shared might be true, caching could be bypassed for whatever reason, |
|
136 | + // so we don't want the core loader to cache anything, therefore caching is turned off |
|
137 | + return $this->loader->load($fqcn, $arguments, false); |
|
138 | + } |
|
139 | + $object_identifier = $this->object_identifier->getIdentifier($fqcn, $arguments); |
|
140 | + if ($this->cache->has($object_identifier)) { |
|
141 | + return $this->cache->get($object_identifier); |
|
142 | + } |
|
143 | + $object = $this->loader->load($fqcn, $arguments, $shared); |
|
144 | + if ($object instanceof $fqcn) { |
|
145 | + $this->cache->add($object, $object_identifier); |
|
146 | + } |
|
147 | + return $object; |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * empties cache and calls reset() on loader if method exists |
|
153 | + */ |
|
154 | + public function reset() |
|
155 | + { |
|
156 | + $this->clearCache(); |
|
157 | + $this->loader->reset(); |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * unsets and detaches ALL objects from the cache |
|
163 | + * |
|
164 | + * @since 4.9.62.p |
|
165 | + */ |
|
166 | + public function clearCache() |
|
167 | + { |
|
168 | + $this->cache->trashAndDetachAll(); |
|
169 | + } |
|
170 | 170 | } |
@@ -16,60 +16,60 @@ |
||
16 | 16 | class StylesheetAsset extends BrowserAsset |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @var string $media |
|
21 | - */ |
|
22 | - private $media; |
|
19 | + /** |
|
20 | + * @var string $media |
|
21 | + */ |
|
22 | + private $media; |
|
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * CssFile constructor. |
|
27 | - * |
|
28 | - * @param $handle |
|
29 | - * @param string $source |
|
30 | - * @param array $dependencies |
|
31 | - * @param DomainInterface $domain |
|
32 | - * @param $media |
|
33 | - * @throws InvalidDataTypeException |
|
34 | - */ |
|
35 | - public function __construct($handle, $source, array $dependencies, DomainInterface $domain, $media = 'all') |
|
36 | - { |
|
37 | - parent::__construct(Asset::TYPE_CSS, $handle, $source, $dependencies, $domain); |
|
38 | - $this->setMedia($media); |
|
39 | - } |
|
25 | + /** |
|
26 | + * CssFile constructor. |
|
27 | + * |
|
28 | + * @param $handle |
|
29 | + * @param string $source |
|
30 | + * @param array $dependencies |
|
31 | + * @param DomainInterface $domain |
|
32 | + * @param $media |
|
33 | + * @throws InvalidDataTypeException |
|
34 | + */ |
|
35 | + public function __construct($handle, $source, array $dependencies, DomainInterface $domain, $media = 'all') |
|
36 | + { |
|
37 | + parent::__construct(Asset::TYPE_CSS, $handle, $source, $dependencies, $domain); |
|
38 | + $this->setMedia($media); |
|
39 | + } |
|
40 | 40 | |
41 | 41 | |
42 | - /** |
|
43 | - * @return string |
|
44 | - */ |
|
45 | - public function media() |
|
46 | - { |
|
47 | - return $this->media; |
|
48 | - } |
|
42 | + /** |
|
43 | + * @return string |
|
44 | + */ |
|
45 | + public function media() |
|
46 | + { |
|
47 | + return $this->media; |
|
48 | + } |
|
49 | 49 | |
50 | 50 | |
51 | - /** |
|
52 | - * @param string $media |
|
53 | - * @throws InvalidDataTypeException |
|
54 | - */ |
|
55 | - private function setMedia($media) |
|
56 | - { |
|
57 | - if (! is_string($media)) { |
|
58 | - throw new InvalidDataTypeException( |
|
59 | - '$media', |
|
60 | - $media, |
|
61 | - 'string' |
|
62 | - ); |
|
63 | - } |
|
64 | - $this->media = $media; |
|
65 | - } |
|
51 | + /** |
|
52 | + * @param string $media |
|
53 | + * @throws InvalidDataTypeException |
|
54 | + */ |
|
55 | + private function setMedia($media) |
|
56 | + { |
|
57 | + if (! is_string($media)) { |
|
58 | + throw new InvalidDataTypeException( |
|
59 | + '$media', |
|
60 | + $media, |
|
61 | + 'string' |
|
62 | + ); |
|
63 | + } |
|
64 | + $this->media = $media; |
|
65 | + } |
|
66 | 66 | |
67 | 67 | |
68 | - /** |
|
69 | - * @since 4.9.62.p |
|
70 | - */ |
|
71 | - public function enqueueAsset() |
|
72 | - { |
|
73 | - wp_enqueue_style($this->handle()); |
|
74 | - } |
|
68 | + /** |
|
69 | + * @since 4.9.62.p |
|
70 | + */ |
|
71 | + public function enqueueAsset() |
|
72 | + { |
|
73 | + wp_enqueue_style($this->handle()); |
|
74 | + } |
|
75 | 75 | } |
@@ -16,136 +16,136 @@ |
||
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 | } |
@@ -17,97 +17,97 @@ |
||
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 | } |
@@ -19,303 +19,303 @@ discard block |
||
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 |
||
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 | } |
@@ -14,238 +14,238 @@ |
||
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 |
@@ -75,9 +75,9 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
@@ -21,86 +21,86 @@ |
||
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 | } |
@@ -75,7 +75,7 @@ discard block |
||
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 |
||
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 | } |
@@ -23,559 +23,559 @@ |
||
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 | - * Holds the manifest data obtained from registered manifest files. |
|
55 | - * Manifests are maps of asset chunk name to actual built asset file names. |
|
56 | - * Shape of this array is: |
|
57 | - * array( |
|
58 | - * 'some_namespace_slug' => array( |
|
59 | - * 'some_chunk_name' => array( |
|
60 | - * 'js' => 'filename.js' |
|
61 | - * 'css' => 'filename.js' |
|
62 | - * ), |
|
63 | - * 'url_base' => 'https://baseurl.com/to/assets |
|
64 | - * ) |
|
65 | - * ) |
|
66 | - * |
|
67 | - * @var array |
|
68 | - */ |
|
69 | - private $manifest_data = array(); |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * Registry constructor. |
|
74 | - * Hooking into WP actions for script registry. |
|
75 | - * |
|
76 | - * @param AssetCollection $assets |
|
77 | - * @param I18nRegistry $i18n_registry |
|
78 | - */ |
|
79 | - public function __construct(AssetCollection $assets, I18nRegistry $i18n_registry) |
|
80 | - { |
|
81 | - $this->assets = $assets; |
|
82 | - $this->i18n_registry = $i18n_registry; |
|
83 | - add_action('wp_enqueue_scripts', array($this, 'registerManifestFiles'), 1); |
|
84 | - add_action('admin_enqueue_scripts', array($this, 'registerManifestFiles'), 1); |
|
85 | - add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3); |
|
86 | - add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3); |
|
87 | - add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 4); |
|
88 | - add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 4); |
|
89 | - add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
90 | - add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n |
|
96 | - * translation handling. |
|
97 | - * |
|
98 | - * @return I18nRegistry |
|
99 | - */ |
|
100 | - public function getI18nRegistry() |
|
101 | - { |
|
102 | - return $this->i18n_registry; |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * Callback for the wp_enqueue_scripts actions used to register assets. |
|
108 | - * |
|
109 | - * @since 4.9.62.p |
|
110 | - * @throws Exception |
|
111 | - */ |
|
112 | - public function registerScriptsAndStyles() |
|
113 | - { |
|
114 | - try { |
|
115 | - $this->registerScripts($this->assets->getJavascriptAssets()); |
|
116 | - $this->registerStyles($this->assets->getStylesheetAssets()); |
|
117 | - } catch (Exception $exception) { |
|
118 | - new ExceptionStackTraceDisplay($exception); |
|
119 | - } |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * Registers JS assets with WP core |
|
125 | - * |
|
126 | - * @since 4.9.62.p |
|
127 | - * @param JavascriptAsset[] $scripts |
|
128 | - * @throws AssetRegistrationException |
|
129 | - * @throws InvalidDataTypeException |
|
130 | - */ |
|
131 | - public function registerScripts(array $scripts) |
|
132 | - { |
|
133 | - foreach ($scripts as $script) { |
|
134 | - // skip to next script if this has already been done |
|
135 | - if ($script->isRegistered()) { |
|
136 | - continue; |
|
137 | - } |
|
138 | - do_action( |
|
139 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script', |
|
140 | - $script |
|
141 | - ); |
|
142 | - $registered = wp_register_script( |
|
143 | - $script->handle(), |
|
144 | - $script->source(), |
|
145 | - $script->dependencies(), |
|
146 | - $script->version(), |
|
147 | - $script->loadInFooter() |
|
148 | - ); |
|
149 | - if (! $registered && defined('EE_DEBUG') && EE_DEBUG) { |
|
150 | - throw new AssetRegistrationException($script->handle()); |
|
151 | - } |
|
152 | - $script->setRegistered($registered); |
|
153 | - if ($script->requiresTranslation()) { |
|
154 | - $this->registerTranslation($script->handle()); |
|
155 | - } |
|
156 | - do_action( |
|
157 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script', |
|
158 | - $script |
|
159 | - ); |
|
160 | - } |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - /** |
|
165 | - * Registers CSS assets with WP core |
|
166 | - * |
|
167 | - * @since 4.9.62.p |
|
168 | - * @param StylesheetAsset[] $styles |
|
169 | - * @throws InvalidDataTypeException |
|
170 | - */ |
|
171 | - public function registerStyles(array $styles) |
|
172 | - { |
|
173 | - foreach ($styles as $style) { |
|
174 | - // skip to next style if this has already been done |
|
175 | - if ($style->isRegistered()) { |
|
176 | - continue; |
|
177 | - } |
|
178 | - do_action( |
|
179 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style', |
|
180 | - $style |
|
181 | - ); |
|
182 | - wp_enqueue_style( |
|
183 | - $style->handle(), |
|
184 | - $style->source(), |
|
185 | - $style->dependencies(), |
|
186 | - $style->version(), |
|
187 | - $style->media() |
|
188 | - ); |
|
189 | - $style->setRegistered(); |
|
190 | - do_action( |
|
191 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style', |
|
192 | - $style |
|
193 | - ); |
|
194 | - } |
|
195 | - } |
|
196 | - |
|
197 | - |
|
198 | - /** |
|
199 | - * Call back for the script print in frontend and backend. |
|
200 | - * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point. |
|
201 | - * |
|
202 | - * @since 4.9.31.rc.015 |
|
203 | - */ |
|
204 | - public function enqueueData() |
|
205 | - { |
|
206 | - $this->removeAlreadyRegisteredDataForScriptHandles(); |
|
207 | - wp_add_inline_script( |
|
208 | - 'eejs-core', |
|
209 | - 'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)), |
|
210 | - 'before' |
|
211 | - ); |
|
212 | - $scripts = $this->assets->getJavascriptAssetsWithData(); |
|
213 | - foreach ($scripts as $script) { |
|
214 | - $this->addRegisteredScriptHandlesWithData($script->handle()); |
|
215 | - if ($script->hasInlineDataCallback()) { |
|
216 | - $localize = $script->inlineDataCallback(); |
|
217 | - $localize(); |
|
218 | - } |
|
219 | - } |
|
220 | - } |
|
221 | - |
|
222 | - |
|
223 | - /** |
|
224 | - * Used to add data to eejs.data object. |
|
225 | - * Note: Overriding existing data is not allowed. |
|
226 | - * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
227 | - * If the data you add is something like this: |
|
228 | - * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
229 | - * It will be exposed in the page source as: |
|
230 | - * eejs.data.my_plugin_data.foo == gar |
|
231 | - * |
|
232 | - * @param string $key Key used to access your data |
|
233 | - * @param string|array $value Value to attach to key |
|
234 | - * @throws InvalidArgumentException |
|
235 | - */ |
|
236 | - public function addData($key, $value) |
|
237 | - { |
|
238 | - if ($this->verifyDataNotExisting($key)) { |
|
239 | - $this->jsdata[ $key ] = $value; |
|
240 | - } |
|
241 | - } |
|
242 | - |
|
243 | - |
|
244 | - /** |
|
245 | - * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
246 | - * elements in an array. |
|
247 | - * When you use this method, the value you include will be appended to the end of an array on $key. |
|
248 | - * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript |
|
249 | - * object like this, eejs.data.test = [ my_data, |
|
250 | - * ] |
|
251 | - * If there has already been a scalar value attached to the data object given key, then |
|
252 | - * this will throw an exception. |
|
253 | - * |
|
254 | - * @param string $key Key to attach data to. |
|
255 | - * @param string|array $value Value being registered. |
|
256 | - * @throws InvalidArgumentException |
|
257 | - */ |
|
258 | - public function pushData($key, $value) |
|
259 | - { |
|
260 | - if (isset($this->jsdata[ $key ]) |
|
261 | - && ! is_array($this->jsdata[ $key ]) |
|
262 | - ) { |
|
263 | - throw new InvalidArgumentException( |
|
264 | - sprintf( |
|
265 | - __( |
|
266 | - '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 | + * Holds the manifest data obtained from registered manifest files. |
|
55 | + * Manifests are maps of asset chunk name to actual built asset file names. |
|
56 | + * Shape of this array is: |
|
57 | + * array( |
|
58 | + * 'some_namespace_slug' => array( |
|
59 | + * 'some_chunk_name' => array( |
|
60 | + * 'js' => 'filename.js' |
|
61 | + * 'css' => 'filename.js' |
|
62 | + * ), |
|
63 | + * 'url_base' => 'https://baseurl.com/to/assets |
|
64 | + * ) |
|
65 | + * ) |
|
66 | + * |
|
67 | + * @var array |
|
68 | + */ |
|
69 | + private $manifest_data = array(); |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * Registry constructor. |
|
74 | + * Hooking into WP actions for script registry. |
|
75 | + * |
|
76 | + * @param AssetCollection $assets |
|
77 | + * @param I18nRegistry $i18n_registry |
|
78 | + */ |
|
79 | + public function __construct(AssetCollection $assets, I18nRegistry $i18n_registry) |
|
80 | + { |
|
81 | + $this->assets = $assets; |
|
82 | + $this->i18n_registry = $i18n_registry; |
|
83 | + add_action('wp_enqueue_scripts', array($this, 'registerManifestFiles'), 1); |
|
84 | + add_action('admin_enqueue_scripts', array($this, 'registerManifestFiles'), 1); |
|
85 | + add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3); |
|
86 | + add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3); |
|
87 | + add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 4); |
|
88 | + add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 4); |
|
89 | + add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
90 | + add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n |
|
96 | + * translation handling. |
|
97 | + * |
|
98 | + * @return I18nRegistry |
|
99 | + */ |
|
100 | + public function getI18nRegistry() |
|
101 | + { |
|
102 | + return $this->i18n_registry; |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * Callback for the wp_enqueue_scripts actions used to register assets. |
|
108 | + * |
|
109 | + * @since 4.9.62.p |
|
110 | + * @throws Exception |
|
111 | + */ |
|
112 | + public function registerScriptsAndStyles() |
|
113 | + { |
|
114 | + try { |
|
115 | + $this->registerScripts($this->assets->getJavascriptAssets()); |
|
116 | + $this->registerStyles($this->assets->getStylesheetAssets()); |
|
117 | + } catch (Exception $exception) { |
|
118 | + new ExceptionStackTraceDisplay($exception); |
|
119 | + } |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * Registers JS assets with WP core |
|
125 | + * |
|
126 | + * @since 4.9.62.p |
|
127 | + * @param JavascriptAsset[] $scripts |
|
128 | + * @throws AssetRegistrationException |
|
129 | + * @throws InvalidDataTypeException |
|
130 | + */ |
|
131 | + public function registerScripts(array $scripts) |
|
132 | + { |
|
133 | + foreach ($scripts as $script) { |
|
134 | + // skip to next script if this has already been done |
|
135 | + if ($script->isRegistered()) { |
|
136 | + continue; |
|
137 | + } |
|
138 | + do_action( |
|
139 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script', |
|
140 | + $script |
|
141 | + ); |
|
142 | + $registered = wp_register_script( |
|
143 | + $script->handle(), |
|
144 | + $script->source(), |
|
145 | + $script->dependencies(), |
|
146 | + $script->version(), |
|
147 | + $script->loadInFooter() |
|
148 | + ); |
|
149 | + if (! $registered && defined('EE_DEBUG') && EE_DEBUG) { |
|
150 | + throw new AssetRegistrationException($script->handle()); |
|
151 | + } |
|
152 | + $script->setRegistered($registered); |
|
153 | + if ($script->requiresTranslation()) { |
|
154 | + $this->registerTranslation($script->handle()); |
|
155 | + } |
|
156 | + do_action( |
|
157 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script', |
|
158 | + $script |
|
159 | + ); |
|
160 | + } |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + /** |
|
165 | + * Registers CSS assets with WP core |
|
166 | + * |
|
167 | + * @since 4.9.62.p |
|
168 | + * @param StylesheetAsset[] $styles |
|
169 | + * @throws InvalidDataTypeException |
|
170 | + */ |
|
171 | + public function registerStyles(array $styles) |
|
172 | + { |
|
173 | + foreach ($styles as $style) { |
|
174 | + // skip to next style if this has already been done |
|
175 | + if ($style->isRegistered()) { |
|
176 | + continue; |
|
177 | + } |
|
178 | + do_action( |
|
179 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style', |
|
180 | + $style |
|
181 | + ); |
|
182 | + wp_enqueue_style( |
|
183 | + $style->handle(), |
|
184 | + $style->source(), |
|
185 | + $style->dependencies(), |
|
186 | + $style->version(), |
|
187 | + $style->media() |
|
188 | + ); |
|
189 | + $style->setRegistered(); |
|
190 | + do_action( |
|
191 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style', |
|
192 | + $style |
|
193 | + ); |
|
194 | + } |
|
195 | + } |
|
196 | + |
|
197 | + |
|
198 | + /** |
|
199 | + * Call back for the script print in frontend and backend. |
|
200 | + * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point. |
|
201 | + * |
|
202 | + * @since 4.9.31.rc.015 |
|
203 | + */ |
|
204 | + public function enqueueData() |
|
205 | + { |
|
206 | + $this->removeAlreadyRegisteredDataForScriptHandles(); |
|
207 | + wp_add_inline_script( |
|
208 | + 'eejs-core', |
|
209 | + 'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)), |
|
210 | + 'before' |
|
211 | + ); |
|
212 | + $scripts = $this->assets->getJavascriptAssetsWithData(); |
|
213 | + foreach ($scripts as $script) { |
|
214 | + $this->addRegisteredScriptHandlesWithData($script->handle()); |
|
215 | + if ($script->hasInlineDataCallback()) { |
|
216 | + $localize = $script->inlineDataCallback(); |
|
217 | + $localize(); |
|
218 | + } |
|
219 | + } |
|
220 | + } |
|
221 | + |
|
222 | + |
|
223 | + /** |
|
224 | + * Used to add data to eejs.data object. |
|
225 | + * Note: Overriding existing data is not allowed. |
|
226 | + * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
227 | + * If the data you add is something like this: |
|
228 | + * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
229 | + * It will be exposed in the page source as: |
|
230 | + * eejs.data.my_plugin_data.foo == gar |
|
231 | + * |
|
232 | + * @param string $key Key used to access your data |
|
233 | + * @param string|array $value Value to attach to key |
|
234 | + * @throws InvalidArgumentException |
|
235 | + */ |
|
236 | + public function addData($key, $value) |
|
237 | + { |
|
238 | + if ($this->verifyDataNotExisting($key)) { |
|
239 | + $this->jsdata[ $key ] = $value; |
|
240 | + } |
|
241 | + } |
|
242 | + |
|
243 | + |
|
244 | + /** |
|
245 | + * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
246 | + * elements in an array. |
|
247 | + * When you use this method, the value you include will be appended to the end of an array on $key. |
|
248 | + * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript |
|
249 | + * object like this, eejs.data.test = [ my_data, |
|
250 | + * ] |
|
251 | + * If there has already been a scalar value attached to the data object given key, then |
|
252 | + * this will throw an exception. |
|
253 | + * |
|
254 | + * @param string $key Key to attach data to. |
|
255 | + * @param string|array $value Value being registered. |
|
256 | + * @throws InvalidArgumentException |
|
257 | + */ |
|
258 | + public function pushData($key, $value) |
|
259 | + { |
|
260 | + if (isset($this->jsdata[ $key ]) |
|
261 | + && ! is_array($this->jsdata[ $key ]) |
|
262 | + ) { |
|
263 | + throw new InvalidArgumentException( |
|
264 | + sprintf( |
|
265 | + __( |
|
266 | + 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
267 | 267 | push values to this data element when it is an array.', |
268 | - 'event_espresso' |
|
269 | - ), |
|
270 | - $key, |
|
271 | - __METHOD__ |
|
272 | - ) |
|
273 | - ); |
|
274 | - } |
|
275 | - $this->jsdata[ $key ][] = $value; |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - /** |
|
280 | - * Used to set content used by javascript for a template. |
|
281 | - * Note: Overrides of existing registered templates are not allowed. |
|
282 | - * |
|
283 | - * @param string $template_reference |
|
284 | - * @param string $template_content |
|
285 | - * @throws InvalidArgumentException |
|
286 | - */ |
|
287 | - public function addTemplate($template_reference, $template_content) |
|
288 | - { |
|
289 | - if (! isset($this->jsdata['templates'])) { |
|
290 | - $this->jsdata['templates'] = array(); |
|
291 | - } |
|
292 | - //no overrides allowed. |
|
293 | - if (isset($this->jsdata['templates'][ $template_reference ])) { |
|
294 | - throw new InvalidArgumentException( |
|
295 | - sprintf( |
|
296 | - __( |
|
297 | - 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
298 | - 'event_espresso' |
|
299 | - ), |
|
300 | - $template_reference |
|
301 | - ) |
|
302 | - ); |
|
303 | - } |
|
304 | - $this->jsdata['templates'][ $template_reference ] = $template_content; |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - /** |
|
309 | - * Retrieve the template content already registered for the given reference. |
|
310 | - * |
|
311 | - * @param string $template_reference |
|
312 | - * @return string |
|
313 | - */ |
|
314 | - public function getTemplate($template_reference) |
|
315 | - { |
|
316 | - return isset($this->jsdata['templates'][ $template_reference ]) |
|
317 | - ? $this->jsdata['templates'][ $template_reference ] |
|
318 | - : ''; |
|
319 | - } |
|
320 | - |
|
321 | - |
|
322 | - /** |
|
323 | - * Retrieve registered data. |
|
324 | - * |
|
325 | - * @param string $key Name of key to attach data to. |
|
326 | - * @return mixed If there is no for the given key, then false is returned. |
|
327 | - */ |
|
328 | - public function getData($key) |
|
329 | - { |
|
330 | - return isset($this->jsdata[ $key ]) |
|
331 | - ? $this->jsdata[ $key ] |
|
332 | - : false; |
|
333 | - } |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * Verifies whether the given data exists already on the jsdata array. |
|
338 | - * Overriding data is not allowed. |
|
339 | - * |
|
340 | - * @param string $key Index for data. |
|
341 | - * @return bool If valid then return true. |
|
342 | - * @throws InvalidArgumentException if data already exists. |
|
343 | - */ |
|
344 | - protected function verifyDataNotExisting($key) |
|
345 | - { |
|
346 | - if (isset($this->jsdata[ $key ])) { |
|
347 | - if (is_array($this->jsdata[ $key ])) { |
|
348 | - throw new InvalidArgumentException( |
|
349 | - sprintf( |
|
350 | - __( |
|
351 | - 'The value for %1$s already exists in the Registry::eejs object. |
|
268 | + 'event_espresso' |
|
269 | + ), |
|
270 | + $key, |
|
271 | + __METHOD__ |
|
272 | + ) |
|
273 | + ); |
|
274 | + } |
|
275 | + $this->jsdata[ $key ][] = $value; |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + /** |
|
280 | + * Used to set content used by javascript for a template. |
|
281 | + * Note: Overrides of existing registered templates are not allowed. |
|
282 | + * |
|
283 | + * @param string $template_reference |
|
284 | + * @param string $template_content |
|
285 | + * @throws InvalidArgumentException |
|
286 | + */ |
|
287 | + public function addTemplate($template_reference, $template_content) |
|
288 | + { |
|
289 | + if (! isset($this->jsdata['templates'])) { |
|
290 | + $this->jsdata['templates'] = array(); |
|
291 | + } |
|
292 | + //no overrides allowed. |
|
293 | + if (isset($this->jsdata['templates'][ $template_reference ])) { |
|
294 | + throw new InvalidArgumentException( |
|
295 | + sprintf( |
|
296 | + __( |
|
297 | + 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
298 | + 'event_espresso' |
|
299 | + ), |
|
300 | + $template_reference |
|
301 | + ) |
|
302 | + ); |
|
303 | + } |
|
304 | + $this->jsdata['templates'][ $template_reference ] = $template_content; |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + /** |
|
309 | + * Retrieve the template content already registered for the given reference. |
|
310 | + * |
|
311 | + * @param string $template_reference |
|
312 | + * @return string |
|
313 | + */ |
|
314 | + public function getTemplate($template_reference) |
|
315 | + { |
|
316 | + return isset($this->jsdata['templates'][ $template_reference ]) |
|
317 | + ? $this->jsdata['templates'][ $template_reference ] |
|
318 | + : ''; |
|
319 | + } |
|
320 | + |
|
321 | + |
|
322 | + /** |
|
323 | + * Retrieve registered data. |
|
324 | + * |
|
325 | + * @param string $key Name of key to attach data to. |
|
326 | + * @return mixed If there is no for the given key, then false is returned. |
|
327 | + */ |
|
328 | + public function getData($key) |
|
329 | + { |
|
330 | + return isset($this->jsdata[ $key ]) |
|
331 | + ? $this->jsdata[ $key ] |
|
332 | + : false; |
|
333 | + } |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * Verifies whether the given data exists already on the jsdata array. |
|
338 | + * Overriding data is not allowed. |
|
339 | + * |
|
340 | + * @param string $key Index for data. |
|
341 | + * @return bool If valid then return true. |
|
342 | + * @throws InvalidArgumentException if data already exists. |
|
343 | + */ |
|
344 | + protected function verifyDataNotExisting($key) |
|
345 | + { |
|
346 | + if (isset($this->jsdata[ $key ])) { |
|
347 | + if (is_array($this->jsdata[ $key ])) { |
|
348 | + throw new InvalidArgumentException( |
|
349 | + sprintf( |
|
350 | + __( |
|
351 | + 'The value for %1$s already exists in the Registry::eejs object. |
|
352 | 352 | Overrides are not allowed. Since the value of this data is an array, you may want to use the |
353 | 353 | %2$s method to push your value to the array.', |
354 | - 'event_espresso' |
|
355 | - ), |
|
356 | - $key, |
|
357 | - 'pushData()' |
|
358 | - ) |
|
359 | - ); |
|
360 | - } |
|
361 | - throw new InvalidArgumentException( |
|
362 | - sprintf( |
|
363 | - __( |
|
364 | - 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
354 | + 'event_espresso' |
|
355 | + ), |
|
356 | + $key, |
|
357 | + 'pushData()' |
|
358 | + ) |
|
359 | + ); |
|
360 | + } |
|
361 | + throw new InvalidArgumentException( |
|
362 | + sprintf( |
|
363 | + __( |
|
364 | + 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
365 | 365 | allowed. Consider attaching your value to a different key', |
366 | - 'event_espresso' |
|
367 | - ), |
|
368 | - $key |
|
369 | - ) |
|
370 | - ); |
|
371 | - } |
|
372 | - return true; |
|
373 | - } |
|
374 | - |
|
375 | - |
|
376 | - /** |
|
377 | - * Get the actual asset path for asset manifests. |
|
378 | - * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned. |
|
379 | - * |
|
380 | - * @param string $namespace The namespace associated with the manifest file hosting the map of chunk_name to actual |
|
381 | - * asset file location. |
|
382 | - * @param string $chunk_name |
|
383 | - * @param string $asset_type |
|
384 | - * @return string |
|
385 | - * @since 4.9.59.p |
|
386 | - */ |
|
387 | - public function getAssetUrl($namespace, $chunk_name, $asset_type) |
|
388 | - { |
|
389 | - $url = isset( |
|
390 | - $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ], |
|
391 | - $this->manifest_data[ $namespace ]['url_base'] |
|
392 | - ) |
|
393 | - ? $this->manifest_data[ $namespace ]['url_base'] |
|
394 | - . $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ] |
|
395 | - : $chunk_name; |
|
396 | - return apply_filters( |
|
397 | - 'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl', |
|
398 | - $url, |
|
399 | - $namespace, |
|
400 | - $chunk_name, |
|
401 | - $asset_type |
|
402 | - ); |
|
403 | - } |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * Return the url to a js file for the given namespace and chunk name. |
|
408 | - * |
|
409 | - * @param string $namespace |
|
410 | - * @param string $chunk_name |
|
411 | - * @return string |
|
412 | - */ |
|
413 | - public function getJsUrl($namespace, $chunk_name) |
|
414 | - { |
|
415 | - return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS); |
|
416 | - } |
|
417 | - |
|
418 | - |
|
419 | - /** |
|
420 | - * Return the url to a css file for the given namespace and chunk name. |
|
421 | - * |
|
422 | - * @param string $namespace |
|
423 | - * @param string $chunk_name |
|
424 | - * @return string |
|
425 | - */ |
|
426 | - public function getCssUrl($namespace, $chunk_name) |
|
427 | - { |
|
428 | - return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS); |
|
429 | - } |
|
430 | - |
|
431 | - |
|
432 | - /** |
|
433 | - * @since 4.9.62.p |
|
434 | - * @throws InvalidArgumentException |
|
435 | - * @throws InvalidFilePathException |
|
436 | - */ |
|
437 | - public function registerManifestFiles() |
|
438 | - { |
|
439 | - $manifest_files = $this->assets->getManifestFiles(); |
|
440 | - foreach ($manifest_files as $manifest_file) { |
|
441 | - $this->registerManifestFile( |
|
442 | - $manifest_file->assetNamespace(), |
|
443 | - $manifest_file->urlBase(), |
|
444 | - $manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST |
|
445 | - ); |
|
446 | - } |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - /** |
|
451 | - * Used to register a js/css manifest file with the registered_manifest_files property. |
|
452 | - * |
|
453 | - * @param string $namespace Provided to associate the manifest file with a specific namespace. |
|
454 | - * @param string $url_base The url base for the manifest file location. |
|
455 | - * @param string $manifest_file The absolute path to the manifest file. |
|
456 | - * @throws InvalidArgumentException |
|
457 | - * @throws InvalidFilePathException |
|
458 | - * @since 4.9.59.p |
|
459 | - */ |
|
460 | - public function registerManifestFile($namespace, $url_base, $manifest_file) |
|
461 | - { |
|
462 | - if (isset($this->manifest_data[ $namespace ])) { |
|
463 | - throw new InvalidArgumentException( |
|
464 | - sprintf( |
|
465 | - esc_html__( |
|
466 | - 'The namespace for this manifest file has already been registered, choose a namespace other than %s', |
|
467 | - 'event_espresso' |
|
468 | - ), |
|
469 | - $namespace |
|
470 | - ) |
|
471 | - ); |
|
472 | - } |
|
473 | - if (filter_var($url_base, FILTER_VALIDATE_URL) === false) { |
|
474 | - if (is_admin()) { |
|
475 | - EE_Error::add_error( |
|
476 | - sprintf( |
|
477 | - esc_html__( |
|
478 | - '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', |
|
479 | - 'event_espresso' |
|
480 | - ), |
|
481 | - 'Event Espresso', |
|
482 | - $url_base, |
|
483 | - 'plugins_url', |
|
484 | - 'WP_PLUGIN_URL' |
|
485 | - ), |
|
486 | - __FILE__, |
|
487 | - __FUNCTION__, |
|
488 | - __LINE__ |
|
489 | - ); |
|
490 | - } |
|
491 | - return; |
|
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); |
|
496 | - } |
|
497 | - } |
|
498 | - |
|
499 | - |
|
500 | - /** |
|
501 | - * Decodes json from the provided manifest file. |
|
502 | - * |
|
503 | - * @since 4.9.59.p |
|
504 | - * @param string $manifest_file Path to manifest file. |
|
505 | - * @return array |
|
506 | - * @throws InvalidFilePathException |
|
507 | - */ |
|
508 | - private function decodeManifestFile($manifest_file) |
|
509 | - { |
|
510 | - if (! file_exists($manifest_file)) { |
|
511 | - throw new InvalidFilePathException($manifest_file); |
|
512 | - } |
|
513 | - return json_decode(file_get_contents($manifest_file), true); |
|
514 | - } |
|
515 | - |
|
516 | - |
|
517 | - /** |
|
518 | - * This is used to set registered script handles that have data. |
|
519 | - * |
|
520 | - * @param string $script_handle |
|
521 | - */ |
|
522 | - private function addRegisteredScriptHandlesWithData($script_handle) |
|
523 | - { |
|
524 | - $this->script_handles_with_data[ $script_handle ] = $script_handle; |
|
525 | - } |
|
526 | - |
|
527 | - |
|
528 | - /**i |
|
366 | + 'event_espresso' |
|
367 | + ), |
|
368 | + $key |
|
369 | + ) |
|
370 | + ); |
|
371 | + } |
|
372 | + return true; |
|
373 | + } |
|
374 | + |
|
375 | + |
|
376 | + /** |
|
377 | + * Get the actual asset path for asset manifests. |
|
378 | + * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned. |
|
379 | + * |
|
380 | + * @param string $namespace The namespace associated with the manifest file hosting the map of chunk_name to actual |
|
381 | + * asset file location. |
|
382 | + * @param string $chunk_name |
|
383 | + * @param string $asset_type |
|
384 | + * @return string |
|
385 | + * @since 4.9.59.p |
|
386 | + */ |
|
387 | + public function getAssetUrl($namespace, $chunk_name, $asset_type) |
|
388 | + { |
|
389 | + $url = isset( |
|
390 | + $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ], |
|
391 | + $this->manifest_data[ $namespace ]['url_base'] |
|
392 | + ) |
|
393 | + ? $this->manifest_data[ $namespace ]['url_base'] |
|
394 | + . $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ] |
|
395 | + : $chunk_name; |
|
396 | + return apply_filters( |
|
397 | + 'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl', |
|
398 | + $url, |
|
399 | + $namespace, |
|
400 | + $chunk_name, |
|
401 | + $asset_type |
|
402 | + ); |
|
403 | + } |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * Return the url to a js file for the given namespace and chunk name. |
|
408 | + * |
|
409 | + * @param string $namespace |
|
410 | + * @param string $chunk_name |
|
411 | + * @return string |
|
412 | + */ |
|
413 | + public function getJsUrl($namespace, $chunk_name) |
|
414 | + { |
|
415 | + return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS); |
|
416 | + } |
|
417 | + |
|
418 | + |
|
419 | + /** |
|
420 | + * Return the url to a css file for the given namespace and chunk name. |
|
421 | + * |
|
422 | + * @param string $namespace |
|
423 | + * @param string $chunk_name |
|
424 | + * @return string |
|
425 | + */ |
|
426 | + public function getCssUrl($namespace, $chunk_name) |
|
427 | + { |
|
428 | + return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS); |
|
429 | + } |
|
430 | + |
|
431 | + |
|
432 | + /** |
|
433 | + * @since 4.9.62.p |
|
434 | + * @throws InvalidArgumentException |
|
435 | + * @throws InvalidFilePathException |
|
436 | + */ |
|
437 | + public function registerManifestFiles() |
|
438 | + { |
|
439 | + $manifest_files = $this->assets->getManifestFiles(); |
|
440 | + foreach ($manifest_files as $manifest_file) { |
|
441 | + $this->registerManifestFile( |
|
442 | + $manifest_file->assetNamespace(), |
|
443 | + $manifest_file->urlBase(), |
|
444 | + $manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST |
|
445 | + ); |
|
446 | + } |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + /** |
|
451 | + * Used to register a js/css manifest file with the registered_manifest_files property. |
|
452 | + * |
|
453 | + * @param string $namespace Provided to associate the manifest file with a specific namespace. |
|
454 | + * @param string $url_base The url base for the manifest file location. |
|
455 | + * @param string $manifest_file The absolute path to the manifest file. |
|
456 | + * @throws InvalidArgumentException |
|
457 | + * @throws InvalidFilePathException |
|
458 | + * @since 4.9.59.p |
|
459 | + */ |
|
460 | + public function registerManifestFile($namespace, $url_base, $manifest_file) |
|
461 | + { |
|
462 | + if (isset($this->manifest_data[ $namespace ])) { |
|
463 | + throw new InvalidArgumentException( |
|
464 | + sprintf( |
|
465 | + esc_html__( |
|
466 | + 'The namespace for this manifest file has already been registered, choose a namespace other than %s', |
|
467 | + 'event_espresso' |
|
468 | + ), |
|
469 | + $namespace |
|
470 | + ) |
|
471 | + ); |
|
472 | + } |
|
473 | + if (filter_var($url_base, FILTER_VALIDATE_URL) === false) { |
|
474 | + if (is_admin()) { |
|
475 | + EE_Error::add_error( |
|
476 | + sprintf( |
|
477 | + esc_html__( |
|
478 | + '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', |
|
479 | + 'event_espresso' |
|
480 | + ), |
|
481 | + 'Event Espresso', |
|
482 | + $url_base, |
|
483 | + 'plugins_url', |
|
484 | + 'WP_PLUGIN_URL' |
|
485 | + ), |
|
486 | + __FILE__, |
|
487 | + __FUNCTION__, |
|
488 | + __LINE__ |
|
489 | + ); |
|
490 | + } |
|
491 | + return; |
|
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); |
|
496 | + } |
|
497 | + } |
|
498 | + |
|
499 | + |
|
500 | + /** |
|
501 | + * Decodes json from the provided manifest file. |
|
502 | + * |
|
503 | + * @since 4.9.59.p |
|
504 | + * @param string $manifest_file Path to manifest file. |
|
505 | + * @return array |
|
506 | + * @throws InvalidFilePathException |
|
507 | + */ |
|
508 | + private function decodeManifestFile($manifest_file) |
|
509 | + { |
|
510 | + if (! file_exists($manifest_file)) { |
|
511 | + throw new InvalidFilePathException($manifest_file); |
|
512 | + } |
|
513 | + return json_decode(file_get_contents($manifest_file), true); |
|
514 | + } |
|
515 | + |
|
516 | + |
|
517 | + /** |
|
518 | + * This is used to set registered script handles that have data. |
|
519 | + * |
|
520 | + * @param string $script_handle |
|
521 | + */ |
|
522 | + private function addRegisteredScriptHandlesWithData($script_handle) |
|
523 | + { |
|
524 | + $this->script_handles_with_data[ $script_handle ] = $script_handle; |
|
525 | + } |
|
526 | + |
|
527 | + |
|
528 | + /**i |
|
529 | 529 | * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the |
530 | 530 | * Dependency stored in WP_Scripts if its set. |
531 | 531 | */ |
532 | - private function removeAlreadyRegisteredDataForScriptHandles() |
|
533 | - { |
|
534 | - if (empty($this->script_handles_with_data)) { |
|
535 | - return; |
|
536 | - } |
|
537 | - foreach ($this->script_handles_with_data as $script_handle) { |
|
538 | - $this->removeAlreadyRegisteredDataForScriptHandle($script_handle); |
|
539 | - } |
|
540 | - } |
|
541 | - |
|
542 | - |
|
543 | - /** |
|
544 | - * Removes any data dependency registered in WP_Scripts if its set. |
|
545 | - * |
|
546 | - * @param string $script_handle |
|
547 | - */ |
|
548 | - private function removeAlreadyRegisteredDataForScriptHandle($script_handle) |
|
549 | - { |
|
550 | - if (isset($this->script_handles_with_data[ $script_handle ])) { |
|
551 | - global $wp_scripts; |
|
552 | - $unset_handle = false; |
|
553 | - if ($wp_scripts->get_data($script_handle, 'data')) { |
|
554 | - unset($wp_scripts->registered[ $script_handle ]->extra['data']); |
|
555 | - $unset_handle = true; |
|
556 | - } |
|
557 | - //deal with inline_scripts |
|
558 | - if ($wp_scripts->get_data($script_handle, 'before')) { |
|
559 | - unset($wp_scripts->registered[ $script_handle ]->extra['before']); |
|
560 | - $unset_handle = true; |
|
561 | - } |
|
562 | - if ($wp_scripts->get_data($script_handle, 'after')) { |
|
563 | - unset($wp_scripts->registered[ $script_handle ]->extra['after']); |
|
564 | - } |
|
565 | - if ($unset_handle) { |
|
566 | - unset($this->script_handles_with_data[ $script_handle ]); |
|
567 | - } |
|
568 | - } |
|
569 | - } |
|
570 | - |
|
571 | - |
|
572 | - /** |
|
573 | - * register translations for a registered script |
|
574 | - * |
|
575 | - * @param string $handle |
|
576 | - */ |
|
577 | - public function registerTranslation($handle) |
|
578 | - { |
|
579 | - $this->i18n_registry->registerScriptI18n($handle); |
|
580 | - } |
|
532 | + private function removeAlreadyRegisteredDataForScriptHandles() |
|
533 | + { |
|
534 | + if (empty($this->script_handles_with_data)) { |
|
535 | + return; |
|
536 | + } |
|
537 | + foreach ($this->script_handles_with_data as $script_handle) { |
|
538 | + $this->removeAlreadyRegisteredDataForScriptHandle($script_handle); |
|
539 | + } |
|
540 | + } |
|
541 | + |
|
542 | + |
|
543 | + /** |
|
544 | + * Removes any data dependency registered in WP_Scripts if its set. |
|
545 | + * |
|
546 | + * @param string $script_handle |
|
547 | + */ |
|
548 | + private function removeAlreadyRegisteredDataForScriptHandle($script_handle) |
|
549 | + { |
|
550 | + if (isset($this->script_handles_with_data[ $script_handle ])) { |
|
551 | + global $wp_scripts; |
|
552 | + $unset_handle = false; |
|
553 | + if ($wp_scripts->get_data($script_handle, 'data')) { |
|
554 | + unset($wp_scripts->registered[ $script_handle ]->extra['data']); |
|
555 | + $unset_handle = true; |
|
556 | + } |
|
557 | + //deal with inline_scripts |
|
558 | + if ($wp_scripts->get_data($script_handle, 'before')) { |
|
559 | + unset($wp_scripts->registered[ $script_handle ]->extra['before']); |
|
560 | + $unset_handle = true; |
|
561 | + } |
|
562 | + if ($wp_scripts->get_data($script_handle, 'after')) { |
|
563 | + unset($wp_scripts->registered[ $script_handle ]->extra['after']); |
|
564 | + } |
|
565 | + if ($unset_handle) { |
|
566 | + unset($this->script_handles_with_data[ $script_handle ]); |
|
567 | + } |
|
568 | + } |
|
569 | + } |
|
570 | + |
|
571 | + |
|
572 | + /** |
|
573 | + * register translations for a registered script |
|
574 | + * |
|
575 | + * @param string $handle |
|
576 | + */ |
|
577 | + public function registerTranslation($handle) |
|
578 | + { |
|
579 | + $this->i18n_registry->registerScriptI18n($handle); |
|
580 | + } |
|
581 | 581 | } |
@@ -146,7 +146,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |