@@ -16,30 +16,30 @@ |
||
16 | 16 | class InvalidEntityException extends InvalidArgumentException |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * InvalidEntityException constructor. |
|
21 | - * |
|
22 | - * @param mixed $actual the actual object (or thing) we got |
|
23 | - * @param string $expected classname of the entity we wanted |
|
24 | - * @param string $message |
|
25 | - * @param int $code |
|
26 | - * @param Exception $previous |
|
27 | - */ |
|
28 | - public function __construct($actual, $expected, $message = '', $code = 0, Exception $previous = null) |
|
29 | - { |
|
30 | - if (empty($message)) { |
|
31 | - $message = sprintf( |
|
32 | - __( |
|
33 | - 'The supplied entity is an instance of "%1$s", but an instance of "%2$s" was expected. Object: %3$s', |
|
34 | - 'event_espresso' |
|
35 | - ), |
|
36 | - is_object($actual) |
|
37 | - ? get_class($actual) |
|
38 | - : gettype($actual), |
|
39 | - $expected, |
|
40 | - var_export($actual, true) |
|
41 | - ); |
|
42 | - } |
|
43 | - parent::__construct($message, $code, $previous); |
|
44 | - } |
|
19 | + /** |
|
20 | + * InvalidEntityException constructor. |
|
21 | + * |
|
22 | + * @param mixed $actual the actual object (or thing) we got |
|
23 | + * @param string $expected classname of the entity we wanted |
|
24 | + * @param string $message |
|
25 | + * @param int $code |
|
26 | + * @param Exception $previous |
|
27 | + */ |
|
28 | + public function __construct($actual, $expected, $message = '', $code = 0, Exception $previous = null) |
|
29 | + { |
|
30 | + if (empty($message)) { |
|
31 | + $message = sprintf( |
|
32 | + __( |
|
33 | + 'The supplied entity is an instance of "%1$s", but an instance of "%2$s" was expected. Object: %3$s', |
|
34 | + 'event_espresso' |
|
35 | + ), |
|
36 | + is_object($actual) |
|
37 | + ? get_class($actual) |
|
38 | + : gettype($actual), |
|
39 | + $expected, |
|
40 | + var_export($actual, true) |
|
41 | + ); |
|
42 | + } |
|
43 | + parent::__construct($message, $code, $previous); |
|
44 | + } |
|
45 | 45 | } |
@@ -23,246 +23,246 @@ |
||
23 | 23 | abstract class EditorBlock implements EditorBlockInterface |
24 | 24 | { |
25 | 25 | |
26 | - const NS = 'event-espresso/'; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var DomainInterface $domain |
|
30 | - */ |
|
31 | - protected $domain; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var LoaderInterface $loader |
|
35 | - */ |
|
36 | - protected $loader; |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * @var Registry |
|
41 | - */ |
|
42 | - protected $assets_registry; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var string $editor_block_type |
|
46 | - */ |
|
47 | - private $editor_block_type; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var WP_Block_Type $wp_block_type |
|
51 | - */ |
|
52 | - private $wp_block_type; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var array $supported_post_types |
|
56 | - */ |
|
57 | - private $supported_post_types; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var array $attributes |
|
61 | - */ |
|
62 | - private $attributes; |
|
63 | - |
|
64 | - /** |
|
65 | - * If set to true, then the block will render its content client side |
|
66 | - * If false, then the block will render its content server side using the renderBlock() method |
|
67 | - * |
|
68 | - * @var bool $dynamic |
|
69 | - */ |
|
70 | - private $dynamic = false; |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * EditorBlockLoader constructor. |
|
75 | - * |
|
76 | - * @param DomainInterface $domain |
|
77 | - * @param LoaderInterface $loader |
|
78 | - * @param Registry $assets_registry |
|
79 | - */ |
|
80 | - public function __construct( |
|
81 | - DomainInterface $domain, |
|
82 | - LoaderInterface $loader, |
|
83 | - Registry $assets_registry |
|
84 | - ) { |
|
85 | - $this->domain = $domain; |
|
86 | - $this->loader = $loader; |
|
87 | - $this->assets_registry = $assets_registry; |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * @return string |
|
93 | - */ |
|
94 | - public function editorBlockType() |
|
95 | - { |
|
96 | - return $this->editor_block_type; |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - public function namespacedEditorBlockType() |
|
104 | - { |
|
105 | - return EditorBlock::NS . $this->editor_block_type; |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * @param string $editor_block_type |
|
111 | - */ |
|
112 | - protected function setEditorBlockType($editor_block_type) |
|
113 | - { |
|
114 | - $this->editor_block_type = $editor_block_type; |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * @param WP_Block_Type $wp_block_type |
|
120 | - */ |
|
121 | - protected function setWpBlockType($wp_block_type) |
|
122 | - { |
|
123 | - $this->wp_block_type = $wp_block_type; |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * @param array $supported_post_types |
|
129 | - */ |
|
130 | - protected function setSupportedPostTypes(array $supported_post_types) |
|
131 | - { |
|
132 | - $this->supported_post_types = $supported_post_types; |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * @return array |
|
138 | - */ |
|
139 | - public function attributes() |
|
140 | - { |
|
141 | - return $this->attributes; |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * @param array $attributes |
|
147 | - */ |
|
148 | - public function setAttributes(array $attributes) |
|
149 | - { |
|
150 | - $this->attributes = $attributes; |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * @return bool |
|
156 | - */ |
|
157 | - public function isDynamic() |
|
158 | - { |
|
159 | - return $this->dynamic; |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * @param bool $dynamic |
|
165 | - */ |
|
166 | - public function setDynamic($dynamic = true) |
|
167 | - { |
|
168 | - $this->dynamic = filter_var($dynamic, FILTER_VALIDATE_BOOLEAN); |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * Registers the Editor Block with WP core; |
|
174 | - * Returns the registered block type on success, or false on failure. |
|
175 | - * |
|
176 | - * @return WP_Block_Type|false |
|
177 | - */ |
|
178 | - public function registerBlock() |
|
179 | - { |
|
180 | - $context ='core'; |
|
181 | - // todo add route detection (ie inject route) and change context based on route |
|
182 | - $args = array( |
|
183 | - 'attributes' => $this->attributes(), |
|
184 | - 'editor_script' => "ee-{$context}-blocks", |
|
185 | - 'editor_style' => "ee-{$context}-blocks", |
|
186 | - 'script' => "ee-{$context}-blocks", |
|
187 | - 'style' => "ee-{$context}-blocks", |
|
188 | - ); |
|
189 | - if (! $this->isDynamic()) { |
|
190 | - $args['render_callback'] = $this->renderBlock(); |
|
191 | - } |
|
192 | - $wp_block_type = register_block_type( |
|
193 | - new WP_Block_Type( |
|
194 | - $this->namespacedEditorBlockType(), |
|
195 | - $args |
|
196 | - ) |
|
197 | - ); |
|
198 | - $this->setWpBlockType($wp_block_type); |
|
199 | - return $wp_block_type; |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * @return WP_Block_Type|false The registered block type on success, or false on failure. |
|
205 | - */ |
|
206 | - public function unRegisterBlock() |
|
207 | - { |
|
208 | - return unregister_block_type($this->namespacedEditorBlockType()); |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * returns true if the block type applies for the supplied post type |
|
214 | - * and should be added to that post type's editor |
|
215 | - * |
|
216 | - * @param string $post_type |
|
217 | - * @return boolean |
|
218 | - */ |
|
219 | - public function appliesToPostType($post_type) |
|
220 | - { |
|
221 | - return in_array($post_type, $this->supported_post_types, true); |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - /** |
|
226 | - * @return array |
|
227 | - */ |
|
228 | - public function getEditorContainer() |
|
229 | - { |
|
230 | - return array( |
|
231 | - $this->namespacedEditorBlockType(), |
|
232 | - array() |
|
233 | - ); |
|
234 | - } |
|
235 | - |
|
236 | - |
|
237 | - /** |
|
238 | - * @return void |
|
239 | - */ |
|
240 | - public function registerScripts() |
|
241 | - { |
|
242 | - // wp_register_script( |
|
243 | - // 'core-blocks', |
|
244 | - // $this->domain->distributionAssetsUrl() . 'ee-core-blocks.dist.js', |
|
245 | - // array( |
|
246 | - // 'wp-blocks', // Provides useful functions and components for extending the editor |
|
247 | - // 'wp-i18n', // Provides localization functions |
|
248 | - // 'wp-element', // Provides React.Component |
|
249 | - // 'wp-components' // Provides many prebuilt components and controls |
|
250 | - // ), |
|
251 | - // filemtime($this->domain->distributionAssetsPath() . 'ee-core-blocks.dist.js') |
|
252 | - // ); |
|
253 | - } |
|
254 | - |
|
255 | - |
|
256 | - /** |
|
257 | - * @return void |
|
258 | - */ |
|
259 | - public function registerStyles() |
|
260 | - { |
|
261 | - // wp_register_style( |
|
262 | - // 'ee-block-styles', |
|
263 | - // $this->domain->distributionAssetsUrl() . 'style.css', |
|
264 | - // array(), |
|
265 | - // filemtime($this->domain->distributionAssetsPath() . 'style.css') |
|
266 | - // ); |
|
267 | - } |
|
26 | + const NS = 'event-espresso/'; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var DomainInterface $domain |
|
30 | + */ |
|
31 | + protected $domain; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var LoaderInterface $loader |
|
35 | + */ |
|
36 | + protected $loader; |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * @var Registry |
|
41 | + */ |
|
42 | + protected $assets_registry; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var string $editor_block_type |
|
46 | + */ |
|
47 | + private $editor_block_type; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var WP_Block_Type $wp_block_type |
|
51 | + */ |
|
52 | + private $wp_block_type; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var array $supported_post_types |
|
56 | + */ |
|
57 | + private $supported_post_types; |
|
58 | + |
|
59 | + /** |
|
60 | + * @var array $attributes |
|
61 | + */ |
|
62 | + private $attributes; |
|
63 | + |
|
64 | + /** |
|
65 | + * If set to true, then the block will render its content client side |
|
66 | + * If false, then the block will render its content server side using the renderBlock() method |
|
67 | + * |
|
68 | + * @var bool $dynamic |
|
69 | + */ |
|
70 | + private $dynamic = false; |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * EditorBlockLoader constructor. |
|
75 | + * |
|
76 | + * @param DomainInterface $domain |
|
77 | + * @param LoaderInterface $loader |
|
78 | + * @param Registry $assets_registry |
|
79 | + */ |
|
80 | + public function __construct( |
|
81 | + DomainInterface $domain, |
|
82 | + LoaderInterface $loader, |
|
83 | + Registry $assets_registry |
|
84 | + ) { |
|
85 | + $this->domain = $domain; |
|
86 | + $this->loader = $loader; |
|
87 | + $this->assets_registry = $assets_registry; |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * @return string |
|
93 | + */ |
|
94 | + public function editorBlockType() |
|
95 | + { |
|
96 | + return $this->editor_block_type; |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + public function namespacedEditorBlockType() |
|
104 | + { |
|
105 | + return EditorBlock::NS . $this->editor_block_type; |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * @param string $editor_block_type |
|
111 | + */ |
|
112 | + protected function setEditorBlockType($editor_block_type) |
|
113 | + { |
|
114 | + $this->editor_block_type = $editor_block_type; |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * @param WP_Block_Type $wp_block_type |
|
120 | + */ |
|
121 | + protected function setWpBlockType($wp_block_type) |
|
122 | + { |
|
123 | + $this->wp_block_type = $wp_block_type; |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * @param array $supported_post_types |
|
129 | + */ |
|
130 | + protected function setSupportedPostTypes(array $supported_post_types) |
|
131 | + { |
|
132 | + $this->supported_post_types = $supported_post_types; |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * @return array |
|
138 | + */ |
|
139 | + public function attributes() |
|
140 | + { |
|
141 | + return $this->attributes; |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * @param array $attributes |
|
147 | + */ |
|
148 | + public function setAttributes(array $attributes) |
|
149 | + { |
|
150 | + $this->attributes = $attributes; |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * @return bool |
|
156 | + */ |
|
157 | + public function isDynamic() |
|
158 | + { |
|
159 | + return $this->dynamic; |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * @param bool $dynamic |
|
165 | + */ |
|
166 | + public function setDynamic($dynamic = true) |
|
167 | + { |
|
168 | + $this->dynamic = filter_var($dynamic, FILTER_VALIDATE_BOOLEAN); |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * Registers the Editor Block with WP core; |
|
174 | + * Returns the registered block type on success, or false on failure. |
|
175 | + * |
|
176 | + * @return WP_Block_Type|false |
|
177 | + */ |
|
178 | + public function registerBlock() |
|
179 | + { |
|
180 | + $context ='core'; |
|
181 | + // todo add route detection (ie inject route) and change context based on route |
|
182 | + $args = array( |
|
183 | + 'attributes' => $this->attributes(), |
|
184 | + 'editor_script' => "ee-{$context}-blocks", |
|
185 | + 'editor_style' => "ee-{$context}-blocks", |
|
186 | + 'script' => "ee-{$context}-blocks", |
|
187 | + 'style' => "ee-{$context}-blocks", |
|
188 | + ); |
|
189 | + if (! $this->isDynamic()) { |
|
190 | + $args['render_callback'] = $this->renderBlock(); |
|
191 | + } |
|
192 | + $wp_block_type = register_block_type( |
|
193 | + new WP_Block_Type( |
|
194 | + $this->namespacedEditorBlockType(), |
|
195 | + $args |
|
196 | + ) |
|
197 | + ); |
|
198 | + $this->setWpBlockType($wp_block_type); |
|
199 | + return $wp_block_type; |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * @return WP_Block_Type|false The registered block type on success, or false on failure. |
|
205 | + */ |
|
206 | + public function unRegisterBlock() |
|
207 | + { |
|
208 | + return unregister_block_type($this->namespacedEditorBlockType()); |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * returns true if the block type applies for the supplied post type |
|
214 | + * and should be added to that post type's editor |
|
215 | + * |
|
216 | + * @param string $post_type |
|
217 | + * @return boolean |
|
218 | + */ |
|
219 | + public function appliesToPostType($post_type) |
|
220 | + { |
|
221 | + return in_array($post_type, $this->supported_post_types, true); |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + /** |
|
226 | + * @return array |
|
227 | + */ |
|
228 | + public function getEditorContainer() |
|
229 | + { |
|
230 | + return array( |
|
231 | + $this->namespacedEditorBlockType(), |
|
232 | + array() |
|
233 | + ); |
|
234 | + } |
|
235 | + |
|
236 | + |
|
237 | + /** |
|
238 | + * @return void |
|
239 | + */ |
|
240 | + public function registerScripts() |
|
241 | + { |
|
242 | + // wp_register_script( |
|
243 | + // 'core-blocks', |
|
244 | + // $this->domain->distributionAssetsUrl() . 'ee-core-blocks.dist.js', |
|
245 | + // array( |
|
246 | + // 'wp-blocks', // Provides useful functions and components for extending the editor |
|
247 | + // 'wp-i18n', // Provides localization functions |
|
248 | + // 'wp-element', // Provides React.Component |
|
249 | + // 'wp-components' // Provides many prebuilt components and controls |
|
250 | + // ), |
|
251 | + // filemtime($this->domain->distributionAssetsPath() . 'ee-core-blocks.dist.js') |
|
252 | + // ); |
|
253 | + } |
|
254 | + |
|
255 | + |
|
256 | + /** |
|
257 | + * @return void |
|
258 | + */ |
|
259 | + public function registerStyles() |
|
260 | + { |
|
261 | + // wp_register_style( |
|
262 | + // 'ee-block-styles', |
|
263 | + // $this->domain->distributionAssetsUrl() . 'style.css', |
|
264 | + // array(), |
|
265 | + // filemtime($this->domain->distributionAssetsPath() . 'style.css') |
|
266 | + // ); |
|
267 | + } |
|
268 | 268 | } |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | public function namespacedEditorBlockType() |
104 | 104 | { |
105 | - return EditorBlock::NS . $this->editor_block_type; |
|
105 | + return EditorBlock::NS.$this->editor_block_type; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | |
@@ -177,16 +177,16 @@ discard block |
||
177 | 177 | */ |
178 | 178 | public function registerBlock() |
179 | 179 | { |
180 | - $context ='core'; |
|
180 | + $context = 'core'; |
|
181 | 181 | // todo add route detection (ie inject route) and change context based on route |
182 | - $args = array( |
|
182 | + $args = array( |
|
183 | 183 | 'attributes' => $this->attributes(), |
184 | 184 | 'editor_script' => "ee-{$context}-blocks", |
185 | 185 | 'editor_style' => "ee-{$context}-blocks", |
186 | 186 | 'script' => "ee-{$context}-blocks", |
187 | 187 | 'style' => "ee-{$context}-blocks", |
188 | 188 | ); |
189 | - if (! $this->isDynamic()) { |
|
189 | + if ( ! $this->isDynamic()) { |
|
190 | 190 | $args['render_callback'] = $this->renderBlock(); |
191 | 191 | } |
192 | 192 | $wp_block_type = register_block_type( |
@@ -20,94 +20,94 @@ |
||
20 | 20 | abstract class EditorBlockManager |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * @var CollectionInterface|EditorBlockInterface[] $blocks |
|
25 | - */ |
|
26 | - protected $blocks; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var RequestInterface $request |
|
30 | - */ |
|
31 | - protected $request; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var DomainInterface $domain |
|
35 | - */ |
|
36 | - protected $domain; |
|
37 | - |
|
38 | - /** |
|
39 | - * the post type that the current request applies to |
|
40 | - * |
|
41 | - * @var string $request_post_type |
|
42 | - */ |
|
43 | - protected $request_post_type; |
|
44 | - |
|
45 | - /** |
|
46 | - * value of the 'page' $_GET param |
|
47 | - * |
|
48 | - * @var string $page |
|
49 | - */ |
|
50 | - protected $page; |
|
51 | - |
|
52 | - /** |
|
53 | - * value of the 'action' $_GET param |
|
54 | - * |
|
55 | - * @var string $action |
|
56 | - */ |
|
57 | - protected $action; |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * @var Registry |
|
62 | - */ |
|
63 | - protected $assets_registry; |
|
64 | - |
|
65 | - /** |
|
66 | - * EditorBlockManager constructor. |
|
67 | - * |
|
68 | - * @param EditorBlockCollection $blocks |
|
69 | - * @param RequestInterface $request |
|
70 | - * @param DomainInterface $domain |
|
71 | - * @param Registry $assets_registry |
|
72 | - */ |
|
73 | - public function __construct( |
|
74 | - EditorBlockCollection $blocks, |
|
75 | - RequestInterface $request, |
|
76 | - DomainInterface $domain, |
|
77 | - Registry $assets_registry |
|
78 | - ) { |
|
79 | - $this->blocks = $blocks; |
|
80 | - $this->request = $request; |
|
81 | - $this->domain = $domain; |
|
82 | - $this->assets_registry = $assets_registry; |
|
83 | - $this->request_post_type = $this->request->getRequestParam('post_type', ''); |
|
84 | - $this->page = $this->request->getRequestParam('page', ''); |
|
85 | - $this->action = $this->request->getRequestParam('action', ''); |
|
86 | - add_action($this->init_hook(), array($this, 'initialize')); |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * Returns the name of a hookpoint to be used to call initialize() |
|
92 | - * |
|
93 | - * @return string |
|
94 | - */ |
|
95 | - abstract public function initHook(); |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * Perform any early setup required for block editors to functions |
|
100 | - * |
|
101 | - * @return void |
|
102 | - */ |
|
103 | - abstract public function initialize(); |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * @return string |
|
108 | - */ |
|
109 | - public function currentRequestPostType() |
|
110 | - { |
|
111 | - return $this->request_post_type; |
|
112 | - } |
|
23 | + /** |
|
24 | + * @var CollectionInterface|EditorBlockInterface[] $blocks |
|
25 | + */ |
|
26 | + protected $blocks; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var RequestInterface $request |
|
30 | + */ |
|
31 | + protected $request; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var DomainInterface $domain |
|
35 | + */ |
|
36 | + protected $domain; |
|
37 | + |
|
38 | + /** |
|
39 | + * the post type that the current request applies to |
|
40 | + * |
|
41 | + * @var string $request_post_type |
|
42 | + */ |
|
43 | + protected $request_post_type; |
|
44 | + |
|
45 | + /** |
|
46 | + * value of the 'page' $_GET param |
|
47 | + * |
|
48 | + * @var string $page |
|
49 | + */ |
|
50 | + protected $page; |
|
51 | + |
|
52 | + /** |
|
53 | + * value of the 'action' $_GET param |
|
54 | + * |
|
55 | + * @var string $action |
|
56 | + */ |
|
57 | + protected $action; |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * @var Registry |
|
62 | + */ |
|
63 | + protected $assets_registry; |
|
64 | + |
|
65 | + /** |
|
66 | + * EditorBlockManager constructor. |
|
67 | + * |
|
68 | + * @param EditorBlockCollection $blocks |
|
69 | + * @param RequestInterface $request |
|
70 | + * @param DomainInterface $domain |
|
71 | + * @param Registry $assets_registry |
|
72 | + */ |
|
73 | + public function __construct( |
|
74 | + EditorBlockCollection $blocks, |
|
75 | + RequestInterface $request, |
|
76 | + DomainInterface $domain, |
|
77 | + Registry $assets_registry |
|
78 | + ) { |
|
79 | + $this->blocks = $blocks; |
|
80 | + $this->request = $request; |
|
81 | + $this->domain = $domain; |
|
82 | + $this->assets_registry = $assets_registry; |
|
83 | + $this->request_post_type = $this->request->getRequestParam('post_type', ''); |
|
84 | + $this->page = $this->request->getRequestParam('page', ''); |
|
85 | + $this->action = $this->request->getRequestParam('action', ''); |
|
86 | + add_action($this->init_hook(), array($this, 'initialize')); |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * Returns the name of a hookpoint to be used to call initialize() |
|
92 | + * |
|
93 | + * @return string |
|
94 | + */ |
|
95 | + abstract public function initHook(); |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * Perform any early setup required for block editors to functions |
|
100 | + * |
|
101 | + * @return void |
|
102 | + */ |
|
103 | + abstract public function initialize(); |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * @return string |
|
108 | + */ |
|
109 | + public function currentRequestPostType() |
|
110 | + { |
|
111 | + return $this->request_post_type; |
|
112 | + } |
|
113 | 113 | } |
@@ -34,153 +34,153 @@ |
||
34 | 34 | class EditorBlockRegistrationManager extends EditorBlockManager |
35 | 35 | { |
36 | 36 | |
37 | - /** |
|
38 | - * Returns the name of a hookpoint to be used to call initialize() |
|
39 | - * |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - public function initHook() |
|
43 | - { |
|
44 | - return 'AHEE__EE_System__set_hooks_for_core'; |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * Perform any early setup required for block editors to functions |
|
50 | - * |
|
51 | - * @return void |
|
52 | - * @throws Exception |
|
53 | - */ |
|
54 | - public function initialize() |
|
55 | - { |
|
56 | - $this->loadEditorBlocks(); |
|
57 | - add_action('AHEE__EE_System__initialize', array($this, 'registerEditorBlocks')); |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * @return CollectionInterface|EditorBlockInterface[] |
|
63 | - * @throws ReflectionException |
|
64 | - * @throws InvalidArgumentException |
|
65 | - * @throws EE_Error |
|
66 | - * @throws InvalidClassException |
|
67 | - * @throws InvalidDataTypeException |
|
68 | - * @throws InvalidEntityException |
|
69 | - * @throws InvalidFilePathException |
|
70 | - * @throws InvalidIdentifierException |
|
71 | - * @throws InvalidInterfaceException |
|
72 | - */ |
|
73 | - protected function populateEditorBlockCollection() |
|
74 | - { |
|
75 | - $loader = new CollectionLoader( |
|
76 | - new CollectionDetails( |
|
77 | - // collection name |
|
78 | - 'shortcodes', |
|
79 | - // collection interface |
|
80 | - 'EventEspresso\core\domain\entities\editor\EditorBlockInterface', |
|
81 | - // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
82 | - apply_filters( |
|
83 | - 'FHEE__EventEspresso_core_services_editor_EditorBlockManager__populateEditorBlockCollection__collection_FQCNs', |
|
84 | - array() |
|
85 | - // array( |
|
86 | - // 'EventEspresso\core\domain\entities\editor\blocks\common', |
|
87 | - // 'EventEspresso\core\domain\entities\editor\blocks\editor', |
|
88 | - // 'EventEspresso\core\domain\entities\editor\blocks\shortcodes', |
|
89 | - // 'EventEspresso\core\domain\entities\editor\blocks\widgets', |
|
90 | - // ) |
|
91 | - ), |
|
92 | - // filepaths to classes to add |
|
93 | - array(), |
|
94 | - // file mask to use if parsing folder for files to add |
|
95 | - '', |
|
96 | - // what to use as identifier for collection entities |
|
97 | - // using CLASS NAME prevents duplicates (works like a singleton) |
|
98 | - CollectionDetails::ID_CLASS_NAME |
|
99 | - ), |
|
100 | - $this->blocks |
|
101 | - ); |
|
102 | - return $loader->getCollection(); |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * populates the EditorBlockCollection and calls initialize() on all installed blocks |
|
108 | - * |
|
109 | - * @return void |
|
110 | - * @throws Exception |
|
111 | - */ |
|
112 | - public function loadEditorBlocks() |
|
113 | - { |
|
114 | - try { |
|
115 | - $this->populateEditorBlockCollection(); |
|
116 | - // cycle thru block loaders and initialize each loader |
|
117 | - foreach ($this->blocks as $block) { |
|
118 | - $block->initialize(); |
|
119 | - } |
|
120 | - } catch (Exception $exception) { |
|
121 | - new ExceptionStackTraceDisplay($exception); |
|
122 | - } |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * calls registerBlock() and load assets for all installed blocks |
|
128 | - * |
|
129 | - * @return void |
|
130 | - * @throws Exception |
|
131 | - */ |
|
132 | - public function registerEditorBlocks() |
|
133 | - { |
|
134 | - try { |
|
135 | - // register primary assets |
|
136 | - add_action('enqueue_block_assets', array($this, 'registerStyles')); |
|
137 | - add_action('enqueue_block_assets', array($this, 'registerScripts')); |
|
138 | - // cycle thru block loader folders |
|
139 | - foreach ($this->blocks as $block) { |
|
140 | - // perform any setup required for the block |
|
141 | - $block_type = $block->registerBlock(); |
|
142 | - if (! $block_type instanceof WP_Block_Type) { |
|
143 | - throw new InvalidEntityException($block_type, 'WP_Block_Type'); |
|
144 | - } |
|
145 | - add_action('enqueue_block_assets', array($block, 'registerStyles')); |
|
146 | - add_action('enqueue_block_assets', array($block, 'registerScripts')); |
|
147 | - do_action( |
|
148 | - 'FHEE__EventEspresso_core_services_editor_EditorBlockManager__registerEditorBlocks__block_type_registered', |
|
149 | - $block, |
|
150 | - $block_type |
|
151 | - ); |
|
152 | - } |
|
153 | - } catch (Exception $exception) { |
|
154 | - new ExceptionStackTraceDisplay($exception); |
|
155 | - } |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - public function registerStyles() |
|
160 | - { |
|
161 | - // wp_register_style( |
|
162 | - // 'ee-block-styles', |
|
163 | - // $this->domain->distributionAssetsUrl() . 'style.css', |
|
164 | - // array(), |
|
165 | - // filemtime($this->domain->distributionAssetsPath() . 'style.css') |
|
166 | - // ); |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - public function registerScripts() |
|
171 | - { |
|
172 | - wp_register_script( |
|
173 | - 'ee-core-blocks', |
|
174 | - $this->assets_registry->getAssetUrl(Registry::ASSET_NAMESPACE, 'core-blocks', Registry::ASSET_TYPE_JS), |
|
175 | - array( |
|
176 | - 'eejs-core', |
|
177 | - 'wp-blocks', // Provides useful functions and components for extending the editor |
|
178 | - 'wp-i18n', // Provides localization functions |
|
179 | - 'wp-element', // Provides React.Component |
|
180 | - 'wp-components' // Provides many prebuilt components and controls |
|
181 | - ), |
|
182 | - null, |
|
183 | - true |
|
184 | - ); |
|
185 | - } |
|
37 | + /** |
|
38 | + * Returns the name of a hookpoint to be used to call initialize() |
|
39 | + * |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + public function initHook() |
|
43 | + { |
|
44 | + return 'AHEE__EE_System__set_hooks_for_core'; |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * Perform any early setup required for block editors to functions |
|
50 | + * |
|
51 | + * @return void |
|
52 | + * @throws Exception |
|
53 | + */ |
|
54 | + public function initialize() |
|
55 | + { |
|
56 | + $this->loadEditorBlocks(); |
|
57 | + add_action('AHEE__EE_System__initialize', array($this, 'registerEditorBlocks')); |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * @return CollectionInterface|EditorBlockInterface[] |
|
63 | + * @throws ReflectionException |
|
64 | + * @throws InvalidArgumentException |
|
65 | + * @throws EE_Error |
|
66 | + * @throws InvalidClassException |
|
67 | + * @throws InvalidDataTypeException |
|
68 | + * @throws InvalidEntityException |
|
69 | + * @throws InvalidFilePathException |
|
70 | + * @throws InvalidIdentifierException |
|
71 | + * @throws InvalidInterfaceException |
|
72 | + */ |
|
73 | + protected function populateEditorBlockCollection() |
|
74 | + { |
|
75 | + $loader = new CollectionLoader( |
|
76 | + new CollectionDetails( |
|
77 | + // collection name |
|
78 | + 'shortcodes', |
|
79 | + // collection interface |
|
80 | + 'EventEspresso\core\domain\entities\editor\EditorBlockInterface', |
|
81 | + // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
82 | + apply_filters( |
|
83 | + 'FHEE__EventEspresso_core_services_editor_EditorBlockManager__populateEditorBlockCollection__collection_FQCNs', |
|
84 | + array() |
|
85 | + // array( |
|
86 | + // 'EventEspresso\core\domain\entities\editor\blocks\common', |
|
87 | + // 'EventEspresso\core\domain\entities\editor\blocks\editor', |
|
88 | + // 'EventEspresso\core\domain\entities\editor\blocks\shortcodes', |
|
89 | + // 'EventEspresso\core\domain\entities\editor\blocks\widgets', |
|
90 | + // ) |
|
91 | + ), |
|
92 | + // filepaths to classes to add |
|
93 | + array(), |
|
94 | + // file mask to use if parsing folder for files to add |
|
95 | + '', |
|
96 | + // what to use as identifier for collection entities |
|
97 | + // using CLASS NAME prevents duplicates (works like a singleton) |
|
98 | + CollectionDetails::ID_CLASS_NAME |
|
99 | + ), |
|
100 | + $this->blocks |
|
101 | + ); |
|
102 | + return $loader->getCollection(); |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * populates the EditorBlockCollection and calls initialize() on all installed blocks |
|
108 | + * |
|
109 | + * @return void |
|
110 | + * @throws Exception |
|
111 | + */ |
|
112 | + public function loadEditorBlocks() |
|
113 | + { |
|
114 | + try { |
|
115 | + $this->populateEditorBlockCollection(); |
|
116 | + // cycle thru block loaders and initialize each loader |
|
117 | + foreach ($this->blocks as $block) { |
|
118 | + $block->initialize(); |
|
119 | + } |
|
120 | + } catch (Exception $exception) { |
|
121 | + new ExceptionStackTraceDisplay($exception); |
|
122 | + } |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * calls registerBlock() and load assets for all installed blocks |
|
128 | + * |
|
129 | + * @return void |
|
130 | + * @throws Exception |
|
131 | + */ |
|
132 | + public function registerEditorBlocks() |
|
133 | + { |
|
134 | + try { |
|
135 | + // register primary assets |
|
136 | + add_action('enqueue_block_assets', array($this, 'registerStyles')); |
|
137 | + add_action('enqueue_block_assets', array($this, 'registerScripts')); |
|
138 | + // cycle thru block loader folders |
|
139 | + foreach ($this->blocks as $block) { |
|
140 | + // perform any setup required for the block |
|
141 | + $block_type = $block->registerBlock(); |
|
142 | + if (! $block_type instanceof WP_Block_Type) { |
|
143 | + throw new InvalidEntityException($block_type, 'WP_Block_Type'); |
|
144 | + } |
|
145 | + add_action('enqueue_block_assets', array($block, 'registerStyles')); |
|
146 | + add_action('enqueue_block_assets', array($block, 'registerScripts')); |
|
147 | + do_action( |
|
148 | + 'FHEE__EventEspresso_core_services_editor_EditorBlockManager__registerEditorBlocks__block_type_registered', |
|
149 | + $block, |
|
150 | + $block_type |
|
151 | + ); |
|
152 | + } |
|
153 | + } catch (Exception $exception) { |
|
154 | + new ExceptionStackTraceDisplay($exception); |
|
155 | + } |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + public function registerStyles() |
|
160 | + { |
|
161 | + // wp_register_style( |
|
162 | + // 'ee-block-styles', |
|
163 | + // $this->domain->distributionAssetsUrl() . 'style.css', |
|
164 | + // array(), |
|
165 | + // filemtime($this->domain->distributionAssetsPath() . 'style.css') |
|
166 | + // ); |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + public function registerScripts() |
|
171 | + { |
|
172 | + wp_register_script( |
|
173 | + 'ee-core-blocks', |
|
174 | + $this->assets_registry->getAssetUrl(Registry::ASSET_NAMESPACE, 'core-blocks', Registry::ASSET_TYPE_JS), |
|
175 | + array( |
|
176 | + 'eejs-core', |
|
177 | + 'wp-blocks', // Provides useful functions and components for extending the editor |
|
178 | + 'wp-i18n', // Provides localization functions |
|
179 | + 'wp-element', // Provides React.Component |
|
180 | + 'wp-components' // Provides many prebuilt components and controls |
|
181 | + ), |
|
182 | + null, |
|
183 | + true |
|
184 | + ); |
|
185 | + } |
|
186 | 186 | } |
@@ -38,103 +38,103 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | |
64 | 64 | } else { |
65 | - define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
66 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
67 | - /** |
|
68 | - * espresso_minimum_php_version_error |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
65 | + define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
66 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
67 | + /** |
|
68 | + * espresso_minimum_php_version_error |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.62.rc.032'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.62.rc.032'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | - bootstrap_espresso(); |
|
121 | - } |
|
119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | + bootstrap_espresso(); |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
124 | - /** |
|
125 | - * deactivate_plugin |
|
126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | - { |
|
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | - } |
|
137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | - deactivate_plugins($plugin_basename); |
|
139 | - } |
|
124 | + /** |
|
125 | + * deactivate_plugin |
|
126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | + { |
|
134 | + if (! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | + } |
|
137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | + deactivate_plugins($plugin_basename); |
|
139 | + } |
|
140 | 140 | } |