You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There's very little server side interface to Gutenberg, so we're quite limited in what can be done on the CLI. WordPress/gutenberg#4116
Here's some requests I've seen mentioned at HM and elsewhere:
Ability to filter result sets by block based or non block based posts.
Ability to convert non-Gutenberg posts to block-based posts (to remove responsibility from the client) along with reporting of non-transformable or potentially problematic markup.
Ability to fetch IDs of all posts that contain a given block type. Ended up doing it via a regular string search.
Ability to filter result sets by block based or non block based posts.
This reminds of the block_version() function which returns the version of the block format that the content string is using. This is something that could be exposed when listing posts etc.
Ability to convert non-Gutenberg posts to block-based posts
This is probably not gonna be possible as all the block transforms are written in JavaScript.
Ability to fetch IDs of all posts that contain a given block type
Something else that might be worth considering here is updating non-dynamic blocks when the block definition is modified. Right now, it seems like the only way to do that is to manually open every post where the block is used and resave it.
I've been following the discussion here about this for a little while and WP-CLI was mentioned as a possible solution. Of course, in that comment, he's talking about doing a DB find and replace which is already supported, but that would probably be a bit messy and error prone. If WP-CLI had first class support for this type of operation that might go along way to solving the problem.
Something else that might be worth considering here is updating non-dynamic blocks when the block definition is modified.
As soon as that information is available in PHP, sure.
The problem here - as with block transforms available in PHP - is that this will be something all developers have to opt in first. Which means it can take a while until this will be truly helpful.
There's more and more work being done on improving the server-side awareness of blocks, so I'm approving the general idea of adding a wp block command here.
It needs to be fleshed out, of course, but we could already start with basic commands that hook into what we got for now. We might want to keep it as a non-bundled command while we're figuring out the interface.
I would like to be able to create a page and add a block during the create script for wp-env. I.e. declaratively set up the pages which will be used by my E2E tests.
Currently I have a WooCommerce Blocks-Checkout post_content saved in a txt file which I then import. The single Checkout block comprises of ~22 blocks. (looks like that's how WooCommerce also do it)
Saving the existing one isn't too difficult:
wp post get $(wp post list --post_type=page --title="Blocks Checkout" --format=ids) --field=post_content > blocks_checkout-post_content.txt
And I insert it with:
wp post create --post_type=page --post_title="Blocks Checkout" --post_status=publish ./path/to/blocks-checkout-post-content.txt
But it would be neater to do something like:
wp block add $POST_ID wp:woocommerce/checkout
// or
wp block add $(wp post create --post_type=page --post_title="Blocks Checkout" --post_status=publish --porcelain) wp:woocommerce/checkout
Reusable blocks (wp_block post type) are now named patterns. They can probably already be interacted with using wp post --post_type=wp_block, but nonetheless could benefit from some more block awareness (e.g. the blocks included in the pattern, block version, etc.)
Nowadays widgets can also be blocks. I don't know how well that works with https://github.com/wp-cli/widget-command... Probably not at all? So there might be some room for improvement there as well.
Activity
johnbillion commentedon Dec 21, 2018
There's very little server side interface to Gutenberg, so we're quite limited in what can be done on the CLI. WordPress/gutenberg#4116
Here's some requests I've seen mentioned at HM and elsewhere:
swissspidy commentedon Dec 21, 2018
This reminds of the
block_version()function which returns the version of the block format that the content string is using. This is something that could be exposed when listing posts etc.This is probably not gonna be possible as all the block transforms are written in JavaScript.
👍 + including reusable blocks.
schlessera commentedon Dec 21, 2018
Easy... =>
wp eval-js "transform_block( source, dest );";)dominic-p commentedon Jan 21, 2019
Something else that might be worth considering here is updating non-dynamic blocks when the block definition is modified. Right now, it seems like the only way to do that is to manually open every post where the block is used and resave it.
I've been following the discussion here about this for a little while and WP-CLI was mentioned as a possible solution. Of course, in that comment, he's talking about doing a DB find and replace which is already supported, but that would probably be a bit messy and error prone. If WP-CLI had first class support for this type of operation that might go along way to solving the problem.
swissspidy commentedon Jan 21, 2019
As soon as that information is available in PHP, sure.
The problem here - as with block transforms available in PHP - is that this will be something all developers have to opt in first. Which means it can take a while until this will be truly helpful.
swissspidy commentedon Mar 22, 2019
Some updates regarding server-side awareness of blocks:
WordPress/gutenberg#2751
WordPress/gutenberg#13693
schlessera commentedon Mar 30, 2019
There's more and more work being done on improving the server-side awareness of blocks, so I'm approving the general idea of adding a
wp blockcommand here.It needs to be fleshed out, of course, but we could already start with basic commands that hook into what we got for now. We might want to keep it as a non-bundled command while we're figuring out the interface.
johnbillion commentedon Jul 2, 2020
Further updates:
BrianHenryIE commentedon Aug 17, 2023
I would like to be able to create a page and add a block during the create script for wp-env. I.e. declaratively set up the pages which will be used by my E2E tests.
Currently I have a WooCommerce Blocks-Checkout post_content saved in a txt file which I then import. The single Checkout block comprises of ~22 blocks. (looks like that's how WooCommerce also do it)
Saving the existing one isn't too difficult:
And I insert it with:
But it would be neater to do something like:
swissspidy commentedon Apr 26, 2024
Reusable blocks (
wp_blockpost type) are now named patterns. They can probably already be interacted with usingwp post --post_type=wp_block, but nonetheless could benefit from some more block awareness (e.g. the blocks included in the pattern, block version, etc.)Nowadays widgets can also be blocks. I don't know how well that works with https://github.com/wp-cli/widget-command... Probably not at all? So there might be some room for improvement there as well.
Related to that, just sharing https://github.com/spacedmonkey/wp-rest-blocks here as it might be useful.
Also, what about the site editor,
wp_templateposts, etc.?At the very least, if things like that can be used already with existing commands, we should provide some good examples in the documentation.
Oh, and
wp themeshould indicate whether a theme is a block theme or not. Maybe get info fromtheme.jsontoo?swissspidy commentedon Dec 24, 2025
In WP-CLI v3 we're adding several
wp block *commands (https://github.com/wp-cli/block-command) andwp post block *as well, Closing for now :)