Skip to content

Commit 3dc0674

Browse files
committed
Post Generate: Add support for post_date_gmt
Set the GMT date of the generated posts. Default: value of post_date (or current date if it's not set)
1 parent 943fd52 commit 3dc0674

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/Post_Command.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,9 @@ public function list_( $_, $assoc_args ) {
634634
* [--post_date=<yyyy-mm-dd-hh-ii-ss>]
635635
* : The date of the generated posts. Default: current date
636636
*
637+
* [--post_date_gmt=<yyyy-mm-dd-hh-ii-ss>]
638+
* : The GMT date of the generated posts. Default: value of post_date (or current date if it's not set)
639+
*
637640
* [--post_content]
638641
* : If set, the command reads the post_content from STDIN.
639642
*
@@ -681,11 +684,16 @@ public function generate( $args, $assoc_args ) {
681684
'post_status' => 'publish',
682685
'post_author' => false,
683686
'post_date' => current_time( 'mysql' ),
687+
'post_date_gmt' => false,
684688
'post_content' => '',
685689
'post_title' => '',
686690
);
687691
extract( array_merge( $defaults, $assoc_args ), EXTR_SKIP );
688692

693+
if ( $post_date_gmt === false ) {
694+
$post_date_gmt = $post_date;
695+
}
696+
689697
// @codingStandardsIgnoreStart
690698
if ( !post_type_exists( $post_type ) ) {
691699
WP_CLI::error( sprintf( "'%s' is not a registered post type.", $post_type ) );
@@ -745,6 +753,7 @@ public function generate( $args, $assoc_args ) {
745753
'post_parent' => $current_parent,
746754
'post_name' => ! empty( $post_title ) ? sanitize_title( $post_title . ( $i === $total ) ? '' : '-$i' ) : "post-$i",
747755
'post_date' => $post_date,
756+
'post_date_gmt' => $post_date_gmt,
748757
'post_content' => $post_content,
749758
);
750759

0 commit comments

Comments
 (0)