From dd68c64a6985901aab6b12facd78908e6e9bf2ec Mon Sep 17 00:00:00 2001
From: Max Lyuchin <maxim.lyuchin@gmail.com>
Date: Wed, 15 Mar 2023 15:40:52 +0300
Subject: [PATCH 1/3] Force publish scheduled post in bulk edit
---
src/wp-admin/includes/post.php | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/wp-admin/includes/post.php b/src/wp-admin/includes/post.php
index 824b96945075..1a0473c46dd2 100644
a
|
b
|
function bulk_edit_posts( $post_data = null ) { |
664 | 664 | // Prevent wp_insert_post() from overwriting post format with the old data. |
665 | 665 | unset( $post_data['tax_input']['post_format'] ); |
666 | 666 | |
| 667 | // Reset post date of scheduled post to be published. |
| 668 | if ( 'future' === $post->post_status && 'publish' === $post_data['post_status'] ) { |
| 669 | $post_data['post_date'] = current_time( 'mysql' ); |
| 670 | $post_data['post_date_gmt'] = ''; |
| 671 | } |
| 672 | |
667 | 673 | $post_id = wp_update_post( $post_data ); |
668 | 674 | update_post_meta( $post_id, '_edit_last', get_current_user_id() ); |
669 | 675 | $updated[] = $post_id; |
From 558e6e49a6dbc2703d4ebbdc4ae9f0c3cc4d4d6a Mon Sep 17 00:00:00 2001
From: Max Lyuchin <maxim.lyuchin@gmail.com>
Date: Wed, 15 Mar 2023 15:41:02 +0300
Subject: [PATCH 2/3] Unit tests
---
tests/phpunit/tests/admin/includesPost.php | 31 ++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/tests/phpunit/tests/admin/includesPost.php b/tests/phpunit/tests/admin/includesPost.php
index 799d927dfa90..9a94d1e3d5f0 100644
a
|
b
|
public function test_bulk_edit_posts_should_preserve_post_format_when_unchanged( |
293 | 293 | $this->assertFalse( get_post_format( $post_ids[2] ) ); |
294 | 294 | } |
295 | 295 | |
| 296 | /** |
| 297 | * @ticket 31635 |
| 298 | */ |
| 299 | public function test_bulk_edit_posts_should_publish_scheduled_post() { |
| 300 | wp_set_current_user( self::$admin_id ); |
| 301 | |
| 302 | $post = self::factory()->post->create( |
| 303 | array( |
| 304 | 'post_author' => self::$author_ids[0], |
| 305 | 'comment_status' => 'closed', |
| 306 | 'ping_status' => 'closed', |
| 307 | 'post_status' => 'future', |
| 308 | 'post_date' => gmdate( 'Y-m-d H:i:s', strtotime( '+1 month' ) ), |
| 309 | ) |
| 310 | ); |
| 311 | |
| 312 | $request = array( |
| 313 | 'post_type' => 'post', |
| 314 | 'post_author' => -1, |
| 315 | 'ping_status' => -1, |
| 316 | 'comment_status' => -1, |
| 317 | '_status' => 'publish', |
| 318 | 'post' => array( $post ), |
| 319 | ); |
| 320 | |
| 321 | bulk_edit_posts( $request ); |
| 322 | |
| 323 | $this->assertSame( 'publish', get_post_status( $post ) ); |
| 324 | $this->assertLessThanOrEqual( gmdate( 'Y-m-d H:i:s' ), get_post_time( 'Y-m-d H:i:s', false, $post ) ); |
| 325 | } |
| 326 | |
296 | 327 | /** |
297 | 328 | * @ticket 41396 |
298 | 329 | */ |
From 4a520a124e8eac4149475d27c9e7c095f7b63042 Mon Sep 17 00:00:00 2001
From: Max Lyuchin <maxim.lyuchin@gmail.com>
Date: Wed, 15 Mar 2023 15:47:18 +0300
Subject: [PATCH 3/3] code styles
---
src/wp-admin/includes/post.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/wp-admin/includes/post.php b/src/wp-admin/includes/post.php
index 1a0473c46dd2..0c9f9250ed9f 100644
a
|
b
|
function bulk_edit_posts( $post_data = null ) { |
669 | 669 | $post_data['post_date'] = current_time( 'mysql' ); |
670 | 670 | $post_data['post_date_gmt'] = ''; |
671 | 671 | } |
672 | | |
| 672 | |
673 | 673 | $post_id = wp_update_post( $post_data ); |
674 | 674 | update_post_meta( $post_id, '_edit_last', get_current_user_id() ); |
675 | 675 | $updated[] = $post_id; |