diff --git a/features/post.feature b/features/post.feature index 0f8a08b0..66332aea 100644 --- a/features/post.feature +++ b/features/post.feature @@ -545,3 +545,26 @@ Feature: Manage WordPress posts """ {"block_version":1} """ + + Scenario: Creating a post should create an initial revision + When I run `wp post create --post_title='Original Title' --post_content='Original content' --post_status=publish --porcelain` + Then STDOUT should be a number + And save STDOUT as {POST_ID} + + When I run `wp post list --post_type=revision --post_parent={POST_ID} --format=count` + Then STDOUT should be: + """ + 1 + """ + + When I run `wp post update {POST_ID} --post_title='Updated Title'` + Then STDOUT should contain: + """ + Success: Updated post {POST_ID}. + """ + + When I run `wp post list --post_type=revision --post_parent={POST_ID} --format=count` + Then STDOUT should be: + """ + 2 + """ diff --git a/src/Post_Command.php b/src/Post_Command.php index 0572718a..357721bf 100644 --- a/src/Post_Command.php +++ b/src/Post_Command.php @@ -212,7 +212,15 @@ public function create( $args, $assoc_args ) { $args, $assoc_args, function ( $params ) { - return wp_insert_post( $params, true ); + $post_id = wp_insert_post( $params, true ); + + if ( ! is_wp_error( $post_id ) ) { + // Create initial revision to match WordPress admin behavior. + // This ensures the original content can be restored if the post is later edited. + wp_save_post_revision( $post_id ); + } + + return $post_id; } ); }