diff --git a/includes/class-wpbdp.php b/includes/class-wpbdp.php index 2ec26965d..306f237a2 100644 --- a/includes/class-wpbdp.php +++ b/includes/class-wpbdp.php @@ -696,8 +696,9 @@ private function can_edit_listing_images( $listing_id ) { /** * Whether the current request may permanently remove a listing image. * - * Authenticated users need attachment-level delete rights. Guests already - * proved listing access via submit token or access key. + * Authenticated users need attachment-level delete rights or must have + * uploaded the image themselves (Subscribers lack `delete_posts`). + * Guests already proved listing access via submit token or access key. * * @since 6.4.28 * @@ -715,7 +716,7 @@ private function can_delete_listing_image( $image_id, $listing_id ) { return true; } - return current_user_can( 'delete_post', $image_id ); + return current_user_can( 'delete_post', $image_id ) || (int) get_post_field( 'post_author', $image_id ) === get_current_user_id(); } public function ajax_listing_media_image() { diff --git a/tests/wpunit/Listing/ListingMediaAuthorizationTest.php b/tests/wpunit/Listing/ListingMediaAuthorizationTest.php index 4414a3fef..37e211607 100644 --- a/tests/wpunit/Listing/ListingMediaAuthorizationTest.php +++ b/tests/wpunit/Listing/ListingMediaAuthorizationTest.php @@ -106,6 +106,21 @@ public function testReparentedForeignImageCannotBeDeletedAfterUpgrade() { $this->assertSame( $listing_id, (int) wp_get_post_parent_id( $image_id ) ); } + /** + * @since x.x + */ + public function testSubscriberOwnerCanDeleteOwnListingImage() { + $subscriber_id = $this->get_or_create_user( 'subscriber', 'media-subscriber@example.com' ); + $listing_id = $this->create_listing( $subscriber_id ); + $image_id = $this->create_image_attachment( $subscriber_id, $listing_id ); + + wp_set_current_user( $subscriber_id ); + $response = $this->dispatch_image_delete( $listing_id, $image_id ); + + $this->assertTrue( $response['success'] ); + $this->assertNull( get_post( $image_id ) ); + } + /** * @since 6.4.28 */