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' diff --git a/block-command.php b/block-command.php index 393d412..83f6d0f 100644 --- a/block-command.php +++ b/block-command.php @@ -43,8 +43,10 @@ } }; -// Register commands with appropriate version checks. +// Register the namespace command for better help screens. 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 ] ); 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 { } 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. *