Move counting of attachments for audio/video to the backend, instead of using a `reduce` function in JS.

See #27554.


Built from https://develop.svn.wordpress.org/trunk@27788


git-svn-id: http://core.svn.wordpress.org/trunk@27624 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2014-03-27 18:16:16 +00:00
parent e1be2d21d8
commit ff6c0731fa
3 changed files with 15 additions and 46 deletions

View File

@ -902,50 +902,6 @@
} }
}); });
_.extend( wp.media.playlist, {
/**
* Determine how many audio and video files the user has uploaded
*
* @global wp.media.view.settings
*
* @param {Object} settings
* @returns {Object}
*/
counts : (function(settings) {
var counts = {};
return function() {
if ( ! _.isEmpty( counts ) ) {
return counts;
}
var a = 0, v = 0;
_.each( settings.attachmentCounts, function(total, mime) {
var type;
if ( -1 < mime.indexOf('/') ) {
type = mime.split('/')[0];
total = parseInt(total, 10);
switch ( type ) {
case 'audio':
a += total;
break;
case 'video':
v += total;
break;
}
}
} );
counts.audio = a;
counts.video = v;
return counts;
};
}(media.view.settings))
} );
/** /**
* Event binding * Event binding
*/ */

File diff suppressed because one or more lines are too long

View File

@ -2380,6 +2380,16 @@ function wp_enqueue_media( $args = array() ) {
} }
} }
$audio = $video = 0;
$counts = wp_count_attachments();
foreach ( $counts as $mime => $total ) {
if ( 0 === strpos( $mime, 'audio/' ) ) {
$audio += (int) $total;
} elseif ( 0 === strpos( $mime, 'video/' ) ) {
$video += (int) $total;
}
}
$settings = array( $settings = array(
'tabs' => $tabs, 'tabs' => $tabs,
'tabUrl' => add_query_arg( array( 'chromeless' => true ), admin_url('media-upload.php') ), 'tabUrl' => add_query_arg( array( 'chromeless' => true ), admin_url('media-upload.php') ),
@ -2392,7 +2402,10 @@ function wp_enqueue_media( $args = array() ) {
'id' => 0, 'id' => 0,
), ),
'defaultProps' => $props, 'defaultProps' => $props,
'attachmentCounts' => wp_count_attachments(), 'attachmentCounts' => array(
'audio' => $audio,
'video' => $video
),
'embedExts' => $exts, 'embedExts' => $exts,
'embedMimes' => $ext_mimes, 'embedMimes' => $ext_mimes,
'contentWidth' => $content_width, 'contentWidth' => $content_width,