Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions features/post.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
10 changes: 9 additions & 1 deletion src/Post_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
);
}
Expand Down