wp-cli / entity-command

Manage WordPress comments, menus, options, posts, sites, terms, and users.
MIT License
100 stars 90 forks source link

Cannot add block content via the `--post_content` flag #490

Closed helgatheviking closed 6 months ago

helgatheviking commented 7 months ago

Bug Report

Describe the current, buggy behavior

Cannot add block content via the --post_content flag.

Describe how other contributors can replicate this bug

Try to create a post with block content

wp post create --post_title="Pizza Day" --post_status=publish --post_content="<!-- wp:paragraph --><p>PIZZA FRIDAY</p><!-- /wp:paragraph -->"

See error that the event is not found.

bash: !-: event not found

However

wp post create --post_title="Pizza Day" --post_status=publish --post_content="PIZZA FRIDAY"

inserts a post, though with "classic editor" content that then needs to be converted to blocks.

Hopefully this is just bad formatting on my part? In which case, we can switch this to a documentation request?

Describe what you would expect as the correct outcome

post inserted with block content ready for use in the block editor

Let us know what environment you are running this on

OS: Linux 5.4.0-163-generic #180-Ubuntu SMP Tue Sep 5 13:21:23 UTC 2023 x86_64
Shell:  /bin/bash
PHP binary: /usr/bin/php8.0
PHP version:    8.0.30
php.ini used:   /etc/php/8.0/cli/php.ini
MySQL binary:   /usr/bin/mysql
MySQL version:  mysql  Ver 15.1 Distrib 10.5.23-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
SQL modes:  
WP-CLI root dir:    phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:  phar://wp-cli.phar/vendor
WP_CLI phar path:   /var/www/subdomain.mywebsite.com
WP-CLI packages dir:    /home/leftback/.wp-cli/packages/
WP-CLI cache dir:   /home/leftback/.wp-cli/cache
WP-CLI global config:   
WP-CLI project config:  
WP-CLI version: 2.7.1
ernilambar commented 7 months ago

This seems to be the issue with shell rather than WP CLI. Even echo "<!-- wp:paragraph --><p>PIZZA FRIDAY</p><!-- /wp:paragraph -->" gives that error. ! character is expected to be escaped. When you escape such character in the command, it works as expected.

wp post create --post_title="Pizza Day" --post_status=publish --post_content="<\!-- wp:paragraph --><p>PIZZA FRIDAY</p><\!-- /wp:paragraph -->"
helgatheviking commented 6 months ago

I just tested your command in the CLI and it runs without error, however the content created is still not a block but the classic content. The escaped comment is still considered a string.

image

Found [this issue] which suggests importing escaped content via HTML file. don't know if I'll be able to do that in the blueprint.json, but I will try to test.

ernilambar commented 6 months ago

Above command is working fine for me. I am using WP-CLI 2.10.0. Screenshot 2024-04-02 at 11 41 42 AM

danielbachhuber commented 6 months ago

Let's continue the conversation in https://github.com/wp-cli/wp-cli/issues/5923#issuecomment-2040069624