Skip to content

fix(media): let upload_files users run fetch-wordpress-media - #4008

Merged
chubes4 merged 2 commits into
mainfrom
fix/4005-fetch-media-upload-files
Nov 21, 2026
Merged

chubes4 merged 2 commits into
mainfrom
fix/4005-fetch-media-upload-files

Conversation

@chubes4

@chubes4 chubes4 commented Nov 20, 2026

Copy link
Copy Markdown
Member

Closes #4005

Problem

datamachine/fetch-wordpress-media required PermissionHelper::can_manage(), but upload-media allows anyone with PermissionHelper::can( 'upload_media' ) (core upload_files). Team users (extra_chill_team) could import into the Media Library but got rest_ability_cannot_execute when listing it.

Fix

  • checkPermission() now returns can_manage() || can( 'upload_media' ).
  • For non-operators, execute skips attachments that fail PermissionHelper::can_wp_capability( 'read_post', $attachment_id ). For an inherit attachment, core maps that check to the parent post's status and author. So uploaders can't see media attached to other users' drafts or private posts, which matches what /wp/v2/media shows them. Operators are unchanged.

Tests

New tests/fetch-wordpress-media-permission-smoke.php (php tests/fetch-wordpress-media-permission-smoke.php): 9 checks pass. It fails on the pre-fix code.

  • logged out: denied. Subscriber: denied.
  • upload_files non-manager: allowed. Sees media whose parent is published or is their own private post. Doesn't see media on another user's draft.
  • administrator and manage_flows operator: allowed, see all media.

Related (not changed)

Other fetch abilities still gate on can_manage() alone: QueryWordPressPosts, GetWordPressPost, FetchRss, FetchFiles, FetchWordPressApi. None has a matching non-manager write path the way media has upload-media, so they're left alone.

Note: the item payload still includes the server file_path (needed by the pipeline engine), and /wp/v2/media doesn't expose that.

AI-authored (Extra Chill Bot). Fixed directly outside Homeboy Cook with operator authorization because the Lab runner was capacity-blocked.

fetch-wordpress-media required can_manage() while upload-media allows any
upload_media (core upload_files) holder, so team uploaders hit
rest_ability_cannot_execute when listing media. Allow upload_media and
scope non-operators to attachments they can read_post, matching what core
/wp/v2/media exposes.

Closes #4005
@chubes4
chubes4 merged commit bf1df1e into main Nov 21, 2026
38 checks passed
@chubes4
chubes4 deleted the fix/4005-fetch-media-upload-files branch November 21, 2026 00:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fetch-wordpress-media should be gated on upload_files like upload-media

1 participant