Make WordPress Core

Changeset 25579


Ignore:
Timestamp:
09/23/2013 07:10:53 PM (11 years ago)
Author:
nacin
Message:

Introduce a wp_count_attachments filter.

props kevinB.
fixes #17071.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r25578 r25579  
    21522152    $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 );
    21532153
    2154     $stats = array();
     2154    $counts = array();
    21552155    foreach( (array) $count as $row ) {
    2156         $stats[$row['post_mime_type']] = $row['num_posts'];
    2157     }
    2158     $stats['trash'] = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status = 'trash' $and");
    2159 
    2160     return (object) $stats;
     2156        $counts[ $row['post_mime_type'] ] = $row['num_posts'];
     2157    }
     2158    $counts['trash'] = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status = 'trash' $and");
     2159
     2160    /**
     2161     * Modify returned attachment counts by mime type.
     2162     *
     2163     * @since 3.7.0
     2164     *
     2165     * @param object $counts    An object containing the attachment counts by mime type.
     2166     * @param string $mime_type The mime type pattern used to filter the attachments counted.
     2167     */
     2168    return apply_filters( 'wp_count_attachments', (object) $stats, $mime_type );
    21612169}
    21622170
Note: See TracChangeset for help on using the changeset viewer.