Make WordPress Core

Opened 10 years ago

Last modified 5 years ago

#28381 new enhancement

Filter for unattached attachments count

Reported by: khromov's profile khromov Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.0
Component: Media Keywords: has-patch needs-refresh
Focuses: Cc:


There is a filter available for modifying attachment counts (wp_count_attachments) but no filter for modifying unattached attachments count. Therefore I am suggesting this be added via a new filter, wp_count_unattached_attachments, see attached patch.

The attached patch is against trunk.

Attachments (1)

unattached_attachments_patch.patch (1.6 KB) - added by khromov 10 years ago.

Download all attachments as: .zip

Change History (5)

#1 @SergeyBiryukov
10 years ago

  • Component changed from General to Media
  • Keywords has-patch added

#2 @ericlewis
10 years ago

Hey @khromov, thanks for the bug report and patch!

Can you provide a use case for this?

#3 @khromov
10 years ago

Hey Eric,

I'm making a plugin that will allow non-admins to see their own Media items only.

Here is a working copy of the plugin, (assuming the hook is added as per my patch):

The "problem" is the inconsistency that you can filter media attachment counts, but not the unattached media attachment count.

Here's a photo for clarification. The count in the red box cannot be filtered.

#4 @wonderboymusic
9 years ago

  • Keywords needs-refresh added
  • Milestone changed from Awaiting Review to Future Release

I would suggest that the filter occur before the database query and pass null. That way, if you get a non-null value, you can return immediately without hitting the database.

Note: See TracTickets for help on using tickets.