WordPress.org

Make WordPress Core

Opened 5 years ago

Last modified 5 months ago

#28381 new enhancement

Filter for unattached attachments count

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

Description

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 5 years ago.

Download all attachments as: .zip

Change History (5)

#1 @SergeyBiryukov
5 years ago

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

#2 @ericlewis
5 years ago

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

Can you provide a use case for this?

#3 @khromov
5 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):

https://gist.github.com/khromov/29411bb7ca3fdd2c3890

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.
https://dl.dropboxusercontent.com/u/2758854/this-one-.png

#4 @wonderboymusic
5 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.