File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed
Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -509,3 +509,39 @@ Feature: Manage WordPress posts
509509 """
510510 2005-01-24T09:52:00.000Z
511511 """
512+
513+ @require-wp-5.0
514+ Scenario : Get block_version field for post with blocks
515+ When I run `wp post create --post_title='Block Post' --post_content='<!-- wp:paragraph --><p>Hello block world</p><!-- /wp:paragraph -->' --porcelain`
516+ Then STDOUT should be a number
517+ And save STDOUT as {POST_ID}
518+
519+ When I run `wp post get {POST_ID} --field=block_version`
520+ Then STDOUT should be:
521+ """
522+ 1
523+ """
524+
525+ @require-wp-5.0
526+ Scenario : Get block_version field for post without blocks
527+ When I run `wp post create --post_title='Classic Post' --post_content='<p>Just plain HTML</p>' --porcelain`
528+ Then STDOUT should be a number
529+ And save STDOUT as {POST_ID}
530+
531+ When I run `wp post get {POST_ID} --field=block_version`
532+ Then STDOUT should be:
533+ """
534+ 0
535+ """
536+
537+ @require-wp-5.0
538+ Scenario : Get block_version field included in default output
539+ When I run `wp post create --post_title='Test Post' --post_content='<!-- wp:heading --><h2>Title</h2><!-- /wp:heading -->' --porcelain`
540+ Then STDOUT should be a number
541+ And save STDOUT as {POST_ID}
542+
543+ When I run `wp post get {POST_ID} --format=json`
544+ Then STDOUT should be JSON containing:
545+ """
546+ {"block_version":1}
547+ """
Original file line number Diff line number Diff line change @@ -423,6 +423,11 @@ protected function _edit( $content, $title ) {
423423 *
424424 * # Save the post content to a file
425425 * $ wp post get 123 --field=content > file.txt
426+ *
427+ * # Get the block version of a post (1 = has blocks, 0 = no blocks)
428+ * # Requires WordPress 5.0+.
429+ * $ wp post get 123 --field=block_version
430+ * 1
426431 */
427432 public function get ( $ args , $ assoc_args ) {
428433 $ post = $ this ->fetcher ->get_check ( $ args [0 ] );
@@ -434,6 +439,10 @@ public function get( $args, $assoc_args ) {
434439 $ post_arr ['url ' ] = get_permalink ( $ post ->ID );
435440 }
436441
442+ if ( function_exists ( 'block_version ' ) ) {
443+ $ post_arr ['block_version ' ] = block_version ( $ post ->post_content );
444+ }
445+
437446 if ( empty ( $ assoc_args ['fields ' ] ) ) {
438447 $ assoc_args ['fields ' ] = array_keys ( $ post_arr );
439448 }
You can’t perform that action at this time.
0 commit comments