Ticket #55227: 55227.diff
File 55227.diff, 2.1 KB (added by , 3 years ago) |
---|
-
src/wp-includes/post.php
3083 3083 } 3084 3084 3085 3085 /** 3086 * Return the cache key for wp_count_attachments() based on the passed mime type. 3087 * 3088 * @since 6.0.0 3089 * @access private 3090 * 3091 * @param string|string[] $mime_type Optional. Array or comma-separated list of 3092 * MIME patterns. Default empty. 3093 * @return string The cache key. 3094 */ 3095 function _count_attachments_cache_key( $mime_type = '' ) { 3096 $cache_key = sprintf( 3097 'attachments%s', 3098 ! empty( $mime_type ) ? ':' . str_replace( '/', '_', implode( '-', (array) $mime_type ) ) : '' 3099 ); 3100 3101 return $cache_key; 3102 } 3103 3104 /** 3086 3105 * Count number of attachments for the mime type(s). 3087 3106 * 3088 3107 * If you set the optional mime_type parameter, then an array will still be … … 3101 3120 function wp_count_attachments( $mime_type = '' ) { 3102 3121 global $wpdb; 3103 3122 3123 $cache_key = _count_attachments_cache_key( $mime_type ); 3124 3125 $counts = wp_cache_get( $cache_key, 'counts' ); 3126 if ( false !== $counts ) { 3127 /** This filter is documented in wp-includes/post.php */ 3128 return apply_filters( 'wp_count_attachments', $counts, $mime_type ); 3129 } 3130 3104 3131 $and = wp_post_mime_type_where( $mime_type ); 3105 3132 $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 ); 3106 3133 … … 3110 3137 } 3111 3138 $counts['trash'] = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status = 'trash' $and" ); 3112 3139 3140 $counts = (object) $counts; 3141 wp_cache_set( $cache_key, $counts, 'counts' ); 3142 3113 3143 /** 3114 3144 * Modify returned attachment counts by mime type. 3115 3145 * … … 3119 3149 * mime type. 3120 3150 * @param string|string[] $mime_type Array or comma-separated list of MIME patterns. 3121 3151 */ 3122 return apply_filters( 'wp_count_attachments', (object)$counts, $mime_type );3152 return apply_filters( 'wp_count_attachments', $counts, $mime_type ); 3123 3153 } 3124 3154 3125 3155 /**