Skip to content

Fix Subscriber listing owners unable to delete their listing images - #583

Merged
sorinmarta merged 4 commits into
masterfrom
fix/issue-395-subscriber-delete-image
Nov 17, 2026
Merged

sorinmarta merged 4 commits into
masterfrom
fix/issue-395-subscriber-delete-image

Conversation

@vivi-the-going-merry

@vivi-the-going-merry vivi-the-going-merry Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Fixes Strategy11/business-directory-premium#395

What was broken

A Subscriber who owns a listing could not delete its images on the front-end edit page. can_delete_listing_image() required delete_post on the image, and Subscribers don't have delete_posts. The AJAX call returned success:false and nothing happened.

What changed

A logged-in user can now delete a listing image if they have delete_post on it or they are the image's author (they uploaded it). Guests and the other checks are unchanged.

The issue suggests dropping the delete_post check and relying on belongs_to_listing(). I didn't, because belongs_to_listing() is also true for a foreign image that was re-parented to the listing. testReparentedForeignImageCannotBeDeletedAfterUpgrade (the #538 security fix) covers that case and still passes.

Known limit: an image uploaded by someone else (for example an admin on the owner's behalf) still can't be deleted by a Subscriber owner.

Verified

🤖 Generated with Claude Code

vivi-the-going-merry Bot and others added 2 commits November 17, 2026 10:26
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@vivi-the-going-merry vivi-the-going-merry Bot added the run analysis Runs phpcs and phpunit label Nov 17, 2026
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@vivi-the-going-merry vivi-the-going-merry Bot changed the title Fix subscriber listing owners unable to delete listing images Fix Subscriber listing owners unable to delete their listing images Nov 17, 2026
@vivi-the-going-merry
vivi-the-going-merry Bot marked this pull request as ready for review November 17, 2026 17:31
@franky-the-going-merry franky-the-going-merry Bot added the franky-working Franky is actively reviewing this label Nov 17, 2026

@franky-the-going-merry franky-the-going-merry Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve. Nothing blocking, no notes.

What I checked

  • The change is one expression in can_delete_listing_image(): a logged-in user passes with delete_post on the image OR when post_author of the attachment is their own ID. The belongs_to_listing() check above it is untouched, and the AJAX handler still requires the nonce, can_edit_listing_images() and the listing-parent match first. A guest never reaches the new clause (not logged in returns earlier), and get_current_user_id() is always above 0 there, so an author of 0 cannot match.
  • Your reasoning for not dropping delete_post holds: the re-parented foreign image case from #538 is still denied, because that image's author is not the caller.

Live before/after (BD Playground env, throwaway mu-plugin that creates a Subscriber owner, a listing they own, one image they uploaded and one an admin uploaded, then calls the real private can_delete_listing_image() by reflection and the real ajax_listing_submit_image_delete() handler with a valid nonce):

Case master PR
Subscriber owner, own upload false true
Subscriber owner, admin's upload false false (the known limit you documented)
Another Subscriber, owner's upload false false
Real AJAX handler, owner, own upload {"success":false,"error":"Unknown error"} {"success":true,"data":{"imageId":8}}

CI: both Codeception jobs, PHPStan and PHPCS are green at this head. The new testSubscriberOwnerCanDeleteOwnListingImage is covered by those CI runs (I did not run PHPUnit separately).

Not run: a browser click-through of the front-end edit page (the handler and permission check were exercised directly, as above), and the review skills (a one-expression diff plus one test).

@franky-the-going-merry franky-the-going-merry Bot removed franky-review franky-working Franky is actively reviewing this labels Nov 17, 2026
@sorinmarta
sorinmarta merged commit bf6328b into master Nov 17, 2026
5 checks passed
@sorinmarta
sorinmarta deleted the fix/issue-395-subscriber-delete-image branch November 17, 2026 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run analysis Runs phpcs and phpunit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant