PluginProbe
Getwid – Gutenberg Blocks / 3.0.2
Getwid – Gutenberg Blocks v3.0.2
3.0.2 3.0.1 3.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.2.0 trunk 1.8.7 1.9.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9
← All changes | includes/blocks-manager.php +70 -37 2.1.23.0.2 View file →
@@ -7,10 +7,10 @@
7 7 * @package Getwid
8 8 */
9 9 class BlocksManager {
10 10
11 - private $blocks = array();
12 - private $enabledBlocks = array();
11 + private $blocks = array();
12 + private $enabledBlocks = array();
13 13 private $disabledBlocks = array();
14 14
15 15 /**
16 16 * BlockManager constructor.
@@ -22,9 +22,11 @@
22 22 } else {
23 23 add_filter( 'block_categories', array( $this, 'block_categories' ), 10, 2 );
24 24 }
25 25
26 - add_action( 'init', [$this, 'includeBlocks'] );
26 + add_action( 'init', array( $this, 'includeBlocks' ) );
27 +
28 + add_filter( 'block_type_metadata_settings', array( $this, 'filter_block_type_metadata_settings' ), 10, 2 );
27 29 }
28 30
29 31 public function block_categories_all( $block_categories, $editor_context ) {
30 32
@@ -32,9 +34,9 @@
32 34 $block_categories = array_merge(
33 35 $block_categories,
34 36 array(
35 37 array(
36 - 'slug' => 'getwid-blocks',
38 + 'slug' => 'getwid-blocks',
37 39 'title' => __( 'Getwid Blocks', 'getwid' ),
38 40 ),
39 41 )
40 42 );
@@ -44,9 +46,9 @@
44 46 $block_categories = array_merge(
45 47 $block_categories,
46 48 array(
47 49 array(
48 - 'slug' => 'getwid-post-blocks',
50 + 'slug' => 'getwid-post-blocks',
49 51 'title' => __( 'Getwid Post Blocks', 'getwid' ),
50 52 ),
51 53 )
52 54 );
@@ -57,9 +59,9 @@
57 59 $block_categories = array_merge(
58 60 $block_categories,
59 61 array(
60 62 array(
61 - 'slug' => 'getwid-acf-blocks',
63 + 'slug' => 'getwid-acf-blocks',
62 64 'title' => __( 'Getwid ACF Blocks', 'getwid' ),
63 65 ),
64 66 )
65 67 );
@@ -75,9 +77,9 @@
75 77 $categories = array_merge(
76 78 $categories,
77 79 array(
78 80 array(
79 - 'slug' => 'getwid-blocks',
81 + 'slug' => 'getwid-blocks',
80 82 'title' => __( 'Getwid Blocks', 'getwid' ),
81 83 ),
82 84 )
83 85 );
@@ -87,9 +89,9 @@
87 89 $categories = array_merge(
88 90 $categories,
89 91 array(
90 92 array(
91 - 'slug' => 'getwid-post-blocks',
93 + 'slug' => 'getwid-post-blocks',
92 94 'title' => __( 'Getwid Post Blocks', 'getwid' ),
93 95 ),
94 96 )
95 97 );
@@ -100,9 +102,9 @@
100 102 $categories = array_merge(
101 103 $categories,
102 104 array(
103 105 array(
104 - 'slug' => 'getwid-acf-blocks',
106 + 'slug' => 'getwid-acf-blocks',
105 107 'title' => __( 'Getwid ACF Blocks', 'getwid' ),
106 108 ),
107 109 )
108 110 );
@@ -155,26 +157,16 @@
155 157 'contact-form',
156 158 'mailchimp',
157 159 'content-timeline',
158 160 'table',
159 - 'content-slider'
161 + 'content-slider',
160 162 );
161 163
162 164 // load and register main blocks
163 165 foreach ( $block_files as $block_file_name ) {
164 - $this->require_block($block_file_name);
166 + $this->require_block( $block_file_name );
165 167 }
166 168
167 - // fill array of active blocks
168 - foreach ( $this->blocks as $block ) {
169 -
170 - if ( $block->isEnabled() ) {
171 - $this->enabledBlocks[] = $block;
172 - } else {
173 - $this->disabledBlocks[] = $block;
174 - }
175 - }
176 -
177 169 $template_parts = array(
178 170 'template-parts/post-title',
179 171 'template-parts/post-featured-image',
180 172 'template-parts/post-content',
@@ -192,9 +184,9 @@
192 184 );
193 185
194 186 // load template-parts blocks
195 187 foreach ( $template_parts as $block_file_name ) {
196 - $this->require_block($block_file_name);
188 + $this->require_block( $block_file_name );
197 189 }
198 190
199 191 $template_parts_acf = array(
200 192 'template-parts/acf/background-image',
@@ -204,11 +196,20 @@
204 196 );
205 197
206 198 // load template-acf blocks
207 199 foreach ( $template_parts_acf as $block_file_name ) {
208 - $this->require_block($block_file_name);
200 + $this->require_block( $block_file_name );
209 201 }
210 202
203 + // fill array of active blocks
204 + foreach ( $this->blocks as $block ) {
205 +
206 + if ( $block->is_enabled() ) {
207 + $this->enabledBlocks[] = $block;
208 + } else {
209 + $this->disabledBlocks[] = $block;
210 + }
211 + }
211 212 }
212 213
213 214 private function require_block( $block_file_name ) {
214 215
@@ -214,9 +215,9 @@
214 215
215 216 $path = getwid_get_plugin_path( '/includes/blocks/' . $block_file_name . '.php' );
216 217
217 218 if ( file_exists( $path ) ) {
218 - require_once( $path );
219 + require_once $path;
219 220 }
220 221 }
221 222
222 223 public function addBlock( $block ) {
@@ -221,9 +222,9 @@
221 222
222 223 public function addBlock( $block ) {
223 224
224 225 if ( $block instanceof \Getwid\Blocks\AbstractBlock ) {
225 - $this->blocks[ $block::getBlockName() ] = $block;
226 + $this->blocks[ $block->get_block_name() ] = $block;
226 227 }
227 228 }
228 229
229 230 public function getBlocks() {
@@ -229,8 +230,17 @@
229 230 public function getBlocks() {
230 231 return $this->blocks;
231 232 }
232 233
234 + public function getControlledBlocks() {
235 + return array_filter(
236 + $this->getBlocks(),
237 + function ( $block ) {
238 + return $block->can_be_disabled();
239 + }
240 + );
241 + }
242 +
233 243 public function getEnabledBlocks() {
234 244 return $this->enabledBlocks;
235 245 }
236 246
@@ -238,13 +248,13 @@
238 248 return $this->disabledBlocks;
239 249 }
240 250
241 251 public function hasEnabledBlocks() {
242 - return ( sizeof ($this->enabledBlocks ) > 0 );
252 + return ( sizeof( $this->enabledBlocks ) > 0 );
243 253 }
244 254
245 255 public function hasDisabledBlocks() {
246 - return ( sizeof ($this->disabledBlocks ) > 0 );
256 + return ( sizeof( $this->disabledBlocks ) > 0 );
247 257 }
248 258
249 259 /**
250 260 * Determine whether a post or content string has Getwid blocks.
@@ -257,9 +267,9 @@
257 267
258 268 $blocks = $this->getBlocks();
259 269 foreach ( $blocks as $block ) {
260 270
261 - if ( has_block( $block->getBlockName() ) ) {
271 + if ( has_block( $block->get_block_name() ) ) {
262 272 $has_getwid_blocks = true;
263 273 break;
264 274 }
265 275 }
@@ -264,9 +274,9 @@
264 274 }
265 275 }
266 276 }
267 277
268 - return apply_filters( 'getwid/blocks/has_getwid_blocks', $has_getwid_blocks);
278 + return apply_filters( 'getwid/blocks/has_getwid_blocks', $has_getwid_blocks );
269 279 }
270 280
271 281 public function hasGetwidNestedBlocks() {
272 282
@@ -271,21 +281,44 @@
271 281 public function hasGetwidNestedBlocks() {
272 282
273 283 $has_getwid_nested_blocks = false;
274 284
275 - $nestedBlocks = [
276 - \Getwid\Blocks\PostCarousel::getBlockName(),
277 - \Getwid\Blocks\PostSlider::getBlockName(),
278 - \Getwid\Blocks\CustomPostType::getBlockName(),
279 - ];
285 + $nestedBlocks = array(
286 + 'getwid/post-carousel',
287 + 'getwid/post-slider',
288 + 'getwid/custom-post-type',
289 + );
280 290
281 - foreach( $nestedBlocks as $block ) {
282 - if ( has_block($block) ) {
291 + foreach ( $nestedBlocks as $block ) {
292 + if ( has_block( $block ) ) {
283 293 $has_getwid_nested_blocks = true;
284 294 break;
285 295 }
286 296 }
287 297
288 - return apply_filters( 'getwid/blocks/has_getwid_nested_blocks', $has_getwid_nested_blocks);
298 + return apply_filters( 'getwid/blocks/has_getwid_nested_blocks', $has_getwid_nested_blocks );
289 299 }
290 300
301 + public function filter_block_type_metadata_settings( $settings, $metadata ) {
302 +
303 + $blocks = array(
304 + 'getwid/accordion',
305 + 'getwid/custom-post-type',
306 + 'getwid/icon-box',
307 + 'getwid/icon',
308 + 'getwid/icon',
309 + 'getwid/image-hotspot',
310 + 'getwid/post-carousel',
311 + 'getwid/post-slider',
312 + 'getwid/section',
313 + 'getwid/social-links',
314 + 'getwid/toggle',
315 + 'getwid/video-popup',
316 + );
317 +
318 + if ( in_array( $metadata['name'], $blocks ) ) {
319 + $settings['style_handles'] = getwid()->fontIconsManager()->enqueueFonts( $settings['style_handles'] );
320 + }
321 +
322 + return $settings;
323 + }
291 324 }