From d3b22823e88c11423798cd5e43ffa42de78bf824 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Wed, 10 Dec 2025 01:19:03 +0000 Subject: [PATCH 1/4] Turn block into a command namespace --- block-command.php | 6 +++++- src/Block_Command.php | 7 ++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/block-command.php b/block-command.php index 393d412..d9ebacf 100644 --- a/block-command.php +++ b/block-command.php @@ -43,8 +43,12 @@ } }; +// Register the namespace command for better help screens. +if ( class_exists( 'WP_CLI\Dispatcher\CommandNamespace' ) ) { + WP_CLI::add_command( 'block', WP_CLI\Block\Block_Command::class ); +} + // Register commands with appropriate version checks. -WP_CLI::add_command( 'block', WP_CLI\Block\Block_Command::class ); WP_CLI::add_command( 'block type', WP_CLI\Block\Block_Type_Command::class, [ 'before_invoke' => $wpcli_block_before_invoke_5_0 ] ); WP_CLI::add_command( 'block pattern', WP_CLI\Block\Block_Pattern_Command::class, [ 'before_invoke' => $wpcli_block_before_invoke_5_5 ] ); WP_CLI::add_command( 'block pattern-category', WP_CLI\Block\Block_Pattern_Category_Command::class, [ 'before_invoke' => $wpcli_block_before_invoke_5_5 ] ); diff --git a/src/Block_Command.php b/src/Block_Command.php index e048b41..0dae254 100644 --- a/src/Block_Command.php +++ b/src/Block_Command.php @@ -2,14 +2,11 @@ namespace WP_CLI\Block; -use WP_CLI_Command; +use WP_CLI\Dispatcher\CommandNamespace; /** * Manages WordPress block editor blocks and related entities. * - * This command provides tools for working with the WordPress block editor, - * including block types, patterns, styles, bindings, templates, and synced patterns. - * * ## EXAMPLES * * # List all registered block types @@ -29,5 +26,5 @@ * * @package wp-cli */ -class Block_Command extends WP_CLI_Command { +class Block_Command extends CommandNamespace { } From 292610516305ec60970333d23200d289ef463cec Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Wed, 10 Dec 2025 01:59:21 +0000 Subject: [PATCH 2/4] Skip WP matrix that has no test scenarios --- .github/workflows/testing.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index bf67592..da46cbc 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -13,3 +13,5 @@ on: jobs: test: uses: wp-cli/.github/.github/workflows/reusable-testing.yml@main + with: + minimum-wp: '5.0' From bfc7fe978136576522a10cd72f5283967d27224a Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Wed, 10 Dec 2025 02:02:13 +0000 Subject: [PATCH 3/4] Register command namespace unconditionally --- block-command.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/block-command.php b/block-command.php index d9ebacf..83f6d0f 100644 --- a/block-command.php +++ b/block-command.php @@ -44,9 +44,7 @@ }; // Register the namespace command for better help screens. -if ( class_exists( 'WP_CLI\Dispatcher\CommandNamespace' ) ) { - WP_CLI::add_command( 'block', WP_CLI\Block\Block_Command::class ); -} +WP_CLI::add_command( 'block', WP_CLI\Block\Block_Command::class ); // Register commands with appropriate version checks. WP_CLI::add_command( 'block type', WP_CLI\Block\Block_Type_Command::class, [ 'before_invoke' => $wpcli_block_before_invoke_5_0 ] ); From 68e9559a5a277a13e6c4c03c13252d0d3e22d344 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Wed, 10 Dec 2025 11:20:24 +0000 Subject: [PATCH 4/4] Fix PHP notices on missing block type properties --- src/Block_Type_Command.php | 62 +++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/src/Block_Type_Command.php b/src/Block_Type_Command.php index 1a38d79..8a94c07 100644 --- a/src/Block_Type_Command.php +++ b/src/Block_Type_Command.php @@ -262,34 +262,48 @@ public function get( $args, $assoc_args ) { private function block_type_to_array( $block_type ) { return [ 'name' => $block_type->name, - 'title' => $block_type->title, - 'description' => $block_type->description, - 'category' => $block_type->category, + 'title' => $this->get_block_type_property( $block_type, 'title' ), + 'description' => $this->get_block_type_property( $block_type, 'description' ), + 'category' => $this->get_block_type_property( $block_type, 'category' ), 'is_dynamic' => $block_type->is_dynamic(), - 'icon' => $block_type->icon, - 'keywords' => $block_type->keywords, - 'parent' => $block_type->parent, - 'ancestor' => $block_type->ancestor, - 'allowed_blocks' => $block_type->allowed_blocks, - 'supports' => $block_type->supports, - 'attributes' => $block_type->attributes, - 'provides_context' => $block_type->provides_context, - 'uses_context' => $block_type->uses_context, - 'block_hooks' => $block_type->block_hooks, - 'selectors' => $block_type->selectors, - 'styles' => $block_type->styles, - 'example' => $block_type->example, - 'editor_script_handles' => $block_type->editor_script_handles, - 'script_handles' => $block_type->script_handles, - 'view_script_handles' => $block_type->view_script_handles, - 'view_script_module_ids' => $block_type->view_script_module_ids, - 'editor_style_handles' => $block_type->editor_style_handles, - 'style_handles' => $block_type->style_handles, - 'view_style_handles' => $block_type->view_style_handles, - 'api_version' => $block_type->api_version, + 'icon' => $this->get_block_type_property( $block_type, 'icon' ), + 'keywords' => $this->get_block_type_property( $block_type, 'keywords' ), + 'parent' => $this->get_block_type_property( $block_type, 'parent' ), + 'ancestor' => $this->get_block_type_property( $block_type, 'ancestor' ), + 'allowed_blocks' => $this->get_block_type_property( $block_type, 'allowed_blocks' ), + 'supports' => $this->get_block_type_property( $block_type, 'supports' ), + 'attributes' => $this->get_block_type_property( $block_type, 'attributes' ), + 'provides_context' => $this->get_block_type_property( $block_type, 'provides_context' ), + 'uses_context' => $this->get_block_type_property( $block_type, 'uses_context' ), + 'block_hooks' => $this->get_block_type_property( $block_type, 'block_hooks' ), + 'selectors' => $this->get_block_type_property( $block_type, 'selectors' ), + 'styles' => $this->get_block_type_property( $block_type, 'styles' ), + 'example' => $this->get_block_type_property( $block_type, 'example' ), + 'editor_script_handles' => $this->get_block_type_property( $block_type, 'editor_script_handles' ), + 'script_handles' => $this->get_block_type_property( $block_type, 'script_handles' ), + 'view_script_handles' => $this->get_block_type_property( $block_type, 'view_script_handles' ), + 'view_script_module_ids' => $this->get_block_type_property( $block_type, 'view_script_module_ids' ), + 'editor_style_handles' => $this->get_block_type_property( $block_type, 'editor_style_handles' ), + 'style_handles' => $this->get_block_type_property( $block_type, 'style_handles' ), + 'view_style_handles' => $this->get_block_type_property( $block_type, 'view_style_handles' ), + 'api_version' => $this->get_block_type_property( $block_type, 'api_version' ), ]; } + /** + * Safely gets a property from a WP_Block_Type object. + * + * Some properties may not exist on all block types depending on WordPress + * version or how the block was registered. + * + * @param WP_Block_Type $block_type Block type object. + * @param string $property Property name. + * @return mixed|null Property value or null if not set. + */ + private function get_block_type_property( $block_type, $property ) { + return isset( $block_type->$property ) ? $block_type->$property : null; + } + /** * Gets the formatter instance. *