Skip to content

Commit a5685f2

Browse files
committed
Namespace/Package change and phpcs updates
1 parent 2803f16 commit a5685f2

File tree

12 files changed

+78
-52
lines changed

12 files changed

+78
-52
lines changed

.phpcs.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
<property name="prefixes" type="array">
107107
<element value="VGTBT_"/>
108108
<element value="vgtbt_"/>
109-
<element value="VigetBlocksToolkit"/>
109+
<element value="Viget\BlocksToolkit"/>
110110
</property>
111111
</properties>
112112
</rule>

includes/assets.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
/**
33
* Assets
44
*
5-
* @package VigetBlocksToolkit
5+
* @package Viget\BlocksToolkit
66
*/
77

8+
namespace Viget\BlocksToolkit;
9+
810
add_action(
911
'admin_enqueue_scripts',
1012
function () {

includes/helpers.php

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
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

1010
if ( ! 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'];

includes/parts-kit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @package VigetBlocksToolkit
66
*/
77

8-
use Viget\VigetBlocksToolkit\Block_Registration;
8+
use Viget\BlocksToolkit\Block_Registration;
99

1010
add_filter(
1111
'vgtpk_parts_kit_block_%',

includes/timber.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
/**
33
* Timber Integration
44
*
5-
* @package VigetBlocksToolkit
5+
* @package Viget\BlocksToolkit
66
*/
77

8+
namespace Viget\BlocksToolkit;
9+
810
add_action(
911
'after_setup_theme',
1012
function () {
11-
if ( ! class_exists( 'Timber\Timber' ) ) {
13+
if ( ! class_exists( '\Timber\Timber' ) ) {
1214
return;
1315
}
1416

src/classes/BlockIcons.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
* Block Icons Support
44
*
55
* Inspired by Nick Diego's Enable Button Icons plugin.
6+
*
67
* @link https://github.com/ndiego/enable-button-icons
78
*
8-
* @package VigetBlocksToolkit
9+
* @package Viget\BlocksToolkit
910
*/
1011

11-
namespace Viget\VigetBlocksToolkit;
12+
namespace Viget\BlocksToolkit;
1213

1314
use WP_HTML_Tag_Processor;
1415

@@ -182,11 +183,11 @@ public function get_icons( bool $from_file = true ): array {
182183
}
183184

184185
/**
185-
* Filter the available button icons.
186+
* Filter the available block icons.
186187
*
187-
* @param array $icons The available button icons.
188+
* @param array $icons The available block icons.
188189
*/
189-
return apply_filters( 'vgtbt_button_icons', $icons );
190+
return apply_filters( 'vgtbt_block_icons', $icons );
190191
}
191192

192193
/**

src/classes/BlockRegistration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
/**
33
* ACF Block Registration
44
*
5-
* @package VigetBlocksToolkit
5+
* @package Viget\BlocksToolkit
66
*/
77

8-
namespace Viget\VigetBlocksToolkit;
8+
namespace Viget\BlocksToolkit;
99

1010
use Timber\Timber;
1111
use WP_Block;

src/classes/BlockTemplate/Block.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
/**
33
* Template Block
44
*
5-
* @package ACFFormBlocks
5+
* @package Viget\BlocksToolkit
66
*/
77

8-
namespace Viget\VigetBlocksToolkit\BlockTemplate;
8+
namespace Viget\BlocksToolkit\BlockTemplate;
99

1010
use Exception;
1111

@@ -86,8 +86,15 @@ public function get_name(): string {
8686
public function attr( string $key, mixed $value ): Block {
8787
$supported = $this->get_supported_attributes();
8888

89-
if ( ! in_array( $key, $supported ) ) {
90-
throw new Exception( 'Unsupported block attribute: ' . $key . '. Must be one of: ' . implode( ', ', $supported ) );
89+
if ( ! in_array( $key, $supported, true ) ) {
90+
throw new Exception(
91+
sprintf(
92+
// translators: %1$s represents the attribute key, %2$s lists the supported attributes.
93+
esc_html__( 'Unsupported block attribute: %1$s. Must be one of: %2$s', 'viget-blocks-toolkit' ),
94+
esc_html( $key ),
95+
esc_html( implode( ', ', $supported ) )
96+
)
97+
);
9198
}
9299

93100
$this->attributes[ $key ] = $value;
@@ -145,7 +152,7 @@ public function add( Block|string $block ): Block {
145152
$allowed = $this->get_allowed_blocks();
146153
$block_name = is_string( $block ) ? $block : $block->get_name();
147154

148-
if ( ! empty( $allowed ) && ! in_array( $block_name, $allowed ) ) {
155+
if ( ! empty( $allowed ) && ! in_array( $block_name, $allowed, true ) ) {
149156
throw new Exception( 'Block not allowed' );
150157
}
151158

src/classes/BlockTemplate/Template.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
*
55
* @link https://developer.wordpress.org/block-editor/reference-guides/block-api/block-templates/
66
*
7-
* @package ACFFormBlocks
7+
* @package Viget\BlocksToolkit
88
*/
99

10-
namespace Viget\VigetBlocksToolkit\BlockTemplate;
10+
namespace Viget\BlocksToolkit\BlockTemplate;
1111

1212
use Exception;
1313

src/classes/BreakpointVisibility.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
/**
33
* Breakpoint Visibility Support
44
*
5-
* @package VigetBlocksToolkit
5+
* @package Viget\BlocksToolkit
66
*/
77

8-
namespace Viget\VigetBlocksToolkit;
8+
namespace Viget\BlocksToolkit;
99

1010
/**
1111
* Breakpoint Visibility Class

src/classes/Core.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
/**
33
* Core API
44
*
5-
* @package VigetBlocksToolkit
5+
* @package Viget\BlocksToolkit
66
*/
77

8-
namespace Viget\VigetBlocksToolkit;
8+
namespace Viget\BlocksToolkit;
99

1010
/**
1111
* Core API

0 commit comments

Comments
 (0)