Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions includes/class-wpbdp.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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() {
Expand Down
15 changes: 15 additions & 0 deletions tests/wpunit/Listing/ListingMediaAuthorizationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Loading