2
2
/**
3
3
* Helper functions
4
4
*
5
- * @package VigetBlocksToolkit
5
+ * @package Viget\BlocksToolkit
6
6
*/
7
7
8
- use Viget \VigetBlocksToolkit \Core ;
8
+ use Viget \BlocksToolkit \Core ;
9
9
10
10
if ( ! function_exists ( 'vgtbt ' ) ) {
11
11
/**
12
12
* Viget Blocks Toolkit Core API instance.
13
13
*
14
14
* @return Core
15
15
*/
16
- function vgtbt (): Core {
16
+ function vgtbt (): Core { // phpcs:ignore
17
17
return Core::instance ();
18
18
}
19
19
}
@@ -28,7 +28,7 @@ function vgtbt(): Core {
28
28
* @param string $custom_class A custom class.
29
29
* @param array $attrs Array of attributes.
30
30
*/
31
- function block_attrs ( array $ block , string $ custom_class = '' , array $ attrs = [] ): void {
31
+ function block_attrs ( array $ block , string $ custom_class = '' , array $ attrs = [] ): void { // phpcs:ignore
32
32
$ id = ! empty ( $ attrs ['id ' ] ) ? $ attrs ['id ' ] : get_block_id ( $ block );
33
33
$ id = apply_filters ( 'vgtbt_block_id_attr ' , $ id , $ block );
34
34
@@ -80,6 +80,12 @@ function block_attrs( array $block, string $custom_class = '', array $attrs = []
80
80
unset( $ attrs ['id ' ] );
81
81
}
82
82
83
+ $ block_supports = WP_Block_Supports::get_instance ();
84
+
85
+ if ( is_null ( $ block_supports ::$ block_to_render ) ) {
86
+ $ attrs = array_merge ( $ attrs , $ extra );
87
+ }
88
+
83
89
foreach ( $ attrs as $ key => $ value ) {
84
90
if ( is_null ( $ value ) ) {
85
91
continue ;
@@ -91,6 +97,10 @@ function block_attrs( array $block, string $custom_class = '', array $attrs = []
91
97
92
98
do_action ( 'vgtbt_block_attr ' , $ block );
93
99
100
+ if ( is_null ( $ block_supports ::$ block_to_render ) ) {
101
+ return ;
102
+ }
103
+
94
104
echo wp_kses_data ( get_block_wrapper_attributes ( $ extra ) );
95
105
}
96
106
}
@@ -106,7 +116,7 @@ function block_attrs( array $block, string $custom_class = '', array $attrs = []
106
116
*
107
117
* @return string
108
118
*/
109
- function get_block_id ( array $ block , bool $ ignore_anchor = false ): string {
119
+ function get_block_id ( array $ block , bool $ ignore_anchor = false ): string { // phpcs:ignore
110
120
if ( ! empty ( $ block ['anchor ' ] ) && ! $ ignore_anchor ) {
111
121
$ id = $ block ['anchor ' ];
112
122
} elseif ( ! empty ( $ block ['blockId ' ] ) ) {
@@ -134,7 +144,7 @@ function get_block_id( array $block, bool $ignore_anchor = false ): string {
134
144
*
135
145
* @return string
136
146
*/
137
- function get_block_class ( array $ block , string $ custom_class = '' ): string {
147
+ function get_block_class ( array $ block , string $ custom_class = '' ): string { // phpcs:ignore
138
148
$ classes = [
139
149
'wp-block ' ,
140
150
'acf-block ' ,
@@ -178,7 +188,7 @@ function get_block_class( array $block, string $custom_class = '' ): string {
178
188
*/
179
189
function vgtbt_render_block ( string $ block_name , array $ props = [] ): void {
180
190
if ( ! str_starts_with ( $ block_name , 'acf/ ' ) ) {
181
- $ block_name = ' acf/ ' . $ block_name ;
191
+ $ block_name = " acf/ $ block_name" ;
182
192
}
183
193
184
194
$ block = array_merge (
@@ -211,7 +221,7 @@ function vgtbt_render_block( string $block_name, array $props = [] ): void {
211
221
*
212
222
* @return array|false
213
223
*/
214
- function get_block_from_blocks ( string $ name , array $ blocks ): array |false {
224
+ function get_block_from_blocks ( string $ name , array $ blocks ): array |false { // phpcs:ignore
215
225
foreach ( $ blocks as $ block ) {
216
226
if ( $ name === $ block ['blockName ' ] ) {
217
227
return $ block ;
@@ -238,9 +248,9 @@ function get_block_from_blocks( string $name, array $blocks ): array|false {
238
248
*
239
249
* @return array
240
250
*/
241
- function get_block_fields ( string $ block_name ): array {
251
+ function get_block_fields ( string $ block_name ): array { // phpcs:ignore
242
252
if ( ! str_starts_with ( $ block_name , 'acf/ ' ) ) {
243
- $ block_name = ' acf/ ' . $ block_name ;
253
+ $ block_name = " acf/ $ block_name" ;
244
254
}
245
255
246
256
$ field_groups = acf_get_field_groups ();
@@ -282,7 +292,7 @@ function get_block_fields( string $block_name ): array {
282
292
*
283
293
* @return string
284
294
*/
285
- function get_field_property ( string $ selector , string $ property , ?string $ group_id = null ): string {
295
+ function get_field_property ( string $ selector , string $ property , ?string $ group_id = null ): string { // phpcs:ignore
286
296
if ( null !== $ group_id ) {
287
297
$ fields = acf_get_fields ( $ group_id );
288
298
foreach ( $ fields as $ field_array ) {
@@ -314,15 +324,17 @@ function get_field_property( string $selector, string $property, ?string $group_
314
324
* @since 1.0.0
315
325
*
316
326
* @param array $props {
317
- * @type array $allowedBlocks Allowed blocks
318
- * @type array $template Block Template
319
- * @type string $templateLock Template Lock
320
- * @type string $className Class Name
327
+ * The properties array.
328
+ *
329
+ * @type array $allowedBlocks The allowed blocks.
330
+ * @type array $template The block template.
331
+ * @type string $templateLock The template lock.
332
+ * @type string $className The class name.
321
333
* }
322
334
*
323
335
* @return void
324
336
*/
325
- function inner_blocks ( array $ props = [] ): void {
337
+ function inner_blocks ( array $ props = [] ): void { // phpcs:ignore
326
338
$ json_encode = [ 'allowedBlocks ' , 'template ' ];
327
339
$ attributes = '' ;
328
340
@@ -333,7 +345,7 @@ function inner_blocks( array $props = [] ): void {
333
345
334
346
printf (
335
347
'<InnerBlocks%s /> ' ,
336
- $ attributes
348
+ $ attributes // phpcs:ignore
337
349
);
338
350
}
339
351
}
@@ -349,7 +361,7 @@ function inner_blocks( array $props = [] ): void {
349
361
*
350
362
* @return void
351
363
*/
352
- function print_admin_message ( string $ notice = '' , string $ class = 'vgtbt-admin-message ' ): void {
364
+ function print_admin_message ( string $ notice = '' , string $ class = 'vgtbt-admin-message ' ): void { // phpcs:ignore
353
365
if ( ! is_admin () || ! $ notice ) {
354
366
return ;
355
367
}
@@ -370,7 +382,7 @@ function print_admin_message( string $notice = '', string $class = 'vgtbt-admin-
370
382
*
371
383
* @return bool
372
384
*/
373
- function is_acf_saving_field (): bool {
385
+ function is_acf_saving_field (): bool { // phpcs:ignore
374
386
global $ pagenow ;
375
387
376
388
if ( doing_action ( 'acf/update_field_group ' ) ) {
@@ -381,12 +393,12 @@ function is_acf_saving_field(): bool {
381
393
return false ;
382
394
}
383
395
384
- if ( empty ( $ _GET ['post ' ] ) || empty ( $ _GET ['action ' ] ) ) {
396
+ if ( empty ( $ _GET ['post ' ] ) || empty ( $ _GET ['action ' ] ) ) { // phpcs:ignore
385
397
return false ;
386
398
}
387
399
388
- $ post_id = sanitize_text_field ( wp_unslash ( $ _GET ['post ' ] ) );
389
- $ action = sanitize_text_field ( wp_unslash ( $ _GET ['action ' ] ) );
400
+ $ post_id = sanitize_text_field ( wp_unslash ( $ _GET ['post ' ] ) ); // phpcs:ignore
401
+ $ action = sanitize_text_field ( wp_unslash ( $ _GET ['action ' ] ) ); // phpcs:ignore
390
402
391
403
if ( 'edit ' === $ action && 'acf-field-group ' === get_post_type ( $ post_id ) ) {
392
404
return true ;
@@ -404,7 +416,7 @@ function is_acf_saving_field(): bool {
404
416
*
405
417
* @return array
406
418
*/
407
- function get_core_classes ( array $ block ): array {
419
+ function get_core_classes ( array $ block ): array { // phpcs:ignore
408
420
$ classes = [];
409
421
410
422
if ( ! empty ( $ block ['backgroundColor ' ] ) ) {
@@ -435,7 +447,7 @@ function get_core_classes( array $block ): array {
435
447
*
436
448
* @return string
437
449
*/
438
- function get_core_styles ( array $ block ): string {
450
+ function get_core_styles ( array $ block ): string { // phpcs:ignore
439
451
if ( ! empty ( $ block ['style ' ] ) ) {
440
452
$ styles = wp_style_engine_get_styles ( $ block ['style ' ] );
441
453
return $ styles ['css ' ];
0 commit comments