Make WordPress Core

Changeset 37727


Ignore:
Timestamp:
06/16/2016 03:38:12 PM (8 years ago)
Author:
ocean90
Message:

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.

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/plupload/handlers.js

    r37722 r37727  
    286286            break;
    287287        case plupload.FILE_EXTENSION_ERROR:
    288             wpFileError(fileObj, pluploadL10n.invalid_filetype);
     288            wpFileExtensionError( uploader, file, pluploadL10n.invalid_filetype );
    289289            break;
    290290        case plupload.FILE_SIZE_ERROR:
     
    337337        message = pluploadL10n.file_exceeds_size_limit.replace('%s', file.name);
    338338
     339    jQuery('#media-items').append('<div id="media-item-' + file.id + '" class="media-item error"><p>' + message + '</p></div>');
     340    up.removeFile(file);
     341}
     342
     343function wpFileExtensionError( up, file, message ) {
    339344    jQuery('#media-items').append('<div id="media-item-' + file.id + '" class="media-item error"><p>' + message + '</p></div>');
    340345    up.removeFile(file);
  • trunk/src/wp-includes/media.php

    r37560 r37727  
    29192919
    29202920/**
    2921  * Prints default plupload arguments.
     2921 * Prints default Plupload arguments.
    29222922 *
    29232923 * @since 3.4.0
     
    29312931
    29322932    $max_upload_size = wp_max_upload_size();
     2933    $allowed_extensions = array_keys( get_allowed_mime_types() );
     2934    $extensions = array();
     2935    foreach ( $allowed_extensions as $extension ) {
     2936        $extensions = array_merge( $extensions, explode( '|', $extension ) );
     2937    }
    29332938
    29342939    $defaults = array(
     
    29402945        'filters' => array(
    29412946            'max_file_size'   => $max_upload_size . 'b',
     2947            'mime_types'      => array( array( 'extensions' => implode( ',', $extensions ) ) ),
    29422948        ),
    29432949    );
Note: See TracChangeset for help on using the changeset viewer.