Skip to content

Fix media library grid pagination for non-admin users#1679

Open
dd32 wants to merge 6 commits into
WordPress:productionfrom
dd32:fix/claude/1316-media-library-pagination
Open

Fix media library grid pagination for non-admin users#1679
dd32 wants to merge 6 commits into
WordPress:productionfrom
dd32:fix/claude/1316-media-library-pagination

Conversation

@dd32

@dd32 dd32 commented Mar 24, 2026

Copy link
Copy Markdown
Member

Summary

  • Fixes media library "load more" button not working for non-admin users
  • Root cause: the the_posts filter in privacy.php removed payment file attachments AFTER the query, causing fewer results than posts_per_page. The JavaScript then concluded there were no more items to load.
  • Solution: moves the filtering from the_posts to posts_clauses, so the exclusion happens at the SQL level and found_posts matches the actual results
  • Non-admins still cannot see payment files uploaded by other users (security preserved)

Fixes #1316

Test plan

  • Log in as an Editor (non-admin) user
  • Go to Media Library in grid view
  • Scroll down and verify the "Load more" button works
  • Verify payment files from other users are still hidden
  • Log in as an admin and verify all files are visible

🤖 Generated with Claude Code

The previous the_posts filter removed payment attachments from query
results after the query ran, which caused the media library grid to
stop loading more items for non-admin users. The JavaScript checks if
the returned batch size is less than posts_per_page to determine if
there are more items, so removing items post-query broke pagination.

Switch to posts_clauses to exclude other users payment attachments
at the SQL level, keeping found_posts and results consistent.

Fixes WordPress#1316

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace the two IN (SELECT ...) subqueries with a single LEFT JOIN on
the parent post, making the SQL more readable and efficient.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dd32 dd32 force-pushed the fix/claude/1316-media-library-pagination branch from 9234f40 to 8b6fb99 Compare March 25, 2026 05:44
dd32 and others added 4 commits March 25, 2026 15:50
Tests that admins see all attachments, editors see their own payment
attachments, editors see attachments on their own payment posts, and
unrelated editors cannot see other users payment attachments. Also
verifies found_posts matches actual results (the original bug).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
In multisite, manage_options requires super admin status rather than
just the administrator role with add_cap.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Component] Payments Payment tools, budgets, invoices [Type] Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Non admin users can't view more than the first page in media library grid

1 participant