Avoid an expensive attachment counting query on the post editing screen.
Merges [28191], [28194] to the 3.9 branch. props johnbillion. fixes #27985. Built from https://develop.svn.wordpress.org/branches/3.9@28261 git-svn-id: http://core.svn.wordpress.org/branches/3.9@28089 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
524068c83b
commit
f2512c50eb
|
@ -2654,7 +2654,7 @@ function wp_enqueue_media( $args = array() ) {
|
||||||
if ( did_action( 'wp_enqueue_media' ) )
|
if ( did_action( 'wp_enqueue_media' ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
global $content_width;
|
global $content_width, $wpdb;
|
||||||
|
|
||||||
$defaults = array(
|
$defaults = array(
|
||||||
'post' => null,
|
'post' => null,
|
||||||
|
@ -2693,15 +2693,20 @@ function wp_enqueue_media( $args = array() ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$audio = $video = 0;
|
$has_audio = $wpdb->get_var( "
|
||||||
$counts = (array) wp_count_attachments();
|
SELECT ID
|
||||||
foreach ( $counts as $mime => $total ) {
|
FROM $wpdb->posts
|
||||||
if ( 0 === strpos( $mime, 'audio/' ) ) {
|
WHERE post_type = 'attachment'
|
||||||
$audio += (int) $total;
|
AND post_mime_type LIKE 'audio%'
|
||||||
} elseif ( 0 === strpos( $mime, 'video/' ) ) {
|
LIMIT 1
|
||||||
$video += (int) $total;
|
" );
|
||||||
}
|
$has_video = $wpdb->get_var( "
|
||||||
}
|
SELECT ID
|
||||||
|
FROM $wpdb->posts
|
||||||
|
WHERE post_type = 'attachment'
|
||||||
|
AND post_mime_type LIKE 'video%'
|
||||||
|
LIMIT 1
|
||||||
|
" );
|
||||||
|
|
||||||
$settings = array(
|
$settings = array(
|
||||||
'tabs' => $tabs,
|
'tabs' => $tabs,
|
||||||
|
@ -2717,8 +2722,8 @@ function wp_enqueue_media( $args = array() ) {
|
||||||
),
|
),
|
||||||
'defaultProps' => $props,
|
'defaultProps' => $props,
|
||||||
'attachmentCounts' => array(
|
'attachmentCounts' => array(
|
||||||
'audio' => $audio,
|
'audio' => (int) $has_audio,
|
||||||
'video' => $video
|
'video' => (int) $has_video,
|
||||||
),
|
),
|
||||||
'embedExts' => $exts,
|
'embedExts' => $exts,
|
||||||
'embedMimes' => $ext_mimes,
|
'embedMimes' => $ext_mimes,
|
||||||
|
|
Loading…
Reference in New Issue