From 9cffbf989a000c5edf9148f425c7a798a84862eb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 13 Jan 2026 10:10:45 +0000 Subject: [PATCH 1/3] Initial plan From 27fa7407968c38e63a9ba87a7708a08470b49160 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 13 Jan 2026 10:19:44 +0000 Subject: [PATCH 2/3] Add initial revision creation when creating posts Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/post.feature | 23 +++++++++++++++++++++++ src/Post_Command.php | 27 ++++++++++++++++++++------- 2 files changed, 43 insertions(+), 7 deletions(-) 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..c710077a 100644 --- a/src/Post_Command.php +++ b/src/Post_Command.php @@ -208,13 +208,26 @@ public function create( $args, $assoc_args ) { } $assoc_args = wp_slash( $assoc_args ); - parent::_create( - $args, - $assoc_args, - function ( $params ) { - return wp_insert_post( $params, true ); - } - ); + + // Remove ID key if present to ensure we're creating, not updating. + unset( $assoc_args[ $this->obj_id_key ] ); + + // Create the post. + $post_id = wp_insert_post( $assoc_args, true ); + + if ( is_wp_error( $post_id ) ) { + WP_CLI::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 ); + + if ( Utils\get_flag_value( $assoc_args, 'porcelain' ) ) { + WP_CLI::line( (string) $post_id ); + } else { + WP_CLI::success( "Created {$this->obj_type} {$post_id}." ); + } } /** From fb72f064e0a9a72c249ac8ddc6c192984f806230 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 13 Jan 2026 15:12:27 +0000 Subject: [PATCH 3/3] Refactor to use callback approach for revision creation Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Post_Command.php | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/Post_Command.php b/src/Post_Command.php index c710077a..357721bf 100644 --- a/src/Post_Command.php +++ b/src/Post_Command.php @@ -208,26 +208,21 @@ public function create( $args, $assoc_args ) { } $assoc_args = wp_slash( $assoc_args ); + parent::_create( + $args, + $assoc_args, + function ( $params ) { + $post_id = wp_insert_post( $params, true ); - // Remove ID key if present to ensure we're creating, not updating. - unset( $assoc_args[ $this->obj_id_key ] ); - - // Create the post. - $post_id = wp_insert_post( $assoc_args, true ); - - if ( is_wp_error( $post_id ) ) { - WP_CLI::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 ); + 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 ); + } - if ( Utils\get_flag_value( $assoc_args, 'porcelain' ) ) { - WP_CLI::line( (string) $post_id ); - } else { - WP_CLI::success( "Created {$this->obj_type} {$post_id}." ); - } + return $post_id; + } + ); } /**