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