Skip to content
This repository was archived by the owner on Dec 27, 2022. It is now read-only.

Commit 13f8edf

Browse files
committed
Allow author and date_gmt to be supplied in Post_Type::save()
1 parent 4b3cb85 commit 13f8edf

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

php/class-post-type.php

+6
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,12 @@ public function save( array $args ) {
531531
}
532532
$post_arr['post_status'] = $args['status'];
533533
}
534+
if ( ! empty( $args['author'] ) ) {
535+
$post_arr['post_author'] = $args['author'];
536+
}
537+
if ( ! empty( $args['date_gmt'] ) ) {
538+
$post_arr['post_date_gmt'] = $args['date_gmt'];
539+
}
534540

535541
$this->suspend_kses();
536542
if ( $is_update ) {

tests/php/test-class-post-type.php

+19
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,25 @@ public function test_save() {
489489

490490
$this->assertEquals( get_stylesheet(), get_post_meta( $r, '_snapshot_theme', true ) );
491491
$this->assertEquals( $this->plugin->version, get_post_meta( $r, '_snapshot_version', true ) );
492+
493+
// Success with author supplied.
494+
$user_id = $this->factory()->user->create( array( 'role' => 'administrator' ) );
495+
$post_id = $post_type->save( array(
496+
'uuid' => self::UUID,
497+
'data' => $data,
498+
'status' => 'publish',
499+
'author' => $user_id,
500+
) );
501+
$this->assertEquals( $user_id, get_post( $post_id )->post_author );
502+
503+
// Success with future date.
504+
$post_id = $post_type->save( array(
505+
'uuid' => self::UUID,
506+
'data' => $data,
507+
'status' => 'publish',
508+
'date_gmt' => gmdate( 'Y-m-d H:i:s', time() + 24 * 3600 ),
509+
) );
510+
$this->assertEquals( 'future', get_post_status( $post_id ) );
492511
}
493512

494513
/**

0 commit comments

Comments
 (0)