Media: Pass allowed file extensions to Plupload.

Plupload's `mime_types` filter (http://www.plupload.com/docs/Options#filters.mime_types) allows us to inform a user about an unsupported file before the file gets uploaded.

Props polevaultweb.
Fixes #14244.
Built from https://develop.svn.wordpress.org/trunk@37727


git-svn-id: http://core.svn.wordpress.org/trunk@37693 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dominik Schilling 2016-06-16 15:39:28 +00:00
parent 228c60a222
commit 4e403b2752
4 changed files with 15 additions and 4 deletions

View File

@ -285,7 +285,7 @@ function uploadError(fileObj, errorCode, message, uploader) {
wpFileError(fileObj, pluploadL10n.upload_failed);
break;
case plupload.FILE_EXTENSION_ERROR:
wpFileError(fileObj, pluploadL10n.invalid_filetype);
wpFileExtensionError( uploader, file, pluploadL10n.invalid_filetype );
break;
case plupload.FILE_SIZE_ERROR:
uploadSizeError(uploader, fileObj);
@ -340,6 +340,11 @@ function uploadSizeError( up, file, over100mb ) {
up.removeFile(file);
}
function wpFileExtensionError( up, file, message ) {
jQuery('#media-items').append('<div id="media-item-' + file.id + '" class="media-item error"><p>' + message + '</p></div>');
up.removeFile(file);
}
jQuery(document).ready(function($){
$('.media-upload-form').bind('click.uploader', function(e) {
var target = $(e.target), tr, c;

File diff suppressed because one or more lines are too long

View File

@ -2918,7 +2918,7 @@ function _wp_image_editor_choose( $args = array() ) {
}
/**
* Prints default plupload arguments.
* Prints default Plupload arguments.
*
* @since 3.4.0
*/
@ -2930,6 +2930,11 @@ function wp_plupload_default_settings() {
return;
$max_upload_size = wp_max_upload_size();
$allowed_extensions = array_keys( get_allowed_mime_types() );
$extensions = array();
foreach ( $allowed_extensions as $extension ) {
$extensions = array_merge( $extensions, explode( '|', $extension ) );
}
$defaults = array(
'runtimes' => 'html5,flash,silverlight,html4',
@ -2939,6 +2944,7 @@ function wp_plupload_default_settings() {
'silverlight_xap_url' => includes_url( 'js/plupload/plupload.silverlight.xap' ),
'filters' => array(
'max_file_size' => $max_upload_size . 'b',
'mime_types' => array( array( 'extensions' => implode( ',', $extensions ) ) ),
),
);

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.6-alpha-37726';
$wp_version = '4.6-alpha-37727';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.