From 8fa6e99edc8f6f1d3d538ca391ab9c94d2cb156e Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Mon, 23 Sep 2013 19:11:09 +0000 Subject: [PATCH] Introduce a wp_count_attachments filter. props kevinB. fixes #17071. Built from https://develop.svn.wordpress.org/trunk@25579 git-svn-id: http://core.svn.wordpress.org/trunk@25496 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index 4130ffaf1e..cf809e592a 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -2151,13 +2151,21 @@ function wp_count_attachments( $mime_type = '' ) { $and = wp_post_mime_type_where( $mime_type ); $count = $wpdb->get_results( "SELECT post_mime_type, COUNT( * ) AS num_posts FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' $and GROUP BY post_mime_type", ARRAY_A ); - $stats = array(); + $counts = array(); foreach( (array) $count as $row ) { - $stats[$row['post_mime_type']] = $row['num_posts']; + $counts[ $row['post_mime_type'] ] = $row['num_posts']; } - $stats['trash'] = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status = 'trash' $and"); + $counts['trash'] = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status = 'trash' $and"); - return (object) $stats; + /** + * Modify returned attachment counts by mime type. + * + * @since 3.7.0 + * + * @param object $counts An object containing the attachment counts by mime type. + * @param string $mime_type The mime type pattern used to filter the attachments counted. + */ + return apply_filters( 'wp_count_attachments', (object) $stats, $mime_type ); } /**