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