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. git-svn-id: https://develop.svn.wordpress.org/trunk@37727 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
7a4e523b5e
commit
41823be421
@ -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;
|
||||
|
@ -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 ) ) ),
|
||||
),
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user