mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 04:40:26 +00:00
Avoid an expensive attachment counting query on the post editing screen. See #27985, for trunk.
git-svn-id: https://develop.svn.wordpress.org/trunk@28191 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -2291,6 +2291,23 @@ function wp_count_attachments( $mime_type = '' ) {
|
||||
return apply_filters( 'wp_count_attachments', (object) $counts, $mime_type );
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if at least one attachment of a particular mime-type has been uploaded
|
||||
*
|
||||
* @global wpdb $wpdb
|
||||
*
|
||||
* @since 3.9.1
|
||||
*
|
||||
* @param string $mime_type The mime-type string to check.
|
||||
*
|
||||
* @return int|null If exist, the post ID of the first found attachment.
|
||||
*/
|
||||
function wp_has_mime_type_attachments( $mime_type ) {
|
||||
global $wpdb;
|
||||
$sql = sprintf( "SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' AND post_mime_type LIKE '%s%%' LIMIT 1", like_escape( $mime_type ) );
|
||||
return $wpdb->get_var( $sql );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default post mime types
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user