Quick/Bulk Edit: Ensure scheduled posts are published when using Bulk Edit.

This changeset ensures scheduled posts are actually published when changing their status to "Published" using bulk edit. Also adds related unit tests.

Props siobhan, Clorith, webcommsat, cadic, oglekler, audrasjb, pavanpatil1.
Fixes #31635.




git-svn-id: https://develop.svn.wordpress.org/trunk@56123 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jb Audras
2023-07-02 08:02:45 +00:00
parent 7f0eb0780f
commit e635540d1c
2 changed files with 75 additions and 0 deletions
+9
View File
@@ -668,6 +668,15 @@ function bulk_edit_posts( $post_data = null ) {
// Prevent wp_insert_post() from overwriting post format with the old data.
unset( $post_data['tax_input']['post_format'] );
// Reset post date of scheduled post to be published.
if (
in_array( $post->post_status, array( 'future', 'draft' ), true ) &&
'publish' === $post_data['post_status']
) {
$post_data['post_date'] = current_time( 'mysql' );
$post_data['post_date_gmt'] = '';
}
$post_id = wp_update_post( $post_data );
update_post_meta( $post_id, '_edit_last', get_current_user_id() );
$updated[] = $post_id;
@@ -293,6 +293,72 @@ class Tests_Admin_IncludesPost extends WP_UnitTestCase {
$this->assertFalse( get_post_format( $post_ids[2] ) );
}
/**
* @ticket 31635
*/
public function test_bulk_edit_posts_should_publish_scheduled_post() {
wp_set_current_user( self::$admin_id );
$post = self::factory()->post->create(
array(
'post_author' => self::$author_ids[0],
'comment_status' => 'closed',
'ping_status' => 'closed',
'post_status' => 'future',
'post_date' => gmdate( 'Y-m-d H:i:s', strtotime( '+1 month' ) ),
)
);
$request = array(
'post_type' => 'post',
'post_author' => -1,
'ping_status' => -1,
'comment_status' => -1,
'_status' => 'publish',
'post' => array( $post ),
);
bulk_edit_posts( $request );
$this->assertSame( 'publish', get_post_status( $post ) );
$this->assertLessThanOrEqual( gmdate( 'Y-m-d H:i:s' ), get_post_time( 'Y-m-d H:i:s', false, $post ) );
}
/**
* @ticket 31635
*/
public function test_bulk_edit_posts_should_publish_draft_immediately() {
wp_set_current_user( self::$admin_id );
// Create draft last edited a month ago
$post = self::factory()->post->create(
array(
'post_author' => self::$author_ids[0],
'comment_status' => 'closed',
'ping_status' => 'closed',
'post_status' => 'draft',
'post_date' => gmdate( 'Y-m-d H:i:s', strtotime( '-1 month' ) ),
)
);
$request = array(
'post_type' => 'post',
'post_author' => -1,
'ping_status' => -1,
'comment_status' => -1,
'_status' => 'publish',
'post' => array( $post ),
);
bulk_edit_posts( $request );
$this->assertSame( 'publish', get_post_status( $post ) );
// Expect to be published within the last minute (to consider slow testing environment).
$minute_before = gmdate( 'Y-m-d H:i:s', strtotime( '-1 minute' ) );
$this->assertGreaterThanOrEqual( $minute_before, get_post_time( 'Y-m-d H:i:s', false, $post ) );
$this->assertLessThanOrEqual( gmdate( 'Y-m-d H:i:s' ), get_post_time( 'Y-m-d H:i:s', false, $post ) );
}
/**
* @ticket 41396
*/