diff --git a/src/js/_enqueues/vendor/plupload/handlers.js b/src/js/_enqueues/vendor/plupload/handlers.js index 1edfc5cf42..884d8596fc 100644 --- a/src/js/_enqueues/vendor/plupload/handlers.js +++ b/src/js/_enqueues/vendor/plupload/handlers.js @@ -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 ); }); diff --git a/src/js/_enqueues/vendor/plupload/wp-plupload.js b/src/js/_enqueues/vendor/plupload/wp-plupload.js index c89553b2de..7ac790ec00 100644 --- a/src/js/_enqueues/vendor/plupload/wp-plupload.js +++ b/src/js/_enqueues/vendor/plupload/wp-plupload.js @@ -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, diff --git a/src/wp-admin/includes/admin-filters.php b/src/wp-admin/includes/admin-filters.php index 7f9e09e0ed..345a6114af 100644 --- a/src/wp-admin/includes/admin-filters.php +++ b/src/wp-admin/includes/admin-filters.php @@ -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' ); diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php index 2fd1d33b69..dc51908604 100644 --- a/src/wp-includes/default-filters.php +++ b/src/wp-includes/default-filters.php @@ -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 ); diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 4fea38c7fa..5a2abd808c 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -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', diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index 5fe27ba113..18cc3d6d30 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -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; +} diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index 63e5d08a7f..30a4090b37 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -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' );