diff --git a/wp-includes/media.php b/wp-includes/media.php index b65529e2e3..14ce8a6cfb 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -2656,7 +2656,7 @@ function wp_enqueue_media( $args = array() ) { if ( did_action( 'wp_enqueue_media' ) ) return; - global $content_width; + global $content_width, $wpdb; $defaults = array( 'post' => null, @@ -2695,6 +2695,21 @@ function wp_enqueue_media( $args = array() ) { } } + $has_audio = $wpdb->get_var( " + SELECT ID + FROM $wpdb->posts + WHERE post_type = 'attachment' + AND post_mime_type LIKE 'audio%' + LIMIT 1 + " ); + $has_video = $wpdb->get_var( " + SELECT ID + FROM $wpdb->posts + WHERE post_type = 'attachment' + AND post_mime_type LIKE 'video%' + LIMIT 1 + " ); + $settings = array( 'tabs' => $tabs, 'tabUrl' => add_query_arg( array( 'chromeless' => true ), admin_url('media-upload.php') ), @@ -2709,8 +2724,8 @@ function wp_enqueue_media( $args = array() ) { ), 'defaultProps' => $props, 'attachmentCounts' => array( - 'audio' => wp_has_mime_type_attachments( 'audio' ) ? 1 : 0, - 'video' => wp_has_mime_type_attachments( 'video' ) ? 1 : 0 + 'audio' => ( $has_audio ) ? 1 : 0, + 'video' => ( $has_video ) ? 1 : 0 ), 'embedExts' => $exts, 'embedMimes' => $ext_mimes, diff --git a/wp-includes/post.php b/wp-includes/post.php index 8da9437251..d537148d29 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -2291,23 +2291,6 @@ 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 *