Media: Show an error message when a .heic file is uploaded that this type of files cannot be displayed in a web browser and suggesting to convert to JPEG. The message is shown by using filters, plugins that want to handle uploading of .heic files can remove it.

Props mattheweppelsheimer, mikeschroder, jeffr0, andraganescu, desrosj, azaozz.
Fixes #42775.

git-svn-id: https://develop.svn.wordpress.org/trunk@48288 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Ozz 2020-07-03 23:13:30 +00:00
parent ce09e3c87b
commit 1285255381
7 changed files with 35 additions and 2 deletions

View File

@ -568,6 +568,11 @@ jQuery( document ).ready( function( $ ) {
uploadStart();
plupload.each( files, function( file ) {
if ( file.type === 'image/heic' && up.settings.heic_upload_error ) {
// Show error but do not block uploading.
wpQueueError( pluploadL10n.unsupported_image )
}
fileQueued( file );
});

View File

@ -351,6 +351,15 @@ window.wp = window.wp || {};
return;
}
if ( file.type === 'image/heic' && up.settings.heic_upload_error ) {
// Show error but do not block uploading.
Uploader.errors.unshift({
message: pluploadL10n.unsupported_image,
data: {},
file: file
});
}
// Generate attributes for a new `Attachment` model.
attributes = _.extend({
file: file,

View File

@ -15,6 +15,7 @@ add_action( 'activity_box_end', 'wp_dashboard_quota' );
// Media hooks.
add_action( 'attachment_submitbox_misc_actions', 'attachment_submitbox_metadata' );
add_filter( 'plupload_init', 'wp_show_heic_upload_error' );
add_action( 'media_upload_image', 'wp_media_upload_handler' );
add_action( 'media_upload_audio', 'wp_media_upload_handler' );

View File

@ -534,6 +534,7 @@ add_filter( 'the_content', 'do_shortcode', 11 ); // AFTER wpautop().
add_action( 'wp_playlist_scripts', 'wp_playlist_scripts' );
add_action( 'customize_controls_enqueue_scripts', 'wp_plupload_default_settings' );
add_action( 'plugins_loaded', '_wp_add_additional_image_sizes', 0 );
add_filter( 'plupload_default_settings', 'wp_show_heic_upload_error' );
// Nav menu.
add_filter( 'nav_menu_item_id', '_nav_menu_item_id_use_once', 10, 2 );

View File

@ -3046,6 +3046,7 @@ function wp_get_mime_types() {
'bmp' => 'image/bmp',
'tiff|tif' => 'image/tiff',
'ico' => 'image/x-icon',
'heic' => 'image/heic',
// Video formats.
'asf|asx' => 'video/x-ms-asf',
'wmv' => 'video/x-ms-wmv',

View File

@ -3599,8 +3599,10 @@ function wp_plupload_default_settings() {
*
* @param array $params Default Plupload parameters array.
*/
$params = apply_filters( 'plupload_default_params', $params );
$params['_wpnonce'] = wp_create_nonce( 'media-form' );
$params = apply_filters( 'plupload_default_params', $params );
$params['_wpnonce'] = wp_create_nonce( 'media-form' );
$defaults['multipart_params'] = $params;
$settings = array(
@ -4686,3 +4688,16 @@ function _wp_add_additional_image_sizes() {
// 2x large size.
add_image_size( '2048x2048', 2048, 2048 );
}
/**
* Callback to enable showig of the user error when uploading .heic images.
*
* @since 5.5.0
*
* @param array[] $plupload_settings The settings for Plupload.js.
* @return array[] Modified settings for Plupload.js.
*/
function wp_show_heic_upload_error( $plupload_settings ) {
$plupload_settings['heic_upload_error'] = true;
return $plupload_settings;
}

View File

@ -846,6 +846,7 @@ function wp_default_scripts( $scripts ) {
'deleted' => __( 'moved to the Trash.' ),
/* translators: %s: File name. */
'error_uploading' => __( '“%s” has failed to upload.' ),
'unsupported_image' => __( 'This image cannot be displayed in a web browser. For best results convert it to JPEG before uploading.' ),
);
$scripts->add( 'moxiejs', "/wp-includes/js/plupload/moxie$suffix.js", array(), '1.3.5' );