Skip to content

Conversation

Copy link

Copilot AI commented Nov 11, 2025

Implements block management commands for WordPress 5.0+ as requested in wp-cli/ideas#119.

Changes

New Commands

Block Type Management (WordPress 5.0+)

  • wp block list - Lists registered block types from WP_Block_Type_Registry
  • wp block get <name> - Gets block type details (title, category, supports, etc.)

Block Pattern Management (WordPress 5.5+)

  • wp pattern list [--category=<cat>] - Lists registered patterns from WP_Block_Patterns_Registry (supports table, csv, json, count, yaml, and ids formats)
  • wp pattern get <name> - Gets pattern details (content, categories, keywords, etc.)

Post Block Operations (WordPress 5.0+)

  • wp post has-blocks <id> - Uses has_blocks() to check if post contains blocks
  • wp post has-block <id> <block> - Uses has_block() to check for specific block type
  • wp post parse-blocks <id> - Outputs parse_blocks() result as JSON/YAML (uses Spyc::YAMLDump() for YAML output)
  • wp post render-blocks <id> - Outputs do_blocks() rendered HTML
  • wp post get now includes block_version field from block_version()

Implementation

Commands use before_invoke hooks with Utils\wp_version_compare() to enforce version requirements. Post subcommands check function existence at runtime with consistent error messages ("This command requires WordPress 5.0 or greater.").

Example usage:

# Check if post uses blocks
$ wp post has-blocks 123
Success: Post 123 has blocks.

# Parse block structure
$ wp post parse-blocks 123 --format=json
[{"blockName":"core/paragraph","attrs":{},...}]

# List block types with category filter
$ wp block list --fields=name,title,category

# Filter patterns by category
$ wp pattern list --category=buttons

Testing

Behat tests cover all commands including:

Original prompt

This section details on the original issue you should resolve

<issue_title>Initial set of block-related commands</issue_title>
<issue_description>From wp-cli/ideas#119

Some more concrete ideas:

  • wp post has-blocks <id> - Whether the post has any blocks. Uses the has_blocks() function.
  • wp post has-block <id> <block> - Whether the post contains any specific block type. Uses the has_block() function.
  • Add a new block_version field to wp post get that uses block_version()
  • wp block list - List all registered block types (WP_Block_Type_Registry)
  • wp block get <block> - Get information about a specific registered block type (WP_Block_Type)
  • wp block parse <id> - Run parse_blocks() on a specific post ID and return the raw JSON tree structure.
  • wp block render <id> - Run do_blocks() to render the specific blocks of a post and return the final HTML.
  • wp pattern list [--category=<cat>] - List all registered block patterns (WP_Block_Patterns_Registry).
  • wp pattern get <id> - Get a specific block pattern

Notes:

  • This functionality was added in WordPress 5.0+, but we still support WordPress 4.9. Thus, we need to make these commands available only conditionally, for example with a before_invoke hook and an appropriate error message.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits November 11, 2025 09:36
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
…r handling

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Add initial set of block-related commands Add block-related commands for WordPress 5.0+ Nov 11, 2025
Copilot AI requested a review from swissspidy November 11, 2025 09:45
Copilot finished work on behalf of swissspidy November 11, 2025 09:45
swissspidy

This comment was marked as resolved.

…tation

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI requested a review from swissspidy November 11, 2025 10:37
Copilot finished work on behalf of swissspidy November 11, 2025 10:37
@swissspidy swissspidy added this to the 2.9.0 milestone Nov 11, 2025
@swissspidy swissspidy changed the title Add block-related commands for WordPress 5.0+ Add initial set of block-related commands Nov 11, 2025
@swissspidy swissspidy marked this pull request as ready for review November 11, 2025 13:34
@swissspidy swissspidy requested a review from a team as a code owner November 11, 2025 13:34
@codecov
Copy link

codecov bot commented Nov 11, 2025

Codecov Report

❌ Patch coverage is 93.07692% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/Post_Command.php 89.18% 4 Missing ⚠️
src/Pattern_Command.php 91.89% 3 Missing ⚠️
entity-command.php 88.88% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI requested a review from swissspidy November 11, 2025 15:09
Copilot finished work on behalf of swissspidy November 11, 2025 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Initial set of block-related commands

2 participants