Skip to content

Commit fb72f06

Browse files
Copilotswissspidy
andcommitted
Refactor to use callback approach for revision creation
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 27fa740 commit fb72f06

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

src/Post_Command.php

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -208,26 +208,21 @@ public function create( $args, $assoc_args ) {
208208
}
209209

210210
$assoc_args = wp_slash( $assoc_args );
211+
parent::_create(
212+
$args,
213+
$assoc_args,
214+
function ( $params ) {
215+
$post_id = wp_insert_post( $params, true );
211216

212-
// Remove ID key if present to ensure we're creating, not updating.
213-
unset( $assoc_args[ $this->obj_id_key ] );
214-
215-
// Create the post.
216-
$post_id = wp_insert_post( $assoc_args, true );
217-
218-
if ( is_wp_error( $post_id ) ) {
219-
WP_CLI::error( $post_id );
220-
}
221-
222-
// Create initial revision to match WordPress admin behavior.
223-
// This ensures the original content can be restored if the post is later edited.
224-
wp_save_post_revision( $post_id );
217+
if ( ! is_wp_error( $post_id ) ) {
218+
// Create initial revision to match WordPress admin behavior.
219+
// This ensures the original content can be restored if the post is later edited.
220+
wp_save_post_revision( $post_id );
221+
}
225222

226-
if ( Utils\get_flag_value( $assoc_args, 'porcelain' ) ) {
227-
WP_CLI::line( (string) $post_id );
228-
} else {
229-
WP_CLI::success( "Created {$this->obj_type} {$post_id}." );
230-
}
223+
return $post_id;
224+
}
225+
);
231226
}
232227

233228
/**

0 commit comments

Comments
 (0)