22/**
33 * Helper functions
44 *
5- * @package VigetBlocksToolkit
5+ * @package Viget\BlocksToolkit
66 */
77
8- use Viget \VigetBlocksToolkit \Core ;
8+ use Viget \BlocksToolkit \Core ;
99
1010if ( ! function_exists ( 'vgtbt ' ) ) {
1111 /**
1212 * Viget Blocks Toolkit Core API instance.
1313 *
1414 * @return Core
1515 */
16- function vgtbt (): Core {
16+ function vgtbt (): Core { // phpcs:ignore
1717 return Core::instance ();
1818 }
1919}
@@ -28,7 +28,7 @@ function vgtbt(): Core {
2828 * @param string $custom_class A custom class.
2929 * @param array $attrs Array of attributes.
3030 */
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
3232 $ id = ! empty ( $ attrs ['id ' ] ) ? $ attrs ['id ' ] : get_block_id ( $ block );
3333 $ id = apply_filters ( 'vgtbt_block_id_attr ' , $ id , $ block );
3434
@@ -80,6 +80,12 @@ function block_attrs( array $block, string $custom_class = '', array $attrs = []
8080 unset( $ attrs ['id ' ] );
8181 }
8282
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+
8389 foreach ( $ attrs as $ key => $ value ) {
8490 if ( is_null ( $ value ) ) {
8591 continue ;
@@ -91,6 +97,10 @@ function block_attrs( array $block, string $custom_class = '', array $attrs = []
9197
9298 do_action ( 'vgtbt_block_attr ' , $ block );
9399
100+ if ( is_null ( $ block_supports ::$ block_to_render ) ) {
101+ return ;
102+ }
103+
94104 echo wp_kses_data ( get_block_wrapper_attributes ( $ extra ) );
95105 }
96106}
@@ -106,7 +116,7 @@ function block_attrs( array $block, string $custom_class = '', array $attrs = []
106116 *
107117 * @return string
108118 */
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
110120 if ( ! empty ( $ block ['anchor ' ] ) && ! $ ignore_anchor ) {
111121 $ id = $ block ['anchor ' ];
112122 } elseif ( ! empty ( $ block ['blockId ' ] ) ) {
@@ -134,7 +144,7 @@ function get_block_id( array $block, bool $ignore_anchor = false ): string {
134144 *
135145 * @return string
136146 */
137- function get_block_class ( array $ block , string $ custom_class = '' ): string {
147+ function get_block_class ( array $ block , string $ custom_class = '' ): string { // phpcs:ignore
138148 $ classes = [
139149 'wp-block ' ,
140150 'acf-block ' ,
@@ -178,7 +188,7 @@ function get_block_class( array $block, string $custom_class = '' ): string {
178188 */
179189 function vgtbt_render_block ( string $ block_name , array $ props = [] ): void {
180190 if ( ! str_starts_with ( $ block_name , 'acf/ ' ) ) {
181- $ block_name = ' acf/ ' . $ block_name ;
191+ $ block_name = " acf/ $ block_name" ;
182192 }
183193
184194 $ block = array_merge (
@@ -211,7 +221,7 @@ function vgtbt_render_block( string $block_name, array $props = [] ): void {
211221 *
212222 * @return array|false
213223 */
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
215225 foreach ( $ blocks as $ block ) {
216226 if ( $ name === $ block ['blockName ' ] ) {
217227 return $ block ;
@@ -238,9 +248,9 @@ function get_block_from_blocks( string $name, array $blocks ): array|false {
238248 *
239249 * @return array
240250 */
241- function get_block_fields ( string $ block_name ): array {
251+ function get_block_fields ( string $ block_name ): array { // phpcs:ignore
242252 if ( ! str_starts_with ( $ block_name , 'acf/ ' ) ) {
243- $ block_name = ' acf/ ' . $ block_name ;
253+ $ block_name = " acf/ $ block_name" ;
244254 }
245255
246256 $ field_groups = acf_get_field_groups ();
@@ -282,7 +292,7 @@ function get_block_fields( string $block_name ): array {
282292 *
283293 * @return string
284294 */
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
286296 if ( null !== $ group_id ) {
287297 $ fields = acf_get_fields ( $ group_id );
288298 foreach ( $ fields as $ field_array ) {
@@ -314,15 +324,17 @@ function get_field_property( string $selector, string $property, ?string $group_
314324 * @since 1.0.0
315325 *
316326 * @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.
321333 * }
322334 *
323335 * @return void
324336 */
325- function inner_blocks ( array $ props = [] ): void {
337+ function inner_blocks ( array $ props = [] ): void { // phpcs:ignore
326338 $ json_encode = [ 'allowedBlocks ' , 'template ' ];
327339 $ attributes = '' ;
328340
@@ -333,7 +345,7 @@ function inner_blocks( array $props = [] ): void {
333345
334346 printf (
335347 '<InnerBlocks%s /> ' ,
336- $ attributes
348+ $ attributes // phpcs:ignore
337349 );
338350 }
339351}
@@ -349,7 +361,7 @@ function inner_blocks( array $props = [] ): void {
349361 *
350362 * @return void
351363 */
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
353365 if ( ! is_admin () || ! $ notice ) {
354366 return ;
355367 }
@@ -370,7 +382,7 @@ function print_admin_message( string $notice = '', string $class = 'vgtbt-admin-
370382 *
371383 * @return bool
372384 */
373- function is_acf_saving_field (): bool {
385+ function is_acf_saving_field (): bool { // phpcs:ignore
374386 global $ pagenow ;
375387
376388 if ( doing_action ( 'acf/update_field_group ' ) ) {
@@ -381,12 +393,12 @@ function is_acf_saving_field(): bool {
381393 return false ;
382394 }
383395
384- if ( empty ( $ _GET ['post ' ] ) || empty ( $ _GET ['action ' ] ) ) {
396+ if ( empty ( $ _GET ['post ' ] ) || empty ( $ _GET ['action ' ] ) ) { // phpcs:ignore
385397 return false ;
386398 }
387399
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
390402
391403 if ( 'edit ' === $ action && 'acf-field-group ' === get_post_type ( $ post_id ) ) {
392404 return true ;
@@ -404,7 +416,7 @@ function is_acf_saving_field(): bool {
404416 *
405417 * @return array
406418 */
407- function get_core_classes ( array $ block ): array {
419+ function get_core_classes ( array $ block ): array { // phpcs:ignore
408420 $ classes = [];
409421
410422 if ( ! empty ( $ block ['backgroundColor ' ] ) ) {
@@ -435,7 +447,7 @@ function get_core_classes( array $block ): array {
435447 *
436448 * @return string
437449 */
438- function get_core_styles ( array $ block ): string {
450+ function get_core_styles ( array $ block ): string { // phpcs:ignore
439451 if ( ! empty ( $ block ['style ' ] ) ) {
440452 $ styles = wp_style_engine_get_styles ( $ block ['style ' ] );
441453 return $ styles ['css ' ];
0 commit comments