@@ -21,86 +21,86 @@ |
||
21 | 21 | { |
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * AssetCollection constructor |
|
26 | - * |
|
27 | - * @throws InvalidInterfaceException |
|
28 | - */ |
|
29 | - public function __construct() |
|
30 | - { |
|
31 | - parent::__construct('EventEspresso\core\domain\values\assets\Asset'); |
|
32 | - } |
|
24 | + /** |
|
25 | + * AssetCollection constructor |
|
26 | + * |
|
27 | + * @throws InvalidInterfaceException |
|
28 | + */ |
|
29 | + public function __construct() |
|
30 | + { |
|
31 | + parent::__construct('EventEspresso\core\domain\values\assets\Asset'); |
|
32 | + } |
|
33 | 33 | |
34 | 34 | |
35 | - /** |
|
36 | - * @return StylesheetAsset[] |
|
37 | - * @since 4.9.62.p |
|
38 | - */ |
|
39 | - public function getStylesheetAssets() |
|
40 | - { |
|
41 | - return $this->getAssetsOfType(Asset::TYPE_CSS); |
|
42 | - } |
|
35 | + /** |
|
36 | + * @return StylesheetAsset[] |
|
37 | + * @since 4.9.62.p |
|
38 | + */ |
|
39 | + public function getStylesheetAssets() |
|
40 | + { |
|
41 | + return $this->getAssetsOfType(Asset::TYPE_CSS); |
|
42 | + } |
|
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * @return JavascriptAsset[] |
|
47 | - * @since 4.9.62.p |
|
48 | - */ |
|
49 | - public function getJavascriptAssets() |
|
50 | - { |
|
51 | - return $this->getAssetsOfType(Asset::TYPE_JS); |
|
52 | - } |
|
45 | + /** |
|
46 | + * @return JavascriptAsset[] |
|
47 | + * @since 4.9.62.p |
|
48 | + */ |
|
49 | + public function getJavascriptAssets() |
|
50 | + { |
|
51 | + return $this->getAssetsOfType(Asset::TYPE_JS); |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * @return ManifestFile[] |
|
57 | - * @since 4.9.62.p |
|
58 | - */ |
|
59 | - public function getManifestFiles() |
|
60 | - { |
|
61 | - return $this->getAssetsOfType(Asset::TYPE_MANIFEST); |
|
62 | - } |
|
55 | + /** |
|
56 | + * @return ManifestFile[] |
|
57 | + * @since 4.9.62.p |
|
58 | + */ |
|
59 | + public function getManifestFiles() |
|
60 | + { |
|
61 | + return $this->getAssetsOfType(Asset::TYPE_MANIFEST); |
|
62 | + } |
|
63 | 63 | |
64 | 64 | |
65 | - /** |
|
66 | - * @param $type |
|
67 | - * @return array |
|
68 | - * @since 4.9.62.p |
|
69 | - */ |
|
70 | - protected function getAssetsOfType($type) |
|
71 | - { |
|
72 | - $files = array(); |
|
73 | - $this->rewind(); |
|
74 | - while ($this->valid()) { |
|
75 | - /** @var \EventEspresso\core\domain\values\assets\Asset $asset */ |
|
76 | - $asset = $this->current(); |
|
77 | - if ($asset->type() === $type) { |
|
78 | - $files[ $asset->handle() ] = $asset; |
|
79 | - } |
|
80 | - $this->next(); |
|
81 | - } |
|
82 | - $this->rewind(); |
|
83 | - return $files; |
|
84 | - } |
|
65 | + /** |
|
66 | + * @param $type |
|
67 | + * @return array |
|
68 | + * @since 4.9.62.p |
|
69 | + */ |
|
70 | + protected function getAssetsOfType($type) |
|
71 | + { |
|
72 | + $files = array(); |
|
73 | + $this->rewind(); |
|
74 | + while ($this->valid()) { |
|
75 | + /** @var \EventEspresso\core\domain\values\assets\Asset $asset */ |
|
76 | + $asset = $this->current(); |
|
77 | + if ($asset->type() === $type) { |
|
78 | + $files[ $asset->handle() ] = $asset; |
|
79 | + } |
|
80 | + $this->next(); |
|
81 | + } |
|
82 | + $this->rewind(); |
|
83 | + return $files; |
|
84 | + } |
|
85 | 85 | |
86 | 86 | |
87 | - /** |
|
88 | - * @return JavascriptAsset[] |
|
89 | - * @since 4.9.62.p |
|
90 | - */ |
|
91 | - public function getJavascriptAssetsWithData() |
|
92 | - { |
|
93 | - $files = array(); |
|
94 | - $this->rewind(); |
|
95 | - while ($this->valid()) { |
|
96 | - /** @var \EventEspresso\core\domain\values\assets\JavascriptAsset $asset */ |
|
97 | - $asset = $this->current(); |
|
98 | - if ($asset->type() === Asset::TYPE_JS && $asset->hasLocalizedData()) { |
|
99 | - $files[ $asset->handle() ] = $asset; |
|
100 | - } |
|
101 | - $this->next(); |
|
102 | - } |
|
103 | - $this->rewind(); |
|
104 | - return $files; |
|
105 | - } |
|
87 | + /** |
|
88 | + * @return JavascriptAsset[] |
|
89 | + * @since 4.9.62.p |
|
90 | + */ |
|
91 | + public function getJavascriptAssetsWithData() |
|
92 | + { |
|
93 | + $files = array(); |
|
94 | + $this->rewind(); |
|
95 | + while ($this->valid()) { |
|
96 | + /** @var \EventEspresso\core\domain\values\assets\JavascriptAsset $asset */ |
|
97 | + $asset = $this->current(); |
|
98 | + if ($asset->type() === Asset::TYPE_JS && $asset->hasLocalizedData()) { |
|
99 | + $files[ $asset->handle() ] = $asset; |
|
100 | + } |
|
101 | + $this->next(); |
|
102 | + } |
|
103 | + $this->rewind(); |
|
104 | + return $files; |
|
105 | + } |
|
106 | 106 | } |
@@ -21,161 +21,161 @@ |
||
21 | 21 | abstract class AssetManager implements AssetManagerInterface |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * @var AssetCollection $assets |
|
26 | - */ |
|
27 | - protected $assets; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var DomainInterface |
|
31 | - */ |
|
32 | - protected $domain; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var Registry $registry |
|
36 | - */ |
|
37 | - protected $registry; |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * AssetRegister constructor. |
|
42 | - * |
|
43 | - * @param DomainInterface $domain |
|
44 | - * @param AssetCollection $assets |
|
45 | - * @param Registry $registry |
|
46 | - */ |
|
47 | - public function __construct(DomainInterface $domain, AssetCollection $assets, Registry $registry) |
|
48 | - { |
|
49 | - $this->domain = $domain; |
|
50 | - $this->assets = $assets; |
|
51 | - $this->registry = $registry; |
|
52 | - add_action('wp_enqueue_scripts', array($this, 'addManifestFile'), 0); |
|
53 | - add_action('admin_enqueue_scripts', array($this, 'addManifestFile'), 0); |
|
54 | - add_action('wp_enqueue_scripts', array($this, 'addAssets'), 2); |
|
55 | - add_action('admin_enqueue_scripts', array($this, 'addAssets'), 2); |
|
56 | - } |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * @return void |
|
61 | - * @throws DuplicateCollectionIdentifierException |
|
62 | - * @throws InvalidDataTypeException |
|
63 | - * @throws InvalidEntityException |
|
64 | - * @since 4.9.62.p |
|
65 | - */ |
|
66 | - public function addManifestFile() |
|
67 | - { |
|
68 | - // if a manifest file has already been added for this domain, then just return that one |
|
69 | - if ($this->assets->has($this->domain->assetNamespace())) { |
|
70 | - return; |
|
71 | - } |
|
72 | - $asset = new ManifestFile($this->domain); |
|
73 | - $this->assets->add($asset, $this->domain->assetNamespace()); |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * @return ManifestFile[] |
|
79 | - * @since 4.9.62.p |
|
80 | - */ |
|
81 | - public function getManifestFile() |
|
82 | - { |
|
83 | - return $this->assets->getManifestFiles(); |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * @param string $handle |
|
89 | - * @param string $source |
|
90 | - * @param array $dependencies |
|
91 | - * @param bool $load_in_footer |
|
92 | - * @return JavascriptAsset |
|
93 | - * @throws DuplicateCollectionIdentifierException |
|
94 | - * @throws InvalidDataTypeException |
|
95 | - * @throws InvalidEntityException |
|
96 | - * @since 4.9.62.p |
|
97 | - */ |
|
98 | - public function addJavascript( |
|
99 | - $handle, |
|
100 | - $source, |
|
101 | - array $dependencies = array(), |
|
102 | - $load_in_footer = true |
|
103 | - ) { |
|
104 | - $asset = new JavascriptAsset( |
|
105 | - $handle, |
|
106 | - $source, |
|
107 | - $dependencies, |
|
108 | - $load_in_footer, |
|
109 | - $this->domain |
|
110 | - ); |
|
111 | - $this->assets->add($asset, $handle); |
|
112 | - return $asset; |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * @return JavascriptAsset[] |
|
118 | - * @since 4.9.62.p |
|
119 | - */ |
|
120 | - public function getJavascriptAssets() |
|
121 | - { |
|
122 | - return $this->assets->getJavascriptAssets(); |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * @param string $handle |
|
128 | - * @param string $source |
|
129 | - * @param array $dependencies |
|
130 | - * @param string $media |
|
131 | - * @return StylesheetAsset |
|
132 | - * @throws DuplicateCollectionIdentifierException |
|
133 | - * @throws InvalidDataTypeException |
|
134 | - * @throws InvalidEntityException |
|
135 | - * @since 4.9.62.p |
|
136 | - */ |
|
137 | - public function addStylesheet( |
|
138 | - $handle, |
|
139 | - $source, |
|
140 | - array $dependencies = array(), |
|
141 | - $media = 'all' |
|
142 | - ) { |
|
143 | - $asset = new StylesheetAsset( |
|
144 | - $handle, |
|
145 | - $source, |
|
146 | - $dependencies, |
|
147 | - $this->domain, |
|
148 | - $media |
|
149 | - ); |
|
150 | - $this->assets->add($asset, $handle); |
|
151 | - return $asset; |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * @return StylesheetAsset[] |
|
157 | - * @since 4.9.62.p |
|
158 | - */ |
|
159 | - public function getStylesheetAssets() |
|
160 | - { |
|
161 | - return $this->assets->getStylesheetAssets(); |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * @param string $handle |
|
167 | - * @return bool |
|
168 | - * @since 4.9.62.p |
|
169 | - */ |
|
170 | - public function enqueueAsset($handle) |
|
171 | - { |
|
172 | - if ($this->assets->has($handle)) { |
|
173 | - $asset = $this->assets->get($handle); |
|
174 | - if ($asset->isRegistered()) { |
|
175 | - $asset->enqueueAsset(); |
|
176 | - return true; |
|
177 | - } |
|
178 | - } |
|
179 | - return false; |
|
180 | - } |
|
24 | + /** |
|
25 | + * @var AssetCollection $assets |
|
26 | + */ |
|
27 | + protected $assets; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var DomainInterface |
|
31 | + */ |
|
32 | + protected $domain; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var Registry $registry |
|
36 | + */ |
|
37 | + protected $registry; |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * AssetRegister constructor. |
|
42 | + * |
|
43 | + * @param DomainInterface $domain |
|
44 | + * @param AssetCollection $assets |
|
45 | + * @param Registry $registry |
|
46 | + */ |
|
47 | + public function __construct(DomainInterface $domain, AssetCollection $assets, Registry $registry) |
|
48 | + { |
|
49 | + $this->domain = $domain; |
|
50 | + $this->assets = $assets; |
|
51 | + $this->registry = $registry; |
|
52 | + add_action('wp_enqueue_scripts', array($this, 'addManifestFile'), 0); |
|
53 | + add_action('admin_enqueue_scripts', array($this, 'addManifestFile'), 0); |
|
54 | + add_action('wp_enqueue_scripts', array($this, 'addAssets'), 2); |
|
55 | + add_action('admin_enqueue_scripts', array($this, 'addAssets'), 2); |
|
56 | + } |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * @return void |
|
61 | + * @throws DuplicateCollectionIdentifierException |
|
62 | + * @throws InvalidDataTypeException |
|
63 | + * @throws InvalidEntityException |
|
64 | + * @since 4.9.62.p |
|
65 | + */ |
|
66 | + public function addManifestFile() |
|
67 | + { |
|
68 | + // if a manifest file has already been added for this domain, then just return that one |
|
69 | + if ($this->assets->has($this->domain->assetNamespace())) { |
|
70 | + return; |
|
71 | + } |
|
72 | + $asset = new ManifestFile($this->domain); |
|
73 | + $this->assets->add($asset, $this->domain->assetNamespace()); |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * @return ManifestFile[] |
|
79 | + * @since 4.9.62.p |
|
80 | + */ |
|
81 | + public function getManifestFile() |
|
82 | + { |
|
83 | + return $this->assets->getManifestFiles(); |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * @param string $handle |
|
89 | + * @param string $source |
|
90 | + * @param array $dependencies |
|
91 | + * @param bool $load_in_footer |
|
92 | + * @return JavascriptAsset |
|
93 | + * @throws DuplicateCollectionIdentifierException |
|
94 | + * @throws InvalidDataTypeException |
|
95 | + * @throws InvalidEntityException |
|
96 | + * @since 4.9.62.p |
|
97 | + */ |
|
98 | + public function addJavascript( |
|
99 | + $handle, |
|
100 | + $source, |
|
101 | + array $dependencies = array(), |
|
102 | + $load_in_footer = true |
|
103 | + ) { |
|
104 | + $asset = new JavascriptAsset( |
|
105 | + $handle, |
|
106 | + $source, |
|
107 | + $dependencies, |
|
108 | + $load_in_footer, |
|
109 | + $this->domain |
|
110 | + ); |
|
111 | + $this->assets->add($asset, $handle); |
|
112 | + return $asset; |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * @return JavascriptAsset[] |
|
118 | + * @since 4.9.62.p |
|
119 | + */ |
|
120 | + public function getJavascriptAssets() |
|
121 | + { |
|
122 | + return $this->assets->getJavascriptAssets(); |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * @param string $handle |
|
128 | + * @param string $source |
|
129 | + * @param array $dependencies |
|
130 | + * @param string $media |
|
131 | + * @return StylesheetAsset |
|
132 | + * @throws DuplicateCollectionIdentifierException |
|
133 | + * @throws InvalidDataTypeException |
|
134 | + * @throws InvalidEntityException |
|
135 | + * @since 4.9.62.p |
|
136 | + */ |
|
137 | + public function addStylesheet( |
|
138 | + $handle, |
|
139 | + $source, |
|
140 | + array $dependencies = array(), |
|
141 | + $media = 'all' |
|
142 | + ) { |
|
143 | + $asset = new StylesheetAsset( |
|
144 | + $handle, |
|
145 | + $source, |
|
146 | + $dependencies, |
|
147 | + $this->domain, |
|
148 | + $media |
|
149 | + ); |
|
150 | + $this->assets->add($asset, $handle); |
|
151 | + return $asset; |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * @return StylesheetAsset[] |
|
157 | + * @since 4.9.62.p |
|
158 | + */ |
|
159 | + public function getStylesheetAssets() |
|
160 | + { |
|
161 | + return $this->assets->getStylesheetAssets(); |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * @param string $handle |
|
167 | + * @return bool |
|
168 | + * @since 4.9.62.p |
|
169 | + */ |
|
170 | + public function enqueueAsset($handle) |
|
171 | + { |
|
172 | + if ($this->assets->has($handle)) { |
|
173 | + $asset = $this->assets->get($handle); |
|
174 | + if ($asset->isRegistered()) { |
|
175 | + $asset->enqueueAsset(); |
|
176 | + return true; |
|
177 | + } |
|
178 | + } |
|
179 | + return false; |
|
180 | + } |
|
181 | 181 | } |
@@ -17,154 +17,154 @@ |
||
17 | 17 | class CachingLoader extends CachingLoaderDecorator |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var string $identifier |
|
22 | - */ |
|
23 | - protected $identifier; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var CollectionInterface $cache |
|
27 | - */ |
|
28 | - protected $cache; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var ObjectIdentifier |
|
32 | - */ |
|
33 | - private $object_identifier; |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * CachingLoader constructor. |
|
38 | - * |
|
39 | - * @param LoaderDecoratorInterface $loader |
|
40 | - * @param CollectionInterface $cache |
|
41 | - * @param ObjectIdentifier $object_identifier |
|
42 | - * @param string $identifier |
|
43 | - * @throws InvalidDataTypeException |
|
44 | - */ |
|
45 | - public function __construct( |
|
46 | - LoaderDecoratorInterface $loader, |
|
47 | - CollectionInterface $cache, |
|
48 | - ObjectIdentifier $object_identifier, |
|
49 | - $identifier = '' |
|
50 | - ) { |
|
51 | - parent::__construct($loader); |
|
52 | - $this->cache = $cache; |
|
53 | - $this->object_identifier = $object_identifier; |
|
54 | - $this->setIdentifier($identifier); |
|
55 | - if ($this->identifier !== '') { |
|
56 | - // to only clear this cache, and assuming an identifier has been set, simply do the following: |
|
57 | - // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER'); |
|
58 | - // where "IDENTIFIER" = the string that was set during construction |
|
59 | - add_action( |
|
60 | - "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}", |
|
61 | - array($this, 'reset') |
|
62 | - ); |
|
63 | - } |
|
64 | - // to clear ALL caches, simply do the following: |
|
65 | - // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache'); |
|
66 | - add_action( |
|
67 | - 'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache', |
|
68 | - array($this, 'reset') |
|
69 | - ); |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * @return string |
|
75 | - */ |
|
76 | - public function identifier() |
|
77 | - { |
|
78 | - return $this->identifier; |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @param string $identifier |
|
84 | - * @throws InvalidDataTypeException |
|
85 | - */ |
|
86 | - private function setIdentifier($identifier) |
|
87 | - { |
|
88 | - if (! is_string($identifier)) { |
|
89 | - throw new InvalidDataTypeException('$identifier', $identifier, 'string'); |
|
90 | - } |
|
91 | - $this->identifier = $identifier; |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * @param FullyQualifiedName|string $fqcn |
|
97 | - * @param mixed $object |
|
98 | - * @return bool |
|
99 | - * @throws InvalidArgumentException |
|
100 | - */ |
|
101 | - public function share($fqcn, $object) |
|
102 | - { |
|
103 | - if ($object instanceof $fqcn) { |
|
104 | - return $this->cache->add($object, md5($fqcn)); |
|
105 | - } |
|
106 | - throw new InvalidArgumentException( |
|
107 | - sprintf( |
|
108 | - esc_html__( |
|
109 | - 'The supplied class name "%1$s" must match the class of the supplied object.', |
|
110 | - 'event_espresso' |
|
111 | - ), |
|
112 | - $fqcn |
|
113 | - ) |
|
114 | - ); |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * @param FullyQualifiedName|string $fqcn |
|
120 | - * @param array $arguments |
|
121 | - * @param bool $shared |
|
122 | - * @param array $interfaces |
|
123 | - * @return mixed |
|
124 | - */ |
|
125 | - public function load($fqcn, $arguments = array(), $shared = true, array $interfaces = array()) |
|
126 | - { |
|
127 | - $fqcn = ltrim($fqcn, '\\'); |
|
128 | - // caching can be turned off via the following code: |
|
129 | - // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
|
130 | - if (apply_filters( |
|
131 | - 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
|
132 | - false, |
|
133 | - $this |
|
134 | - )) { |
|
135 | - // even though $shared might be true, caching could be bypassed for whatever reason, |
|
136 | - // so we don't want the core loader to cache anything, therefore caching is turned off |
|
137 | - return $this->loader->load($fqcn, $arguments, false); |
|
138 | - } |
|
139 | - $object_identifier = $this->object_identifier->getIdentifier($fqcn, $arguments); |
|
140 | - if ($this->cache->has($object_identifier)) { |
|
141 | - return $this->cache->get($object_identifier); |
|
142 | - } |
|
143 | - $object = $this->loader->load($fqcn, $arguments, $shared); |
|
144 | - if ($object instanceof $fqcn) { |
|
145 | - $this->cache->add($object, $object_identifier); |
|
146 | - } |
|
147 | - return $object; |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * empties cache and calls reset() on loader if method exists |
|
153 | - */ |
|
154 | - public function reset() |
|
155 | - { |
|
156 | - $this->clearCache(); |
|
157 | - $this->loader->reset(); |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * unsets and detaches ALL objects from the cache |
|
163 | - * |
|
164 | - * @since 4.9.62.p |
|
165 | - */ |
|
166 | - public function clearCache() |
|
167 | - { |
|
168 | - $this->cache->trashAndDetachAll(); |
|
169 | - } |
|
20 | + /** |
|
21 | + * @var string $identifier |
|
22 | + */ |
|
23 | + protected $identifier; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var CollectionInterface $cache |
|
27 | + */ |
|
28 | + protected $cache; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var ObjectIdentifier |
|
32 | + */ |
|
33 | + private $object_identifier; |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * CachingLoader constructor. |
|
38 | + * |
|
39 | + * @param LoaderDecoratorInterface $loader |
|
40 | + * @param CollectionInterface $cache |
|
41 | + * @param ObjectIdentifier $object_identifier |
|
42 | + * @param string $identifier |
|
43 | + * @throws InvalidDataTypeException |
|
44 | + */ |
|
45 | + public function __construct( |
|
46 | + LoaderDecoratorInterface $loader, |
|
47 | + CollectionInterface $cache, |
|
48 | + ObjectIdentifier $object_identifier, |
|
49 | + $identifier = '' |
|
50 | + ) { |
|
51 | + parent::__construct($loader); |
|
52 | + $this->cache = $cache; |
|
53 | + $this->object_identifier = $object_identifier; |
|
54 | + $this->setIdentifier($identifier); |
|
55 | + if ($this->identifier !== '') { |
|
56 | + // to only clear this cache, and assuming an identifier has been set, simply do the following: |
|
57 | + // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER'); |
|
58 | + // where "IDENTIFIER" = the string that was set during construction |
|
59 | + add_action( |
|
60 | + "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}", |
|
61 | + array($this, 'reset') |
|
62 | + ); |
|
63 | + } |
|
64 | + // to clear ALL caches, simply do the following: |
|
65 | + // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache'); |
|
66 | + add_action( |
|
67 | + 'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache', |
|
68 | + array($this, 'reset') |
|
69 | + ); |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * @return string |
|
75 | + */ |
|
76 | + public function identifier() |
|
77 | + { |
|
78 | + return $this->identifier; |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @param string $identifier |
|
84 | + * @throws InvalidDataTypeException |
|
85 | + */ |
|
86 | + private function setIdentifier($identifier) |
|
87 | + { |
|
88 | + if (! is_string($identifier)) { |
|
89 | + throw new InvalidDataTypeException('$identifier', $identifier, 'string'); |
|
90 | + } |
|
91 | + $this->identifier = $identifier; |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * @param FullyQualifiedName|string $fqcn |
|
97 | + * @param mixed $object |
|
98 | + * @return bool |
|
99 | + * @throws InvalidArgumentException |
|
100 | + */ |
|
101 | + public function share($fqcn, $object) |
|
102 | + { |
|
103 | + if ($object instanceof $fqcn) { |
|
104 | + return $this->cache->add($object, md5($fqcn)); |
|
105 | + } |
|
106 | + throw new InvalidArgumentException( |
|
107 | + sprintf( |
|
108 | + esc_html__( |
|
109 | + 'The supplied class name "%1$s" must match the class of the supplied object.', |
|
110 | + 'event_espresso' |
|
111 | + ), |
|
112 | + $fqcn |
|
113 | + ) |
|
114 | + ); |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * @param FullyQualifiedName|string $fqcn |
|
120 | + * @param array $arguments |
|
121 | + * @param bool $shared |
|
122 | + * @param array $interfaces |
|
123 | + * @return mixed |
|
124 | + */ |
|
125 | + public function load($fqcn, $arguments = array(), $shared = true, array $interfaces = array()) |
|
126 | + { |
|
127 | + $fqcn = ltrim($fqcn, '\\'); |
|
128 | + // caching can be turned off via the following code: |
|
129 | + // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
|
130 | + if (apply_filters( |
|
131 | + 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
|
132 | + false, |
|
133 | + $this |
|
134 | + )) { |
|
135 | + // even though $shared might be true, caching could be bypassed for whatever reason, |
|
136 | + // so we don't want the core loader to cache anything, therefore caching is turned off |
|
137 | + return $this->loader->load($fqcn, $arguments, false); |
|
138 | + } |
|
139 | + $object_identifier = $this->object_identifier->getIdentifier($fqcn, $arguments); |
|
140 | + if ($this->cache->has($object_identifier)) { |
|
141 | + return $this->cache->get($object_identifier); |
|
142 | + } |
|
143 | + $object = $this->loader->load($fqcn, $arguments, $shared); |
|
144 | + if ($object instanceof $fqcn) { |
|
145 | + $this->cache->add($object, $object_identifier); |
|
146 | + } |
|
147 | + return $object; |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * empties cache and calls reset() on loader if method exists |
|
153 | + */ |
|
154 | + public function reset() |
|
155 | + { |
|
156 | + $this->clearCache(); |
|
157 | + $this->loader->reset(); |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * unsets and detaches ALL objects from the cache |
|
163 | + * |
|
164 | + * @since 4.9.62.p |
|
165 | + */ |
|
166 | + public function clearCache() |
|
167 | + { |
|
168 | + $this->cache->trashAndDetachAll(); |
|
169 | + } |
|
170 | 170 | } |
@@ -17,142 +17,142 @@ |
||
17 | 17 | class JavascriptAsset extends BrowserAsset |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var boolean $load_in_footer |
|
22 | - */ |
|
23 | - private $load_in_footer = false; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var boolean $requires_translation |
|
27 | - */ |
|
28 | - private $requires_translation = false; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var boolean $has_localized_data |
|
32 | - */ |
|
33 | - private $has_localized_data = false; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var Closure $localization_callback |
|
37 | - */ |
|
38 | - private $localization_callback; |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * Asset constructor. |
|
43 | - * |
|
44 | - * @param string $handle |
|
45 | - * @param string $source |
|
46 | - * @param array $dependencies |
|
47 | - * @param bool $load_in_footer |
|
48 | - * @param DomainInterface $domain |
|
49 | - * @throws InvalidDataTypeException |
|
50 | - */ |
|
51 | - public function __construct( |
|
52 | - $handle, |
|
53 | - $source, |
|
54 | - array $dependencies, |
|
55 | - $load_in_footer, |
|
56 | - DomainInterface $domain |
|
57 | - ) { |
|
58 | - parent::__construct(Asset::TYPE_JS, $handle, $source, $dependencies, $domain); |
|
59 | - $this->setLoadInFooter($load_in_footer); |
|
60 | - } |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * @return bool |
|
65 | - */ |
|
66 | - public function loadInFooter() |
|
67 | - { |
|
68 | - return $this->load_in_footer; |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * @param bool $load_in_footer |
|
74 | - */ |
|
75 | - private function setLoadInFooter($load_in_footer = true) |
|
76 | - { |
|
77 | - $this->load_in_footer = filter_var($load_in_footer, FILTER_VALIDATE_BOOLEAN); |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * @return bool |
|
83 | - */ |
|
84 | - public function requiresTranslation() |
|
85 | - { |
|
86 | - return $this->requires_translation; |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * @param bool $requires_translation |
|
92 | - * @return JavascriptAsset |
|
93 | - */ |
|
94 | - public function setRequiresTranslation($requires_translation = true) |
|
95 | - { |
|
96 | - $this->requires_translation = filter_var($requires_translation, FILTER_VALIDATE_BOOLEAN); |
|
97 | - return $this; |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * @return bool |
|
103 | - */ |
|
104 | - public function hasLocalizedData() |
|
105 | - { |
|
106 | - return $this->has_localized_data; |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * @param bool $has_localized_data |
|
112 | - * @return JavascriptAsset |
|
113 | - */ |
|
114 | - public function setHasLocalizedData($has_localized_data = true) |
|
115 | - { |
|
116 | - $this->has_localized_data = filter_var($has_localized_data, FILTER_VALIDATE_BOOLEAN); |
|
117 | - return $this; |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * @return Closure |
|
123 | - */ |
|
124 | - public function localizationCallback() |
|
125 | - { |
|
126 | - return $this->localization_callback; |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * @return bool |
|
132 | - */ |
|
133 | - public function hasLocalizationCallback() |
|
134 | - { |
|
135 | - return $this->localization_callback instanceof Closure; |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * @param Closure $localization_callback |
|
141 | - * @return JavascriptAsset |
|
142 | - */ |
|
143 | - public function setLocalizationCallback(Closure $localization_callback) |
|
144 | - { |
|
145 | - $this->localization_callback = $localization_callback; |
|
146 | - $this->setHasLocalizedData(); |
|
147 | - return $this; |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * @since 4.9.62.p |
|
153 | - */ |
|
154 | - public function enqueueAsset() |
|
155 | - { |
|
156 | - wp_enqueue_script($this->handle()); |
|
157 | - } |
|
20 | + /** |
|
21 | + * @var boolean $load_in_footer |
|
22 | + */ |
|
23 | + private $load_in_footer = false; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var boolean $requires_translation |
|
27 | + */ |
|
28 | + private $requires_translation = false; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var boolean $has_localized_data |
|
32 | + */ |
|
33 | + private $has_localized_data = false; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var Closure $localization_callback |
|
37 | + */ |
|
38 | + private $localization_callback; |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * Asset constructor. |
|
43 | + * |
|
44 | + * @param string $handle |
|
45 | + * @param string $source |
|
46 | + * @param array $dependencies |
|
47 | + * @param bool $load_in_footer |
|
48 | + * @param DomainInterface $domain |
|
49 | + * @throws InvalidDataTypeException |
|
50 | + */ |
|
51 | + public function __construct( |
|
52 | + $handle, |
|
53 | + $source, |
|
54 | + array $dependencies, |
|
55 | + $load_in_footer, |
|
56 | + DomainInterface $domain |
|
57 | + ) { |
|
58 | + parent::__construct(Asset::TYPE_JS, $handle, $source, $dependencies, $domain); |
|
59 | + $this->setLoadInFooter($load_in_footer); |
|
60 | + } |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * @return bool |
|
65 | + */ |
|
66 | + public function loadInFooter() |
|
67 | + { |
|
68 | + return $this->load_in_footer; |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * @param bool $load_in_footer |
|
74 | + */ |
|
75 | + private function setLoadInFooter($load_in_footer = true) |
|
76 | + { |
|
77 | + $this->load_in_footer = filter_var($load_in_footer, FILTER_VALIDATE_BOOLEAN); |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * @return bool |
|
83 | + */ |
|
84 | + public function requiresTranslation() |
|
85 | + { |
|
86 | + return $this->requires_translation; |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * @param bool $requires_translation |
|
92 | + * @return JavascriptAsset |
|
93 | + */ |
|
94 | + public function setRequiresTranslation($requires_translation = true) |
|
95 | + { |
|
96 | + $this->requires_translation = filter_var($requires_translation, FILTER_VALIDATE_BOOLEAN); |
|
97 | + return $this; |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * @return bool |
|
103 | + */ |
|
104 | + public function hasLocalizedData() |
|
105 | + { |
|
106 | + return $this->has_localized_data; |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * @param bool $has_localized_data |
|
112 | + * @return JavascriptAsset |
|
113 | + */ |
|
114 | + public function setHasLocalizedData($has_localized_data = true) |
|
115 | + { |
|
116 | + $this->has_localized_data = filter_var($has_localized_data, FILTER_VALIDATE_BOOLEAN); |
|
117 | + return $this; |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * @return Closure |
|
123 | + */ |
|
124 | + public function localizationCallback() |
|
125 | + { |
|
126 | + return $this->localization_callback; |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * @return bool |
|
132 | + */ |
|
133 | + public function hasLocalizationCallback() |
|
134 | + { |
|
135 | + return $this->localization_callback instanceof Closure; |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * @param Closure $localization_callback |
|
141 | + * @return JavascriptAsset |
|
142 | + */ |
|
143 | + public function setLocalizationCallback(Closure $localization_callback) |
|
144 | + { |
|
145 | + $this->localization_callback = $localization_callback; |
|
146 | + $this->setHasLocalizedData(); |
|
147 | + return $this; |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * @since 4.9.62.p |
|
153 | + */ |
|
154 | + public function enqueueAsset() |
|
155 | + { |
|
156 | + wp_enqueue_script($this->handle()); |
|
157 | + } |
|
158 | 158 | } |
@@ -16,60 +16,60 @@ |
||
16 | 16 | class StylesheetAsset extends BrowserAsset |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @var string $media |
|
21 | - */ |
|
22 | - private $media; |
|
19 | + /** |
|
20 | + * @var string $media |
|
21 | + */ |
|
22 | + private $media; |
|
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * CssFile constructor. |
|
27 | - * |
|
28 | - * @param $handle |
|
29 | - * @param string $source |
|
30 | - * @param array $dependencies |
|
31 | - * @param DomainInterface $domain |
|
32 | - * @param $media |
|
33 | - * @throws InvalidDataTypeException |
|
34 | - */ |
|
35 | - public function __construct($handle, $source, array $dependencies, DomainInterface $domain, $media = 'all') |
|
36 | - { |
|
37 | - parent::__construct(Asset::TYPE_CSS, $handle, $source, $dependencies, $domain); |
|
38 | - $this->setMedia($media); |
|
39 | - } |
|
25 | + /** |
|
26 | + * CssFile constructor. |
|
27 | + * |
|
28 | + * @param $handle |
|
29 | + * @param string $source |
|
30 | + * @param array $dependencies |
|
31 | + * @param DomainInterface $domain |
|
32 | + * @param $media |
|
33 | + * @throws InvalidDataTypeException |
|
34 | + */ |
|
35 | + public function __construct($handle, $source, array $dependencies, DomainInterface $domain, $media = 'all') |
|
36 | + { |
|
37 | + parent::__construct(Asset::TYPE_CSS, $handle, $source, $dependencies, $domain); |
|
38 | + $this->setMedia($media); |
|
39 | + } |
|
40 | 40 | |
41 | 41 | |
42 | - /** |
|
43 | - * @return string |
|
44 | - */ |
|
45 | - public function media() |
|
46 | - { |
|
47 | - return $this->media; |
|
48 | - } |
|
42 | + /** |
|
43 | + * @return string |
|
44 | + */ |
|
45 | + public function media() |
|
46 | + { |
|
47 | + return $this->media; |
|
48 | + } |
|
49 | 49 | |
50 | 50 | |
51 | - /** |
|
52 | - * @param string $media |
|
53 | - * @throws InvalidDataTypeException |
|
54 | - */ |
|
55 | - private function setMedia($media) |
|
56 | - { |
|
57 | - if (! is_string($media)) { |
|
58 | - throw new InvalidDataTypeException( |
|
59 | - '$media', |
|
60 | - $media, |
|
61 | - 'string' |
|
62 | - ); |
|
63 | - } |
|
64 | - $this->media = $media; |
|
65 | - } |
|
51 | + /** |
|
52 | + * @param string $media |
|
53 | + * @throws InvalidDataTypeException |
|
54 | + */ |
|
55 | + private function setMedia($media) |
|
56 | + { |
|
57 | + if (! is_string($media)) { |
|
58 | + throw new InvalidDataTypeException( |
|
59 | + '$media', |
|
60 | + $media, |
|
61 | + 'string' |
|
62 | + ); |
|
63 | + } |
|
64 | + $this->media = $media; |
|
65 | + } |
|
66 | 66 | |
67 | 67 | |
68 | - /** |
|
69 | - * @since 4.9.62.p |
|
70 | - */ |
|
71 | - public function enqueueAsset() |
|
72 | - { |
|
73 | - wp_enqueue_style($this->handle()); |
|
74 | - } |
|
68 | + /** |
|
69 | + * @since 4.9.62.p |
|
70 | + */ |
|
71 | + public function enqueueAsset() |
|
72 | + { |
|
73 | + wp_enqueue_style($this->handle()); |
|
74 | + } |
|
75 | 75 | } |
@@ -16,136 +16,136 @@ |
||
16 | 16 | abstract class BrowserAsset extends Asset |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @var string $source |
|
21 | - */ |
|
22 | - private $source; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var array $dependencies |
|
26 | - */ |
|
27 | - private $dependencies; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var string $version |
|
31 | - */ |
|
32 | - private $version; |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * Asset constructor. |
|
37 | - * |
|
38 | - * @param string $type |
|
39 | - * @param string $handle |
|
40 | - * @param string $source |
|
41 | - * @param array $dependencies |
|
42 | - * @param DomainInterface $domain |
|
43 | - * @throws InvalidDataTypeException |
|
44 | - */ |
|
45 | - public function __construct($type, $handle, $source, array $dependencies, DomainInterface $domain) |
|
46 | - { |
|
47 | - parent::__construct($type, $handle, $domain); |
|
48 | - $this->setSource($source); |
|
49 | - $this->setDependencies($dependencies); |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * @since 4.9.62.p |
|
55 | - */ |
|
56 | - abstract public function enqueueAsset(); |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * @return array |
|
61 | - */ |
|
62 | - public function dependencies() |
|
63 | - { |
|
64 | - return $this->dependencies; |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * @param array $dependencies |
|
70 | - */ |
|
71 | - private function setDependencies(array $dependencies) |
|
72 | - { |
|
73 | - $this->dependencies = $dependencies; |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * @since 4.9.62.p |
|
79 | - * @return bool |
|
80 | - */ |
|
81 | - public function hasDependencies() |
|
82 | - { |
|
83 | - return count($this->dependencies) > 0; |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * @return string |
|
89 | - */ |
|
90 | - public function source() |
|
91 | - { |
|
92 | - return $this->source; |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * @param string $source |
|
98 | - * @throws InvalidDataTypeException |
|
99 | - */ |
|
100 | - private function setSource($source) |
|
101 | - { |
|
102 | - if (! is_string($source)) { |
|
103 | - throw new InvalidDataTypeException( |
|
104 | - '$source', |
|
105 | - $source, |
|
106 | - 'string' |
|
107 | - ); |
|
108 | - } |
|
109 | - $this->source = $source; |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * @return string |
|
115 | - * @throws InvalidDataTypeException |
|
116 | - */ |
|
117 | - public function version() |
|
118 | - { |
|
119 | - // if version is NOT set and this asset was NOT built for distribution, |
|
120 | - // then set the version equal to the EE core plugin version |
|
121 | - if ( |
|
122 | - $this->version === null |
|
123 | - && ( |
|
124 | - substr($this->source, -8) !== Asset::FILE_EXTENSION_DISTRIBUTION_JS |
|
125 | - || substr($this->source, -9) !== Asset::FILE_EXTENSION_DISTRIBUTION_CSS |
|
126 | - ) |
|
127 | - ) { |
|
128 | - $this->setVersion(); |
|
129 | - } |
|
130 | - return $this->version; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * @param string $version |
|
136 | - * @return BrowserAsset |
|
137 | - * @throws InvalidDataTypeException |
|
138 | - */ |
|
139 | - public function setVersion($version = EVENT_ESPRESSO_VERSION) |
|
140 | - { |
|
141 | - if (! is_string($version)) { |
|
142 | - throw new InvalidDataTypeException( |
|
143 | - '$version', |
|
144 | - $version, |
|
145 | - 'string' |
|
146 | - ); |
|
147 | - } |
|
148 | - $this->version = $version; |
|
149 | - return $this; |
|
150 | - } |
|
19 | + /** |
|
20 | + * @var string $source |
|
21 | + */ |
|
22 | + private $source; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var array $dependencies |
|
26 | + */ |
|
27 | + private $dependencies; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var string $version |
|
31 | + */ |
|
32 | + private $version; |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * Asset constructor. |
|
37 | + * |
|
38 | + * @param string $type |
|
39 | + * @param string $handle |
|
40 | + * @param string $source |
|
41 | + * @param array $dependencies |
|
42 | + * @param DomainInterface $domain |
|
43 | + * @throws InvalidDataTypeException |
|
44 | + */ |
|
45 | + public function __construct($type, $handle, $source, array $dependencies, DomainInterface $domain) |
|
46 | + { |
|
47 | + parent::__construct($type, $handle, $domain); |
|
48 | + $this->setSource($source); |
|
49 | + $this->setDependencies($dependencies); |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * @since 4.9.62.p |
|
55 | + */ |
|
56 | + abstract public function enqueueAsset(); |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * @return array |
|
61 | + */ |
|
62 | + public function dependencies() |
|
63 | + { |
|
64 | + return $this->dependencies; |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * @param array $dependencies |
|
70 | + */ |
|
71 | + private function setDependencies(array $dependencies) |
|
72 | + { |
|
73 | + $this->dependencies = $dependencies; |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * @since 4.9.62.p |
|
79 | + * @return bool |
|
80 | + */ |
|
81 | + public function hasDependencies() |
|
82 | + { |
|
83 | + return count($this->dependencies) > 0; |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * @return string |
|
89 | + */ |
|
90 | + public function source() |
|
91 | + { |
|
92 | + return $this->source; |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * @param string $source |
|
98 | + * @throws InvalidDataTypeException |
|
99 | + */ |
|
100 | + private function setSource($source) |
|
101 | + { |
|
102 | + if (! is_string($source)) { |
|
103 | + throw new InvalidDataTypeException( |
|
104 | + '$source', |
|
105 | + $source, |
|
106 | + 'string' |
|
107 | + ); |
|
108 | + } |
|
109 | + $this->source = $source; |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * @return string |
|
115 | + * @throws InvalidDataTypeException |
|
116 | + */ |
|
117 | + public function version() |
|
118 | + { |
|
119 | + // if version is NOT set and this asset was NOT built for distribution, |
|
120 | + // then set the version equal to the EE core plugin version |
|
121 | + if ( |
|
122 | + $this->version === null |
|
123 | + && ( |
|
124 | + substr($this->source, -8) !== Asset::FILE_EXTENSION_DISTRIBUTION_JS |
|
125 | + || substr($this->source, -9) !== Asset::FILE_EXTENSION_DISTRIBUTION_CSS |
|
126 | + ) |
|
127 | + ) { |
|
128 | + $this->setVersion(); |
|
129 | + } |
|
130 | + return $this->version; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * @param string $version |
|
136 | + * @return BrowserAsset |
|
137 | + * @throws InvalidDataTypeException |
|
138 | + */ |
|
139 | + public function setVersion($version = EVENT_ESPRESSO_VERSION) |
|
140 | + { |
|
141 | + if (! is_string($version)) { |
|
142 | + throw new InvalidDataTypeException( |
|
143 | + '$version', |
|
144 | + $version, |
|
145 | + 'string' |
|
146 | + ); |
|
147 | + } |
|
148 | + $this->version = $version; |
|
149 | + return $this; |
|
150 | + } |
|
151 | 151 | } |
@@ -17,97 +17,97 @@ |
||
17 | 17 | class RegisterCustomTaxonomies |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var CustomTaxonomyDefinitions $custom_taxonomies |
|
22 | - */ |
|
23 | - public $custom_taxonomies; |
|
20 | + /** |
|
21 | + * @var CustomTaxonomyDefinitions $custom_taxonomies |
|
22 | + */ |
|
23 | + public $custom_taxonomies; |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * RegisterCustomTaxonomies constructor. |
|
28 | - * |
|
29 | - * @param CustomTaxonomyDefinitions $custom_taxonomies |
|
30 | - */ |
|
31 | - public function __construct(CustomTaxonomyDefinitions $custom_taxonomies) |
|
32 | - { |
|
33 | - $this->custom_taxonomies = $custom_taxonomies; |
|
34 | - } |
|
26 | + /** |
|
27 | + * RegisterCustomTaxonomies constructor. |
|
28 | + * |
|
29 | + * @param CustomTaxonomyDefinitions $custom_taxonomies |
|
30 | + */ |
|
31 | + public function __construct(CustomTaxonomyDefinitions $custom_taxonomies) |
|
32 | + { |
|
33 | + $this->custom_taxonomies = $custom_taxonomies; |
|
34 | + } |
|
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * @return void |
|
39 | - * @throws DomainException |
|
40 | - */ |
|
41 | - public function registerCustomTaxonomies() |
|
42 | - { |
|
43 | - $custom_taxonomies = $this->custom_taxonomies->getCustomTaxonomyDefinitions(); |
|
44 | - foreach ($custom_taxonomies as $taxonomy => $tax) { |
|
45 | - $this->registerCustomTaxonomy( |
|
46 | - $taxonomy, |
|
47 | - $tax['singular_name'], |
|
48 | - $tax['plural_name'], |
|
49 | - $tax['args'] |
|
50 | - ); |
|
51 | - } |
|
52 | - } |
|
37 | + /** |
|
38 | + * @return void |
|
39 | + * @throws DomainException |
|
40 | + */ |
|
41 | + public function registerCustomTaxonomies() |
|
42 | + { |
|
43 | + $custom_taxonomies = $this->custom_taxonomies->getCustomTaxonomyDefinitions(); |
|
44 | + foreach ($custom_taxonomies as $taxonomy => $tax) { |
|
45 | + $this->registerCustomTaxonomy( |
|
46 | + $taxonomy, |
|
47 | + $tax['singular_name'], |
|
48 | + $tax['plural_name'], |
|
49 | + $tax['args'] |
|
50 | + ); |
|
51 | + } |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * Registers a custom taxonomy. Should be called before registering custom post types, |
|
57 | - * otherwise you should link the taxonomy to the custom post type using 'register_taxonomy_for_object_type'. |
|
58 | - * |
|
59 | - * @param string $taxonomy_name , eg 'books' |
|
60 | - * @param string $singular_name internationalized singular name |
|
61 | - * @param string $plural_name internationalized plural name |
|
62 | - * @param array $override_arguments like $args on http://codex.wordpress.org/Function_Reference/register_taxonomy |
|
63 | - * @throws DomainException |
|
64 | - */ |
|
65 | - public function registerCustomTaxonomy($taxonomy_name, $singular_name, $plural_name, array $override_arguments) |
|
66 | - { |
|
67 | - $result = register_taxonomy( |
|
68 | - $taxonomy_name, |
|
69 | - null, |
|
70 | - $this->prepareArguments( |
|
71 | - $singular_name, |
|
72 | - $plural_name, |
|
73 | - $override_arguments |
|
74 | - ) |
|
75 | - ); |
|
76 | - if ($result instanceof WP_Error) { |
|
77 | - throw new DomainException($result->get_error_message()); |
|
78 | - } |
|
79 | - } |
|
55 | + /** |
|
56 | + * Registers a custom taxonomy. Should be called before registering custom post types, |
|
57 | + * otherwise you should link the taxonomy to the custom post type using 'register_taxonomy_for_object_type'. |
|
58 | + * |
|
59 | + * @param string $taxonomy_name , eg 'books' |
|
60 | + * @param string $singular_name internationalized singular name |
|
61 | + * @param string $plural_name internationalized plural name |
|
62 | + * @param array $override_arguments like $args on http://codex.wordpress.org/Function_Reference/register_taxonomy |
|
63 | + * @throws DomainException |
|
64 | + */ |
|
65 | + public function registerCustomTaxonomy($taxonomy_name, $singular_name, $plural_name, array $override_arguments) |
|
66 | + { |
|
67 | + $result = register_taxonomy( |
|
68 | + $taxonomy_name, |
|
69 | + null, |
|
70 | + $this->prepareArguments( |
|
71 | + $singular_name, |
|
72 | + $plural_name, |
|
73 | + $override_arguments |
|
74 | + ) |
|
75 | + ); |
|
76 | + if ($result instanceof WP_Error) { |
|
77 | + throw new DomainException($result->get_error_message()); |
|
78 | + } |
|
79 | + } |
|
80 | 80 | |
81 | 81 | |
82 | - /** |
|
83 | - * @param string $singular_name |
|
84 | - * @param string $plural_name |
|
85 | - * @param array $override_arguments |
|
86 | - * @since 4.9.62.p |
|
87 | - * @return array |
|
88 | - */ |
|
89 | - protected function prepareArguments($singular_name, $plural_name, array $override_arguments) |
|
90 | - { |
|
91 | - $arguments = array( |
|
92 | - 'hierarchical' => true, |
|
93 | - 'labels' => array( |
|
94 | - 'name' => $plural_name, |
|
95 | - 'singular_name' => $singular_name, |
|
96 | - ), |
|
97 | - 'show_ui' => true, |
|
98 | - 'show_ee_ui' => true, |
|
99 | - 'show_admin_column' => true, |
|
100 | - 'query_var' => true, |
|
101 | - 'show_in_nav_menus' => false, |
|
102 | - 'map_meta_cap' => true, |
|
103 | - ); |
|
104 | - if ($override_arguments) { |
|
105 | - if (isset($override_args['labels'])) { |
|
106 | - $labels = array_merge($arguments['labels'], $override_arguments['labels']); |
|
107 | - $arguments['labels'] = $labels; |
|
108 | - } |
|
109 | - $arguments = array_merge($arguments, $override_arguments); |
|
110 | - } |
|
111 | - return $arguments; |
|
112 | - } |
|
82 | + /** |
|
83 | + * @param string $singular_name |
|
84 | + * @param string $plural_name |
|
85 | + * @param array $override_arguments |
|
86 | + * @since 4.9.62.p |
|
87 | + * @return array |
|
88 | + */ |
|
89 | + protected function prepareArguments($singular_name, $plural_name, array $override_arguments) |
|
90 | + { |
|
91 | + $arguments = array( |
|
92 | + 'hierarchical' => true, |
|
93 | + 'labels' => array( |
|
94 | + 'name' => $plural_name, |
|
95 | + 'singular_name' => $singular_name, |
|
96 | + ), |
|
97 | + 'show_ui' => true, |
|
98 | + 'show_ee_ui' => true, |
|
99 | + 'show_admin_column' => true, |
|
100 | + 'query_var' => true, |
|
101 | + 'show_in_nav_menus' => false, |
|
102 | + 'map_meta_cap' => true, |
|
103 | + ); |
|
104 | + if ($override_arguments) { |
|
105 | + if (isset($override_args['labels'])) { |
|
106 | + $labels = array_merge($arguments['labels'], $override_arguments['labels']); |
|
107 | + $arguments['labels'] = $labels; |
|
108 | + } |
|
109 | + $arguments = array_merge($arguments, $override_arguments); |
|
110 | + } |
|
111 | + return $arguments; |
|
112 | + } |
|
113 | 113 | } |
@@ -27,329 +27,329 @@ |
||
27 | 27 | class CoreAssetManager extends AssetManager |
28 | 28 | { |
29 | 29 | |
30 | - // WordPress core / Third party JS asset handles |
|
31 | - const JS_HANDLE_JQUERY = 'jquery'; |
|
32 | - |
|
33 | - const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate'; |
|
34 | - |
|
35 | - const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods'; |
|
36 | - |
|
37 | - const JS_HANDLE_UNDERSCORE = 'underscore'; |
|
38 | - |
|
39 | - const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core'; |
|
40 | - |
|
41 | - // EE JS assets handles |
|
42 | - const JS_HANDLE_EE_MANIFEST = 'ee-manifest'; |
|
43 | - |
|
44 | - const JS_HANDLE_EE_JS_CORE = 'eejs-core'; |
|
45 | - |
|
46 | - const JS_HANDLE_EE_VENDOR_REACT = 'ee-vendor-react'; |
|
47 | - |
|
48 | - const JS_HANDLE_EE_JS_API = 'eejs-api'; |
|
49 | - |
|
50 | - const JS_HANDLE_EE_CORE = 'espresso_core'; |
|
51 | - |
|
52 | - const JS_HANDLE_EE_I18N = 'eei18n'; |
|
53 | - |
|
54 | - const JS_HANDLE_EE_ACCOUNTING = 'ee-accounting'; |
|
55 | - |
|
56 | - const JS_HANDLE_EE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page'; |
|
57 | - |
|
58 | - // EE CSS assets handles |
|
59 | - const CSS_HANDLE_EE_DEFAULT = 'espresso_default'; |
|
60 | - |
|
61 | - const CSS_HANDLE_EE_CUSTOM = 'espresso_custom_css'; |
|
62 | - |
|
63 | - /** |
|
64 | - * @var EE_Currency_Config $currency_config |
|
65 | - */ |
|
66 | - protected $currency_config; |
|
67 | - |
|
68 | - /** |
|
69 | - * @var EE_Template_Config $template_config |
|
70 | - */ |
|
71 | - protected $template_config; |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * CoreAssetRegister constructor. |
|
76 | - * |
|
77 | - * @param AssetCollection $assets |
|
78 | - * @param EE_Currency_Config $currency_config |
|
79 | - * @param EE_Template_Config $template_config |
|
80 | - * @param DomainInterface $domain |
|
81 | - * @param Registry $registry |
|
82 | - */ |
|
83 | - public function __construct( |
|
84 | - AssetCollection $assets, |
|
85 | - EE_Currency_Config $currency_config, |
|
86 | - EE_Template_Config $template_config, |
|
87 | - DomainInterface $domain, |
|
88 | - Registry $registry |
|
89 | - ) { |
|
90 | - $this->currency_config = $currency_config; |
|
91 | - $this->template_config = $template_config; |
|
92 | - parent::__construct($domain, $assets, $registry); |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * @since 4.9.62.p |
|
98 | - * @throws DuplicateCollectionIdentifierException |
|
99 | - * @throws InvalidArgumentException |
|
100 | - * @throws InvalidDataTypeException |
|
101 | - * @throws InvalidEntityException |
|
102 | - */ |
|
103 | - public function addAssets() |
|
104 | - { |
|
105 | - $this->addJavascriptFiles(); |
|
106 | - $this->addStylesheetFiles(); |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * @since 4.9.62.p |
|
112 | - * @throws DuplicateCollectionIdentifierException |
|
113 | - * @throws InvalidArgumentException |
|
114 | - * @throws InvalidDataTypeException |
|
115 | - * @throws InvalidEntityException |
|
116 | - */ |
|
117 | - public function addJavascriptFiles() |
|
118 | - { |
|
119 | - $this->loadCoreJs(); |
|
120 | - $this->loadJqueryValidate(); |
|
121 | - $this->loadAccountingJs(); |
|
122 | - add_action( |
|
123 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script', |
|
124 | - array($this, 'loadQtipJs') |
|
125 | - ); |
|
126 | - $this->registerAdminAssets(); |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * @since 4.9.62.p |
|
132 | - * @throws DuplicateCollectionIdentifierException |
|
133 | - * @throws InvalidDataTypeException |
|
134 | - * @throws InvalidEntityException |
|
135 | - */ |
|
136 | - public function addStylesheetFiles() |
|
137 | - { |
|
138 | - $this->loadCoreCss(); |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * core default javascript |
|
144 | - * |
|
145 | - * @since 4.9.62.p |
|
146 | - * @throws DuplicateCollectionIdentifierException |
|
147 | - * @throws InvalidArgumentException |
|
148 | - * @throws InvalidDataTypeException |
|
149 | - * @throws InvalidEntityException |
|
150 | - */ |
|
151 | - private function loadCoreJs() |
|
152 | - { |
|
153 | - $this->addJavascript( |
|
154 | - CoreAssetManager::JS_HANDLE_EE_MANIFEST, |
|
155 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'manifest') |
|
156 | - ); |
|
157 | - |
|
158 | - $this->addJavascript( |
|
159 | - CoreAssetManager::JS_HANDLE_EE_JS_CORE, |
|
160 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'eejs'), |
|
161 | - array(CoreAssetManager::JS_HANDLE_EE_MANIFEST) |
|
162 | - ) |
|
163 | - ->setHasLocalizedData(); |
|
164 | - |
|
165 | - $this->addJavascript( |
|
166 | - CoreAssetManager::JS_HANDLE_EE_VENDOR_REACT, |
|
167 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'reactVendor'), |
|
168 | - array(CoreAssetManager::JS_HANDLE_EE_JS_CORE) |
|
169 | - ); |
|
170 | - |
|
171 | - global $wp_version; |
|
172 | - if (version_compare($wp_version, '4.4.0', '>')) { |
|
173 | - //js.api |
|
174 | - $this->addJavascript( |
|
175 | - CoreAssetManager::JS_HANDLE_EE_JS_API, |
|
176 | - EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
177 | - array( |
|
178 | - CoreAssetManager::JS_HANDLE_UNDERSCORE, |
|
179 | - CoreAssetManager::JS_HANDLE_EE_JS_CORE |
|
180 | - ) |
|
181 | - ); |
|
182 | - $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest')); |
|
183 | - $this->registry->addData('paths', array('rest_route' => rest_url('ee/v4.8.36/'))); |
|
184 | - } |
|
185 | - |
|
186 | - $this->addJavascript( |
|
187 | - CoreAssetManager::JS_HANDLE_EE_CORE, |
|
188 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
189 | - array(CoreAssetManager::JS_HANDLE_JQUERY) |
|
190 | - ) |
|
191 | - ->setLocalizationCallback( |
|
192 | - function () { |
|
193 | - wp_localize_script( |
|
194 | - CoreAssetManager::JS_HANDLE_EE_CORE, |
|
195 | - CoreAssetManager::JS_HANDLE_EE_I18N, |
|
196 | - EE_Registry::$i18n_js_strings |
|
197 | - ); |
|
198 | - } |
|
199 | - ); |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * @since 4.9.62.p |
|
205 | - * @throws DuplicateCollectionIdentifierException |
|
206 | - * @throws InvalidDataTypeException |
|
207 | - * @throws InvalidEntityException |
|
208 | - */ |
|
209 | - private function loadCoreCss() |
|
210 | - { |
|
211 | - if ($this->template_config->enable_default_style && ! is_admin()) { |
|
212 | - $this->addStylesheet( |
|
213 | - CoreAssetManager::CSS_HANDLE_EE_DEFAULT, |
|
214 | - is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
215 | - ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
216 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
217 | - array('dashicons') |
|
218 | - ); |
|
219 | - //Load custom style sheet if available |
|
220 | - if ($this->template_config->custom_style_sheet !== null) { |
|
221 | - $this->addStylesheet( |
|
222 | - CoreAssetManager::CSS_HANDLE_EE_CUSTOM, |
|
223 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
224 | - array(CoreAssetManager::CSS_HANDLE_EE_DEFAULT) |
|
225 | - ); |
|
226 | - } |
|
227 | - } |
|
228 | - } |
|
229 | - |
|
230 | - |
|
231 | - /** |
|
232 | - * jQuery Validate for form validation |
|
233 | - * |
|
234 | - * @since 4.9.62.p |
|
235 | - * @throws DuplicateCollectionIdentifierException |
|
236 | - * @throws InvalidDataTypeException |
|
237 | - * @throws InvalidEntityException |
|
238 | - */ |
|
239 | - private function loadJqueryValidate() |
|
240 | - { |
|
241 | - $this->addJavascript( |
|
242 | - CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE, |
|
243 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
244 | - array(CoreAssetManager::JS_HANDLE_JQUERY) |
|
245 | - ) |
|
246 | - ->setVersion('1.15.0'); |
|
247 | - |
|
248 | - $this->addJavascript( |
|
249 | - CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA, |
|
250 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
251 | - array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE) |
|
252 | - ) |
|
253 | - ->setVersion('1.15.0'); |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * accounting.js for performing client-side calculations |
|
259 | - * |
|
260 | - * @since 4.9.62.p |
|
261 | - * @throws DuplicateCollectionIdentifierException |
|
262 | - * @throws InvalidDataTypeException |
|
263 | - * @throws InvalidEntityException |
|
264 | - */ |
|
265 | - private function loadAccountingJs() |
|
266 | - { |
|
267 | - //accounting.js library |
|
268 | - // @link http://josscrowcroft.github.io/accounting.js/ |
|
269 | - $this->addJavascript( |
|
270 | - CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE, |
|
271 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
272 | - array(CoreAssetManager::JS_HANDLE_UNDERSCORE) |
|
273 | - ) |
|
274 | - ->setVersion('0.3.2'); |
|
275 | - |
|
276 | - $currency_config = $this->currency_config; |
|
277 | - $this->addJavascript( |
|
278 | - CoreAssetManager::JS_HANDLE_EE_ACCOUNTING, |
|
279 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
280 | - array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE) |
|
281 | - ) |
|
282 | - ->setLocalizationCallback( |
|
283 | - function () use ($currency_config) { |
|
284 | - wp_localize_script( |
|
285 | - CoreAssetManager::JS_HANDLE_EE_ACCOUNTING, |
|
286 | - 'EE_ACCOUNTING_CFG', |
|
287 | - array( |
|
288 | - 'currency' => array( |
|
289 | - 'symbol' => $currency_config->sign, |
|
290 | - 'format' => array( |
|
291 | - 'pos' => $currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
292 | - 'neg' => $currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
293 | - 'zero' => $currency_config->sign_b4 ? '%s--' : '--%s', |
|
294 | - ), |
|
295 | - 'decimal' => $currency_config->dec_mrk, |
|
296 | - 'thousand' => $currency_config->thsnds, |
|
297 | - 'precision' => $currency_config->dec_plc, |
|
298 | - ), |
|
299 | - 'number' => array( |
|
300 | - 'precision' => $currency_config->dec_plc, |
|
301 | - 'thousand' => $currency_config->thsnds, |
|
302 | - 'decimal' => $currency_config->dec_mrk, |
|
303 | - ), |
|
304 | - ) |
|
305 | - ); |
|
306 | - } |
|
307 | - ) |
|
308 | - ->setVersion(); |
|
309 | - } |
|
310 | - |
|
311 | - |
|
312 | - /** |
|
313 | - * registers assets for cleaning your ears |
|
314 | - * |
|
315 | - * @param JavascriptAsset $script |
|
316 | - */ |
|
317 | - public function loadQtipJs(JavascriptAsset $script) |
|
318 | - { |
|
319 | - // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
320 | - // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
321 | - if ( |
|
322 | - $script->handle() === CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE |
|
323 | - && apply_filters('FHEE_load_qtip', false) |
|
324 | - ) { |
|
325 | - EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
326 | - } |
|
327 | - } |
|
328 | - |
|
329 | - |
|
330 | - /** |
|
331 | - * assets that are used in the WordPress admin |
|
332 | - * |
|
333 | - * @since 4.9.62.p |
|
334 | - * @throws DuplicateCollectionIdentifierException |
|
335 | - * @throws InvalidDataTypeException |
|
336 | - * @throws InvalidEntityException |
|
337 | - */ |
|
338 | - private function registerAdminAssets() |
|
339 | - { |
|
340 | - $this->addJavascript( |
|
341 | - CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE, |
|
342 | - $this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'), |
|
343 | - array( |
|
344 | - CoreAssetManager::JS_HANDLE_JQUERY, |
|
345 | - CoreAssetManager::JS_HANDLE_EE_VENDOR_REACT, |
|
346 | - ) |
|
347 | - ) |
|
348 | - ->setRequiresTranslation(); |
|
349 | - |
|
350 | - $this->addStylesheet( |
|
351 | - CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE, |
|
352 | - $this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page') |
|
353 | - ); |
|
354 | - } |
|
30 | + // WordPress core / Third party JS asset handles |
|
31 | + const JS_HANDLE_JQUERY = 'jquery'; |
|
32 | + |
|
33 | + const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate'; |
|
34 | + |
|
35 | + const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods'; |
|
36 | + |
|
37 | + const JS_HANDLE_UNDERSCORE = 'underscore'; |
|
38 | + |
|
39 | + const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core'; |
|
40 | + |
|
41 | + // EE JS assets handles |
|
42 | + const JS_HANDLE_EE_MANIFEST = 'ee-manifest'; |
|
43 | + |
|
44 | + const JS_HANDLE_EE_JS_CORE = 'eejs-core'; |
|
45 | + |
|
46 | + const JS_HANDLE_EE_VENDOR_REACT = 'ee-vendor-react'; |
|
47 | + |
|
48 | + const JS_HANDLE_EE_JS_API = 'eejs-api'; |
|
49 | + |
|
50 | + const JS_HANDLE_EE_CORE = 'espresso_core'; |
|
51 | + |
|
52 | + const JS_HANDLE_EE_I18N = 'eei18n'; |
|
53 | + |
|
54 | + const JS_HANDLE_EE_ACCOUNTING = 'ee-accounting'; |
|
55 | + |
|
56 | + const JS_HANDLE_EE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page'; |
|
57 | + |
|
58 | + // EE CSS assets handles |
|
59 | + const CSS_HANDLE_EE_DEFAULT = 'espresso_default'; |
|
60 | + |
|
61 | + const CSS_HANDLE_EE_CUSTOM = 'espresso_custom_css'; |
|
62 | + |
|
63 | + /** |
|
64 | + * @var EE_Currency_Config $currency_config |
|
65 | + */ |
|
66 | + protected $currency_config; |
|
67 | + |
|
68 | + /** |
|
69 | + * @var EE_Template_Config $template_config |
|
70 | + */ |
|
71 | + protected $template_config; |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * CoreAssetRegister constructor. |
|
76 | + * |
|
77 | + * @param AssetCollection $assets |
|
78 | + * @param EE_Currency_Config $currency_config |
|
79 | + * @param EE_Template_Config $template_config |
|
80 | + * @param DomainInterface $domain |
|
81 | + * @param Registry $registry |
|
82 | + */ |
|
83 | + public function __construct( |
|
84 | + AssetCollection $assets, |
|
85 | + EE_Currency_Config $currency_config, |
|
86 | + EE_Template_Config $template_config, |
|
87 | + DomainInterface $domain, |
|
88 | + Registry $registry |
|
89 | + ) { |
|
90 | + $this->currency_config = $currency_config; |
|
91 | + $this->template_config = $template_config; |
|
92 | + parent::__construct($domain, $assets, $registry); |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * @since 4.9.62.p |
|
98 | + * @throws DuplicateCollectionIdentifierException |
|
99 | + * @throws InvalidArgumentException |
|
100 | + * @throws InvalidDataTypeException |
|
101 | + * @throws InvalidEntityException |
|
102 | + */ |
|
103 | + public function addAssets() |
|
104 | + { |
|
105 | + $this->addJavascriptFiles(); |
|
106 | + $this->addStylesheetFiles(); |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * @since 4.9.62.p |
|
112 | + * @throws DuplicateCollectionIdentifierException |
|
113 | + * @throws InvalidArgumentException |
|
114 | + * @throws InvalidDataTypeException |
|
115 | + * @throws InvalidEntityException |
|
116 | + */ |
|
117 | + public function addJavascriptFiles() |
|
118 | + { |
|
119 | + $this->loadCoreJs(); |
|
120 | + $this->loadJqueryValidate(); |
|
121 | + $this->loadAccountingJs(); |
|
122 | + add_action( |
|
123 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script', |
|
124 | + array($this, 'loadQtipJs') |
|
125 | + ); |
|
126 | + $this->registerAdminAssets(); |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * @since 4.9.62.p |
|
132 | + * @throws DuplicateCollectionIdentifierException |
|
133 | + * @throws InvalidDataTypeException |
|
134 | + * @throws InvalidEntityException |
|
135 | + */ |
|
136 | + public function addStylesheetFiles() |
|
137 | + { |
|
138 | + $this->loadCoreCss(); |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * core default javascript |
|
144 | + * |
|
145 | + * @since 4.9.62.p |
|
146 | + * @throws DuplicateCollectionIdentifierException |
|
147 | + * @throws InvalidArgumentException |
|
148 | + * @throws InvalidDataTypeException |
|
149 | + * @throws InvalidEntityException |
|
150 | + */ |
|
151 | + private function loadCoreJs() |
|
152 | + { |
|
153 | + $this->addJavascript( |
|
154 | + CoreAssetManager::JS_HANDLE_EE_MANIFEST, |
|
155 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'manifest') |
|
156 | + ); |
|
157 | + |
|
158 | + $this->addJavascript( |
|
159 | + CoreAssetManager::JS_HANDLE_EE_JS_CORE, |
|
160 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'eejs'), |
|
161 | + array(CoreAssetManager::JS_HANDLE_EE_MANIFEST) |
|
162 | + ) |
|
163 | + ->setHasLocalizedData(); |
|
164 | + |
|
165 | + $this->addJavascript( |
|
166 | + CoreAssetManager::JS_HANDLE_EE_VENDOR_REACT, |
|
167 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'reactVendor'), |
|
168 | + array(CoreAssetManager::JS_HANDLE_EE_JS_CORE) |
|
169 | + ); |
|
170 | + |
|
171 | + global $wp_version; |
|
172 | + if (version_compare($wp_version, '4.4.0', '>')) { |
|
173 | + //js.api |
|
174 | + $this->addJavascript( |
|
175 | + CoreAssetManager::JS_HANDLE_EE_JS_API, |
|
176 | + EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
177 | + array( |
|
178 | + CoreAssetManager::JS_HANDLE_UNDERSCORE, |
|
179 | + CoreAssetManager::JS_HANDLE_EE_JS_CORE |
|
180 | + ) |
|
181 | + ); |
|
182 | + $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest')); |
|
183 | + $this->registry->addData('paths', array('rest_route' => rest_url('ee/v4.8.36/'))); |
|
184 | + } |
|
185 | + |
|
186 | + $this->addJavascript( |
|
187 | + CoreAssetManager::JS_HANDLE_EE_CORE, |
|
188 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
189 | + array(CoreAssetManager::JS_HANDLE_JQUERY) |
|
190 | + ) |
|
191 | + ->setLocalizationCallback( |
|
192 | + function () { |
|
193 | + wp_localize_script( |
|
194 | + CoreAssetManager::JS_HANDLE_EE_CORE, |
|
195 | + CoreAssetManager::JS_HANDLE_EE_I18N, |
|
196 | + EE_Registry::$i18n_js_strings |
|
197 | + ); |
|
198 | + } |
|
199 | + ); |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * @since 4.9.62.p |
|
205 | + * @throws DuplicateCollectionIdentifierException |
|
206 | + * @throws InvalidDataTypeException |
|
207 | + * @throws InvalidEntityException |
|
208 | + */ |
|
209 | + private function loadCoreCss() |
|
210 | + { |
|
211 | + if ($this->template_config->enable_default_style && ! is_admin()) { |
|
212 | + $this->addStylesheet( |
|
213 | + CoreAssetManager::CSS_HANDLE_EE_DEFAULT, |
|
214 | + is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
215 | + ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
216 | + : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
217 | + array('dashicons') |
|
218 | + ); |
|
219 | + //Load custom style sheet if available |
|
220 | + if ($this->template_config->custom_style_sheet !== null) { |
|
221 | + $this->addStylesheet( |
|
222 | + CoreAssetManager::CSS_HANDLE_EE_CUSTOM, |
|
223 | + EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
224 | + array(CoreAssetManager::CSS_HANDLE_EE_DEFAULT) |
|
225 | + ); |
|
226 | + } |
|
227 | + } |
|
228 | + } |
|
229 | + |
|
230 | + |
|
231 | + /** |
|
232 | + * jQuery Validate for form validation |
|
233 | + * |
|
234 | + * @since 4.9.62.p |
|
235 | + * @throws DuplicateCollectionIdentifierException |
|
236 | + * @throws InvalidDataTypeException |
|
237 | + * @throws InvalidEntityException |
|
238 | + */ |
|
239 | + private function loadJqueryValidate() |
|
240 | + { |
|
241 | + $this->addJavascript( |
|
242 | + CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE, |
|
243 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
244 | + array(CoreAssetManager::JS_HANDLE_JQUERY) |
|
245 | + ) |
|
246 | + ->setVersion('1.15.0'); |
|
247 | + |
|
248 | + $this->addJavascript( |
|
249 | + CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA, |
|
250 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
251 | + array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE) |
|
252 | + ) |
|
253 | + ->setVersion('1.15.0'); |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * accounting.js for performing client-side calculations |
|
259 | + * |
|
260 | + * @since 4.9.62.p |
|
261 | + * @throws DuplicateCollectionIdentifierException |
|
262 | + * @throws InvalidDataTypeException |
|
263 | + * @throws InvalidEntityException |
|
264 | + */ |
|
265 | + private function loadAccountingJs() |
|
266 | + { |
|
267 | + //accounting.js library |
|
268 | + // @link http://josscrowcroft.github.io/accounting.js/ |
|
269 | + $this->addJavascript( |
|
270 | + CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE, |
|
271 | + EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
272 | + array(CoreAssetManager::JS_HANDLE_UNDERSCORE) |
|
273 | + ) |
|
274 | + ->setVersion('0.3.2'); |
|
275 | + |
|
276 | + $currency_config = $this->currency_config; |
|
277 | + $this->addJavascript( |
|
278 | + CoreAssetManager::JS_HANDLE_EE_ACCOUNTING, |
|
279 | + EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
280 | + array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE) |
|
281 | + ) |
|
282 | + ->setLocalizationCallback( |
|
283 | + function () use ($currency_config) { |
|
284 | + wp_localize_script( |
|
285 | + CoreAssetManager::JS_HANDLE_EE_ACCOUNTING, |
|
286 | + 'EE_ACCOUNTING_CFG', |
|
287 | + array( |
|
288 | + 'currency' => array( |
|
289 | + 'symbol' => $currency_config->sign, |
|
290 | + 'format' => array( |
|
291 | + 'pos' => $currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
292 | + 'neg' => $currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
293 | + 'zero' => $currency_config->sign_b4 ? '%s--' : '--%s', |
|
294 | + ), |
|
295 | + 'decimal' => $currency_config->dec_mrk, |
|
296 | + 'thousand' => $currency_config->thsnds, |
|
297 | + 'precision' => $currency_config->dec_plc, |
|
298 | + ), |
|
299 | + 'number' => array( |
|
300 | + 'precision' => $currency_config->dec_plc, |
|
301 | + 'thousand' => $currency_config->thsnds, |
|
302 | + 'decimal' => $currency_config->dec_mrk, |
|
303 | + ), |
|
304 | + ) |
|
305 | + ); |
|
306 | + } |
|
307 | + ) |
|
308 | + ->setVersion(); |
|
309 | + } |
|
310 | + |
|
311 | + |
|
312 | + /** |
|
313 | + * registers assets for cleaning your ears |
|
314 | + * |
|
315 | + * @param JavascriptAsset $script |
|
316 | + */ |
|
317 | + public function loadQtipJs(JavascriptAsset $script) |
|
318 | + { |
|
319 | + // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
320 | + // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
321 | + if ( |
|
322 | + $script->handle() === CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE |
|
323 | + && apply_filters('FHEE_load_qtip', false) |
|
324 | + ) { |
|
325 | + EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
326 | + } |
|
327 | + } |
|
328 | + |
|
329 | + |
|
330 | + /** |
|
331 | + * assets that are used in the WordPress admin |
|
332 | + * |
|
333 | + * @since 4.9.62.p |
|
334 | + * @throws DuplicateCollectionIdentifierException |
|
335 | + * @throws InvalidDataTypeException |
|
336 | + * @throws InvalidEntityException |
|
337 | + */ |
|
338 | + private function registerAdminAssets() |
|
339 | + { |
|
340 | + $this->addJavascript( |
|
341 | + CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE, |
|
342 | + $this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'), |
|
343 | + array( |
|
344 | + CoreAssetManager::JS_HANDLE_JQUERY, |
|
345 | + CoreAssetManager::JS_HANDLE_EE_VENDOR_REACT, |
|
346 | + ) |
|
347 | + ) |
|
348 | + ->setRequiresTranslation(); |
|
349 | + |
|
350 | + $this->addStylesheet( |
|
351 | + CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE, |
|
352 | + $this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page') |
|
353 | + ); |
|
354 | + } |
|
355 | 355 | } |
@@ -19,303 +19,303 @@ discard block |
||
19 | 19 | { |
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * instantiated at init priority 5 |
|
24 | - * |
|
25 | - * @deprecated 4.9.62.p |
|
26 | - */ |
|
27 | - public function __construct() |
|
28 | - { |
|
29 | - do_action('AHEE__EE_Register_CPTs__construct_end', $this); |
|
30 | - } |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * This will flush rewrite rules on demand. This actually gets called around wp init priority level 100. |
|
35 | - * |
|
36 | - * @deprecated 4.9.62.p |
|
37 | - * @return void |
|
38 | - * @throws InvalidInterfaceException |
|
39 | - * @throws InvalidDataTypeException |
|
40 | - * @throws InvalidArgumentException |
|
41 | - */ |
|
42 | - public static function maybe_flush_rewrite_rules() |
|
43 | - { |
|
44 | - /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
45 | - $rewrite_rules = LoaderFactory::getLoader()->getShared( |
|
46 | - 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
47 | - ); |
|
48 | - $rewrite_rules->flushRewriteRules(); |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * @return CustomTaxonomyDefinitions |
|
54 | - * @throws InvalidArgumentException |
|
55 | - * @throws InvalidDataTypeException |
|
56 | - * @throws InvalidInterfaceException |
|
57 | - */ |
|
58 | - public static function getTaxonomyDefinitions() |
|
59 | - { |
|
60 | - return LoaderFactory::getLoader()->getShared( |
|
61 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' |
|
62 | - ); |
|
63 | - } |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * @deprecated 4.9.62.p |
|
68 | - * @param string $description The description content. |
|
69 | - * @param string $taxonomy The taxonomy name for the taxonomy being filtered. |
|
70 | - * @return string |
|
71 | - * @throws InvalidArgumentException |
|
72 | - * @throws InvalidDataTypeException |
|
73 | - * @throws InvalidInterfaceException |
|
74 | - */ |
|
75 | - public function ee_filter_ee_term_description_not_wp($description, $taxonomy) |
|
76 | - { |
|
77 | - $taxonomies = EE_Register_CPTs::getTaxonomyDefinitions(); |
|
78 | - return $taxonomies->filterCustomTermDescription($description, $taxonomy); |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @deprecated 4.9.62.p |
|
84 | - * @return array |
|
85 | - * @throws InvalidArgumentException |
|
86 | - * @throws InvalidDataTypeException |
|
87 | - * @throws InvalidInterfaceException |
|
88 | - */ |
|
89 | - public static function get_taxonomies() |
|
90 | - { |
|
91 | - $taxonomies = EE_Register_CPTs::getTaxonomyDefinitions(); |
|
92 | - return $taxonomies->getCustomTaxonomyDefinitions(); |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * @return CustomPostTypeDefinitions |
|
98 | - * @throws InvalidArgumentException |
|
99 | - * @throws InvalidDataTypeException |
|
100 | - * @throws InvalidInterfaceException |
|
101 | - */ |
|
102 | - public static function getCustomPostTypeDefinitions() |
|
103 | - { |
|
104 | - return LoaderFactory::getLoader()->getShared( |
|
105 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
106 | - ); |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * @deprecated 4.9.62.p |
|
112 | - * @return array |
|
113 | - * @throws InvalidArgumentException |
|
114 | - * @throws InvalidDataTypeException |
|
115 | - * @throws InvalidInterfaceException |
|
116 | - */ |
|
117 | - public static function get_CPTs() |
|
118 | - { |
|
119 | - $custom_post_types = EE_Register_CPTs::getCustomPostTypeDefinitions(); |
|
120 | - return $custom_post_types->getDefinitions(); |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * @deprecated 4.9.62.p |
|
126 | - * @return array |
|
127 | - * @throws InvalidArgumentException |
|
128 | - * @throws InvalidDataTypeException |
|
129 | - * @throws InvalidInterfaceException |
|
130 | - */ |
|
131 | - public static function get_private_CPTs() |
|
132 | - { |
|
133 | - $custom_post_types = EE_Register_CPTs::getCustomPostTypeDefinitions(); |
|
134 | - return $custom_post_types->getPrivateCustomPostTypes(); |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * @deprecated 4.9.62.p |
|
140 | - * @param string $post_type_slug If a slug is included, then attempt to retrieve the model name for |
|
141 | - * the given cpt slug. Otherwise if empty, then we'll return all cpt |
|
142 | - * model names for cpts registered in EE. |
|
143 | - * @return array Empty array if no matching model names for the given slug or an array of model |
|
144 | - * names indexed by post type slug. |
|
145 | - * @throws InvalidArgumentException |
|
146 | - * @throws InvalidDataTypeException |
|
147 | - * @throws InvalidInterfaceException |
|
148 | - */ |
|
149 | - public static function get_cpt_model_names($post_type_slug = '') |
|
150 | - { |
|
151 | - $custom_post_types = EE_Register_CPTs::getCustomPostTypeDefinitions(); |
|
152 | - return $custom_post_types->getCustomPostTypeModelNames($post_type_slug); |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * @deprecated 4.9.62.p |
|
158 | - * @param string $post_type_slug If valid slug is provided, then will instantiate the model only for |
|
159 | - * the cpt matching the given slug. Otherwise all cpt models will be |
|
160 | - * instantiated (if possible). |
|
161 | - * @return EEM_CPT_Base[] successful instantiation will return an array of successfully instantiated |
|
162 | - * EEM models indexed by post slug. |
|
163 | - * @throws InvalidArgumentException |
|
164 | - * @throws InvalidDataTypeException |
|
165 | - * @throws InvalidInterfaceException |
|
166 | - */ |
|
167 | - public static function instantiate_cpt_models($post_type_slug = '') |
|
168 | - { |
|
169 | - $custom_post_types = EE_Register_CPTs::getCustomPostTypeDefinitions(); |
|
170 | - return $custom_post_types->getCustomPostTypeModels($post_type_slug); |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * @deprecated 4.9.62.p |
|
176 | - * @param string $taxonomy_name , eg 'books' |
|
177 | - * @param string $singular_name internationalized singular name |
|
178 | - * @param string $plural_name internationalized plural name |
|
179 | - * @param array $override_args like $args on http://codex.wordpress.org/Function_Reference/register_taxonomy |
|
180 | - * @throws InvalidArgumentException |
|
181 | - * @throws InvalidDataTypeException |
|
182 | - * @throws InvalidInterfaceException |
|
183 | - * @throws DomainException |
|
184 | - */ |
|
185 | - public function register_taxonomy($taxonomy_name, $singular_name, $plural_name, $override_args = array()) |
|
186 | - { |
|
187 | - /** @var \EventEspresso\core\domain\services\custom_post_types\registerCustomTaxonomies $taxonomies */ |
|
188 | - $taxonomies = LoaderFactory::getLoader()->getShared( |
|
189 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' |
|
190 | - ); |
|
191 | - $taxonomies->registerCustomTaxonomy( |
|
192 | - $taxonomy_name, |
|
193 | - $singular_name, |
|
194 | - $plural_name, |
|
195 | - $override_args |
|
196 | - ); |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * @deprecated 4.9.62.p |
|
202 | - * @param string $post_type the actual post type name |
|
203 | - * (VERY IMPORTANT: this much match what the slug is for admin pages related to this |
|
204 | - * cpt Also any models must use this slug as well) |
|
205 | - * @param string $singular_name a pre-internationalized string for the singular name of the objects |
|
206 | - * @param string $plural_name a pre-internalized string for the plural name of the objects |
|
207 | - * @param array $override_args exactly like $args as described in |
|
208 | - * http://codex.wordpress.org/Function_Reference/register_post_type The default values |
|
209 | - * set in this function will be overridden by whatever you set in $override_args |
|
210 | - * @param string $singular_slug |
|
211 | - * @param string $plural_slug |
|
212 | - * @return void , but registers the custom post type |
|
213 | - * @throws InvalidArgumentException |
|
214 | - * @throws InvalidDataTypeException |
|
215 | - * @throws InvalidInterfaceException |
|
216 | - * @throws DomainException |
|
217 | - */ |
|
218 | - public function register_CPT( |
|
219 | - $post_type, |
|
220 | - $singular_name, |
|
221 | - $plural_name, |
|
222 | - $override_args = array(), |
|
223 | - $singular_slug = '', |
|
224 | - $plural_slug = '' |
|
225 | - ) { |
|
226 | - /** @var \EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes $register_custom_post_types */ |
|
227 | - $register_custom_post_types = LoaderFactory::getLoader()->getShared( |
|
228 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' |
|
229 | - ); |
|
230 | - $register_custom_post_types->registerCustomPostType( |
|
231 | - $post_type, |
|
232 | - $singular_name, |
|
233 | - $plural_name, |
|
234 | - $singular_slug, |
|
235 | - $plural_slug, |
|
236 | - $override_args |
|
237 | - ); |
|
238 | - } |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * @return RegisterCustomTaxonomyTerms |
|
243 | - * @throws InvalidArgumentException |
|
244 | - * @throws InvalidDataTypeException |
|
245 | - * @throws InvalidInterfaceException |
|
246 | - */ |
|
247 | - public static function getRegisterCustomTaxonomyTerms() |
|
248 | - { |
|
249 | - return LoaderFactory::getLoader()->getShared( |
|
250 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms' |
|
251 | - ); |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * @deprecated 4.9.62.p |
|
257 | - * @throws InvalidArgumentException |
|
258 | - * @throws InvalidDataTypeException |
|
259 | - * @throws InvalidInterfaceException |
|
260 | - */ |
|
261 | - public function set_must_use_event_types() |
|
262 | - { |
|
263 | - $register_custom_taxonomy_terms = EE_Register_CPTs::getRegisterCustomTaxonomyTerms(); |
|
264 | - $register_custom_taxonomy_terms->setMustUseEventTypes(); |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - /** |
|
269 | - * @deprecated 4.9.62.p |
|
270 | - * @param string $taxonomy The name of the taxonomy |
|
271 | - * @param array $term_details An array of term details indexed by slug and containing Name of term, and |
|
272 | - * description as the elements in the array |
|
273 | - * @return void |
|
274 | - * @throws InvalidArgumentException |
|
275 | - * @throws InvalidDataTypeException |
|
276 | - * @throws InvalidInterfaceException |
|
277 | - */ |
|
278 | - public function set_must_use_terms($taxonomy, $term_details) |
|
279 | - { |
|
280 | - $register_custom_taxonomy_terms = EE_Register_CPTs::getRegisterCustomTaxonomyTerms(); |
|
281 | - $register_custom_taxonomy_terms->setMustUseTerms($taxonomy, $term_details); |
|
282 | - } |
|
283 | - |
|
284 | - |
|
285 | - /** |
|
286 | - * @deprecated 4.9.62.p |
|
287 | - * @param string $taxonomy The taxonomy we're using for the default term |
|
288 | - * @param string $term_slug The slug of the term that will be the default. |
|
289 | - * @param array $cpt_slugs An array of custom post types we want the default assigned to |
|
290 | - * @throws InvalidArgumentException |
|
291 | - * @throws InvalidDataTypeException |
|
292 | - * @throws InvalidInterfaceException |
|
293 | - */ |
|
294 | - public function set_default_term($taxonomy, $term_slug, $cpt_slugs = array()) |
|
295 | - { |
|
296 | - $register_custom_taxonomy_terms = EE_Register_CPTs::getRegisterCustomTaxonomyTerms(); |
|
297 | - $register_custom_taxonomy_terms->registerCustomTaxonomyTerm( |
|
298 | - $taxonomy, |
|
299 | - $term_slug, |
|
300 | - $cpt_slugs |
|
301 | - ); |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * @deprecated 4.9.62.p |
|
307 | - * @param int $post_id ID of CPT being saved |
|
308 | - * @param WP_Post $post Post object |
|
309 | - * @return void |
|
310 | - * @throws InvalidArgumentException |
|
311 | - * @throws InvalidDataTypeException |
|
312 | - * @throws InvalidInterfaceException |
|
313 | - */ |
|
314 | - public function save_default_term($post_id, $post) |
|
315 | - { |
|
316 | - $register_custom_taxonomy_terms = EE_Register_CPTs::getRegisterCustomTaxonomyTerms(); |
|
317 | - $register_custom_taxonomy_terms->saveDefaultTerm($post_id, $post); |
|
318 | - } |
|
22 | + /** |
|
23 | + * instantiated at init priority 5 |
|
24 | + * |
|
25 | + * @deprecated 4.9.62.p |
|
26 | + */ |
|
27 | + public function __construct() |
|
28 | + { |
|
29 | + do_action('AHEE__EE_Register_CPTs__construct_end', $this); |
|
30 | + } |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * This will flush rewrite rules on demand. This actually gets called around wp init priority level 100. |
|
35 | + * |
|
36 | + * @deprecated 4.9.62.p |
|
37 | + * @return void |
|
38 | + * @throws InvalidInterfaceException |
|
39 | + * @throws InvalidDataTypeException |
|
40 | + * @throws InvalidArgumentException |
|
41 | + */ |
|
42 | + public static function maybe_flush_rewrite_rules() |
|
43 | + { |
|
44 | + /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
45 | + $rewrite_rules = LoaderFactory::getLoader()->getShared( |
|
46 | + 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
47 | + ); |
|
48 | + $rewrite_rules->flushRewriteRules(); |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * @return CustomTaxonomyDefinitions |
|
54 | + * @throws InvalidArgumentException |
|
55 | + * @throws InvalidDataTypeException |
|
56 | + * @throws InvalidInterfaceException |
|
57 | + */ |
|
58 | + public static function getTaxonomyDefinitions() |
|
59 | + { |
|
60 | + return LoaderFactory::getLoader()->getShared( |
|
61 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' |
|
62 | + ); |
|
63 | + } |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * @deprecated 4.9.62.p |
|
68 | + * @param string $description The description content. |
|
69 | + * @param string $taxonomy The taxonomy name for the taxonomy being filtered. |
|
70 | + * @return string |
|
71 | + * @throws InvalidArgumentException |
|
72 | + * @throws InvalidDataTypeException |
|
73 | + * @throws InvalidInterfaceException |
|
74 | + */ |
|
75 | + public function ee_filter_ee_term_description_not_wp($description, $taxonomy) |
|
76 | + { |
|
77 | + $taxonomies = EE_Register_CPTs::getTaxonomyDefinitions(); |
|
78 | + return $taxonomies->filterCustomTermDescription($description, $taxonomy); |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @deprecated 4.9.62.p |
|
84 | + * @return array |
|
85 | + * @throws InvalidArgumentException |
|
86 | + * @throws InvalidDataTypeException |
|
87 | + * @throws InvalidInterfaceException |
|
88 | + */ |
|
89 | + public static function get_taxonomies() |
|
90 | + { |
|
91 | + $taxonomies = EE_Register_CPTs::getTaxonomyDefinitions(); |
|
92 | + return $taxonomies->getCustomTaxonomyDefinitions(); |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * @return CustomPostTypeDefinitions |
|
98 | + * @throws InvalidArgumentException |
|
99 | + * @throws InvalidDataTypeException |
|
100 | + * @throws InvalidInterfaceException |
|
101 | + */ |
|
102 | + public static function getCustomPostTypeDefinitions() |
|
103 | + { |
|
104 | + return LoaderFactory::getLoader()->getShared( |
|
105 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' |
|
106 | + ); |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * @deprecated 4.9.62.p |
|
112 | + * @return array |
|
113 | + * @throws InvalidArgumentException |
|
114 | + * @throws InvalidDataTypeException |
|
115 | + * @throws InvalidInterfaceException |
|
116 | + */ |
|
117 | + public static function get_CPTs() |
|
118 | + { |
|
119 | + $custom_post_types = EE_Register_CPTs::getCustomPostTypeDefinitions(); |
|
120 | + return $custom_post_types->getDefinitions(); |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * @deprecated 4.9.62.p |
|
126 | + * @return array |
|
127 | + * @throws InvalidArgumentException |
|
128 | + * @throws InvalidDataTypeException |
|
129 | + * @throws InvalidInterfaceException |
|
130 | + */ |
|
131 | + public static function get_private_CPTs() |
|
132 | + { |
|
133 | + $custom_post_types = EE_Register_CPTs::getCustomPostTypeDefinitions(); |
|
134 | + return $custom_post_types->getPrivateCustomPostTypes(); |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * @deprecated 4.9.62.p |
|
140 | + * @param string $post_type_slug If a slug is included, then attempt to retrieve the model name for |
|
141 | + * the given cpt slug. Otherwise if empty, then we'll return all cpt |
|
142 | + * model names for cpts registered in EE. |
|
143 | + * @return array Empty array if no matching model names for the given slug or an array of model |
|
144 | + * names indexed by post type slug. |
|
145 | + * @throws InvalidArgumentException |
|
146 | + * @throws InvalidDataTypeException |
|
147 | + * @throws InvalidInterfaceException |
|
148 | + */ |
|
149 | + public static function get_cpt_model_names($post_type_slug = '') |
|
150 | + { |
|
151 | + $custom_post_types = EE_Register_CPTs::getCustomPostTypeDefinitions(); |
|
152 | + return $custom_post_types->getCustomPostTypeModelNames($post_type_slug); |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * @deprecated 4.9.62.p |
|
158 | + * @param string $post_type_slug If valid slug is provided, then will instantiate the model only for |
|
159 | + * the cpt matching the given slug. Otherwise all cpt models will be |
|
160 | + * instantiated (if possible). |
|
161 | + * @return EEM_CPT_Base[] successful instantiation will return an array of successfully instantiated |
|
162 | + * EEM models indexed by post slug. |
|
163 | + * @throws InvalidArgumentException |
|
164 | + * @throws InvalidDataTypeException |
|
165 | + * @throws InvalidInterfaceException |
|
166 | + */ |
|
167 | + public static function instantiate_cpt_models($post_type_slug = '') |
|
168 | + { |
|
169 | + $custom_post_types = EE_Register_CPTs::getCustomPostTypeDefinitions(); |
|
170 | + return $custom_post_types->getCustomPostTypeModels($post_type_slug); |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * @deprecated 4.9.62.p |
|
176 | + * @param string $taxonomy_name , eg 'books' |
|
177 | + * @param string $singular_name internationalized singular name |
|
178 | + * @param string $plural_name internationalized plural name |
|
179 | + * @param array $override_args like $args on http://codex.wordpress.org/Function_Reference/register_taxonomy |
|
180 | + * @throws InvalidArgumentException |
|
181 | + * @throws InvalidDataTypeException |
|
182 | + * @throws InvalidInterfaceException |
|
183 | + * @throws DomainException |
|
184 | + */ |
|
185 | + public function register_taxonomy($taxonomy_name, $singular_name, $plural_name, $override_args = array()) |
|
186 | + { |
|
187 | + /** @var \EventEspresso\core\domain\services\custom_post_types\registerCustomTaxonomies $taxonomies */ |
|
188 | + $taxonomies = LoaderFactory::getLoader()->getShared( |
|
189 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' |
|
190 | + ); |
|
191 | + $taxonomies->registerCustomTaxonomy( |
|
192 | + $taxonomy_name, |
|
193 | + $singular_name, |
|
194 | + $plural_name, |
|
195 | + $override_args |
|
196 | + ); |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * @deprecated 4.9.62.p |
|
202 | + * @param string $post_type the actual post type name |
|
203 | + * (VERY IMPORTANT: this much match what the slug is for admin pages related to this |
|
204 | + * cpt Also any models must use this slug as well) |
|
205 | + * @param string $singular_name a pre-internationalized string for the singular name of the objects |
|
206 | + * @param string $plural_name a pre-internalized string for the plural name of the objects |
|
207 | + * @param array $override_args exactly like $args as described in |
|
208 | + * http://codex.wordpress.org/Function_Reference/register_post_type The default values |
|
209 | + * set in this function will be overridden by whatever you set in $override_args |
|
210 | + * @param string $singular_slug |
|
211 | + * @param string $plural_slug |
|
212 | + * @return void , but registers the custom post type |
|
213 | + * @throws InvalidArgumentException |
|
214 | + * @throws InvalidDataTypeException |
|
215 | + * @throws InvalidInterfaceException |
|
216 | + * @throws DomainException |
|
217 | + */ |
|
218 | + public function register_CPT( |
|
219 | + $post_type, |
|
220 | + $singular_name, |
|
221 | + $plural_name, |
|
222 | + $override_args = array(), |
|
223 | + $singular_slug = '', |
|
224 | + $plural_slug = '' |
|
225 | + ) { |
|
226 | + /** @var \EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes $register_custom_post_types */ |
|
227 | + $register_custom_post_types = LoaderFactory::getLoader()->getShared( |
|
228 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' |
|
229 | + ); |
|
230 | + $register_custom_post_types->registerCustomPostType( |
|
231 | + $post_type, |
|
232 | + $singular_name, |
|
233 | + $plural_name, |
|
234 | + $singular_slug, |
|
235 | + $plural_slug, |
|
236 | + $override_args |
|
237 | + ); |
|
238 | + } |
|
239 | + |
|
240 | + |
|
241 | + /** |
|
242 | + * @return RegisterCustomTaxonomyTerms |
|
243 | + * @throws InvalidArgumentException |
|
244 | + * @throws InvalidDataTypeException |
|
245 | + * @throws InvalidInterfaceException |
|
246 | + */ |
|
247 | + public static function getRegisterCustomTaxonomyTerms() |
|
248 | + { |
|
249 | + return LoaderFactory::getLoader()->getShared( |
|
250 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms' |
|
251 | + ); |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * @deprecated 4.9.62.p |
|
257 | + * @throws InvalidArgumentException |
|
258 | + * @throws InvalidDataTypeException |
|
259 | + * @throws InvalidInterfaceException |
|
260 | + */ |
|
261 | + public function set_must_use_event_types() |
|
262 | + { |
|
263 | + $register_custom_taxonomy_terms = EE_Register_CPTs::getRegisterCustomTaxonomyTerms(); |
|
264 | + $register_custom_taxonomy_terms->setMustUseEventTypes(); |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + /** |
|
269 | + * @deprecated 4.9.62.p |
|
270 | + * @param string $taxonomy The name of the taxonomy |
|
271 | + * @param array $term_details An array of term details indexed by slug and containing Name of term, and |
|
272 | + * description as the elements in the array |
|
273 | + * @return void |
|
274 | + * @throws InvalidArgumentException |
|
275 | + * @throws InvalidDataTypeException |
|
276 | + * @throws InvalidInterfaceException |
|
277 | + */ |
|
278 | + public function set_must_use_terms($taxonomy, $term_details) |
|
279 | + { |
|
280 | + $register_custom_taxonomy_terms = EE_Register_CPTs::getRegisterCustomTaxonomyTerms(); |
|
281 | + $register_custom_taxonomy_terms->setMustUseTerms($taxonomy, $term_details); |
|
282 | + } |
|
283 | + |
|
284 | + |
|
285 | + /** |
|
286 | + * @deprecated 4.9.62.p |
|
287 | + * @param string $taxonomy The taxonomy we're using for the default term |
|
288 | + * @param string $term_slug The slug of the term that will be the default. |
|
289 | + * @param array $cpt_slugs An array of custom post types we want the default assigned to |
|
290 | + * @throws InvalidArgumentException |
|
291 | + * @throws InvalidDataTypeException |
|
292 | + * @throws InvalidInterfaceException |
|
293 | + */ |
|
294 | + public function set_default_term($taxonomy, $term_slug, $cpt_slugs = array()) |
|
295 | + { |
|
296 | + $register_custom_taxonomy_terms = EE_Register_CPTs::getRegisterCustomTaxonomyTerms(); |
|
297 | + $register_custom_taxonomy_terms->registerCustomTaxonomyTerm( |
|
298 | + $taxonomy, |
|
299 | + $term_slug, |
|
300 | + $cpt_slugs |
|
301 | + ); |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * @deprecated 4.9.62.p |
|
307 | + * @param int $post_id ID of CPT being saved |
|
308 | + * @param WP_Post $post Post object |
|
309 | + * @return void |
|
310 | + * @throws InvalidArgumentException |
|
311 | + * @throws InvalidDataTypeException |
|
312 | + * @throws InvalidInterfaceException |
|
313 | + */ |
|
314 | + public function save_default_term($post_id, $post) |
|
315 | + { |
|
316 | + $register_custom_taxonomy_terms = EE_Register_CPTs::getRegisterCustomTaxonomyTerms(); |
|
317 | + $register_custom_taxonomy_terms->saveDefaultTerm($post_id, $post); |
|
318 | + } |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | /** |
@@ -327,24 +327,24 @@ discard block |
||
327 | 327 | class EE_Default_Term |
328 | 328 | { |
329 | 329 | |
330 | - // props holding the items |
|
331 | - public $taxonomy = ''; |
|
330 | + // props holding the items |
|
331 | + public $taxonomy = ''; |
|
332 | 332 | |
333 | - public $cpt_slugs = array(); |
|
333 | + public $cpt_slugs = array(); |
|
334 | 334 | |
335 | - public $term_slug = ''; |
|
335 | + public $term_slug = ''; |
|
336 | 336 | |
337 | 337 | |
338 | - /** |
|
339 | - * @deprecated 4.9.62.p |
|
340 | - * @param string $taxonomy The taxonomy the default term belongs to |
|
341 | - * @param string $term_slug The slug of the term that will be the default. |
|
342 | - * @param array $cpt_slugs The custom post type the default term gets saved with |
|
343 | - */ |
|
344 | - public function __construct($taxonomy, $term_slug, $cpt_slugs = array()) |
|
345 | - { |
|
346 | - $this->taxonomy = $taxonomy; |
|
347 | - $this->cpt_slugs = (array) $cpt_slugs; |
|
348 | - $this->term_slug = $term_slug; |
|
349 | - } |
|
338 | + /** |
|
339 | + * @deprecated 4.9.62.p |
|
340 | + * @param string $taxonomy The taxonomy the default term belongs to |
|
341 | + * @param string $term_slug The slug of the term that will be the default. |
|
342 | + * @param array $cpt_slugs The custom post type the default term gets saved with |
|
343 | + */ |
|
344 | + public function __construct($taxonomy, $term_slug, $cpt_slugs = array()) |
|
345 | + { |
|
346 | + $this->taxonomy = $taxonomy; |
|
347 | + $this->cpt_slugs = (array) $cpt_slugs; |
|
348 | + $this->term_slug = $term_slug; |
|
349 | + } |
|
350 | 350 | } |