From 85de422f337e65fdcb8f2763c4d509616a9666f8 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Thu, 27 Mar 2014 18:15:09 +0000 Subject: [PATCH] Move counting of attachments for audio/video to the backend, instead of using a `reduce` function in JS. See #27554. git-svn-id: https://develop.svn.wordpress.org/trunk@27788 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/js/media-audiovideo.js | 44 -------------------------- src/wp-includes/media.php | 15 ++++++++- 2 files changed, 14 insertions(+), 45 deletions(-) diff --git a/src/wp-includes/js/media-audiovideo.js b/src/wp-includes/js/media-audiovideo.js index 7462ae117d..a1ee78f6ce 100644 --- a/src/wp-includes/js/media-audiovideo.js +++ b/src/wp-includes/js/media-audiovideo.js @@ -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 */ diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index 6639bd4a67..71ac3bcf0a 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -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( 'tabs' => $tabs, 'tabUrl' => add_query_arg( array( 'chromeless' => true ), admin_url('media-upload.php') ), @@ -2392,7 +2402,10 @@ function wp_enqueue_media( $args = array() ) { 'id' => 0, ), 'defaultProps' => $props, - 'attachmentCounts' => wp_count_attachments(), + 'attachmentCounts' => array( + 'audio' => $audio, + 'video' => $video + ), 'embedExts' => $exts, 'embedMimes' => $ext_mimes, 'contentWidth' => $content_width,