Skip to content

Commit 30b905c

Browse files
authored
Fix PHP warning in bulk edit scenario when post_author is missing (#2230)
1 parent 06e44b8 commit 30b905c

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
Fix PHP warning in bulk edit scenario when post_author is missing from $_REQUEST

includes/scheduler/class-post.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static function schedule_post_activity( $post_id, $post, $update, $post_b
4646
}
4747

4848
// Bail on bulk edits, unless post author or post status changed.
49-
if ( isset( $_REQUEST['bulk_edit'] ) && -1 === (int) $_REQUEST['post_author'] && -1 === (int) $_REQUEST['_status'] ) { // phpcs:ignore WordPress
49+
if ( isset( $_REQUEST['bulk_edit'] ) && ( ! isset( $_REQUEST['post_author'] ) || -1 === (int) $_REQUEST['post_author'] ) && -1 === (int) $_REQUEST['_status'] ) { // phpcs:ignore WordPress
5050
return;
5151
}
5252

tests/includes/scheduler/class-test-post.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,16 @@ public function test_schedule_post_activity_bulk_edit() {
117117
$post_id = self::factory()->post->create( array( 'post_author' => self::$user_id ) );
118118
$activitypub_id = \add_query_arg( 'p', $post_id, \home_url( '/' ) );
119119

120+
// Test bulk edit with missing post_author (should not generate PHP warnings).
121+
$_REQUEST['bulk_edit'] = 1;
122+
$_REQUEST['_status'] = -1;
123+
$_REQUEST['post'] = array( $post_id );
124+
125+
bulk_edit_posts( $_REQUEST ); // phpcs:ignore WordPress.Security.NonceVerification
126+
127+
$outbox_item = $this->get_latest_outbox_item( $activitypub_id );
128+
$this->assertNotSame( 'Update', \get_post_meta( $outbox_item->ID, '_activitypub_activity_type', true ) );
129+
120130
// Test bulk edit that should bail (no author or status change).
121131
$_REQUEST['bulk_edit'] = 1;
122132
$_REQUEST['post_author'] = -1;
@@ -152,7 +162,7 @@ public function test_schedule_post_activity_bulk_edit() {
152162
$this->assertSame( 'Delete', \get_post_meta( $outbox_item->ID, '_activitypub_activity_type', true ) );
153163

154164
// Clean up.
155-
unset( $_REQUEST['bulk_edit'], $_REQUEST['post_author'], $_REQUEST['post_status'] );
165+
unset( $_REQUEST['bulk_edit'], $_REQUEST['post_author'], $_REQUEST['_status'], $_REQUEST['post'] );
156166
\wp_delete_post( $post_id, true );
157167
}
158168

0 commit comments

Comments
 (0)