Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ on:
jobs:
test:
uses: wp-cli/.github/.github/workflows/reusable-testing.yml@main
with:
minimum-wp: '5.0'
4 changes: 3 additions & 1 deletion block-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ] );
Expand Down
7 changes: 2 additions & 5 deletions src/Block_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,5 +26,5 @@
*
* @package wp-cli
*/
class Block_Command extends WP_CLI_Command {
class Block_Command extends CommandNamespace {
}
62 changes: 38 additions & 24 deletions src/Block_Type_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Loading