WordPress.org

Make WordPress Core

Changeset 48288


Ignore:
Timestamp:
07/03/2020 11:13:30 PM (15 months ago)
Author:
azaozz
Message:

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.

Location:
trunk/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/vendor/plupload/handlers.js

    r48168 r48288  
    569569
    570570            plupload.each( files, function( file ) {
     571                if ( file.type === 'image/heic' && up.settings.heic_upload_error ) {
     572                    // Show error but do not block uploading.
     573                    wpQueueError( pluploadL10n.unsupported_image )
     574                }
     575
    571576                fileQueued( file );
    572577            });
  • trunk/src/js/_enqueues/vendor/plupload/wp-plupload.js

    r48110 r48288  
    352352                }
    353353
     354                if ( file.type === 'image/heic' && up.settings.heic_upload_error ) {
     355                    // Show error but do not block uploading.
     356                    Uploader.errors.unshift({
     357                        message: pluploadL10n.unsupported_image,
     358                        data:    {},
     359                        file:    file
     360                    });
     361                }
     362
    354363                // Generate attributes for a new `Attachment` model.
    355364                attributes = _.extend({
  • trunk/src/wp-admin/includes/admin-filters.php

    r48121 r48288  
    1616// Media hooks.
    1717add_action( 'attachment_submitbox_misc_actions', 'attachment_submitbox_metadata' );
     18add_filter( 'plupload_init', 'wp_show_heic_upload_error' );
    1819
    1920add_action( 'media_upload_image', 'wp_media_upload_handler' );
  • trunk/src/wp-includes/default-filters.php

    r48189 r48288  
    535535add_action( 'customize_controls_enqueue_scripts', 'wp_plupload_default_settings' );
    536536add_action( 'plugins_loaded', '_wp_add_additional_image_sizes', 0 );
     537add_filter( 'plupload_default_settings', 'wp_show_heic_upload_error' );
    537538
    538539// Nav menu.
  • trunk/src/wp-includes/functions.php

    r48205 r48288  
    30473047            'tiff|tif'                     => 'image/tiff',
    30483048            'ico'                          => 'image/x-icon',
     3049            'heic'                         => 'image/heic',
    30493050            // Video formats.
    30503051            'asf|asx'                      => 'video/x-ms-asf',
  • trunk/src/wp-includes/media.php

    r48275 r48288  
    36003600     * @param array $params Default Plupload parameters array.
    36013601     */
    3602     $params                       = apply_filters( 'plupload_default_params', $params );
    3603     $params['_wpnonce']           = wp_create_nonce( 'media-form' );
     3602    $params = apply_filters( 'plupload_default_params', $params );
     3603
     3604    $params['_wpnonce'] = wp_create_nonce( 'media-form' );
     3605
    36043606    $defaults['multipart_params'] = $params;
    36053607
     
    46874689    add_image_size( '2048x2048', 2048, 2048 );
    46884690}
     4691
     4692/**
     4693 * Callback to enable showig of the user error when uploading .heic images.
     4694 *
     4695 * @since 5.5.0
     4696 *
     4697 * @param array[] $plupload_settings The settings for Plupload.js.
     4698 * @return array[] Modified settings for Plupload.js.
     4699 */
     4700function wp_show_heic_upload_error( $plupload_settings ) {
     4701    $plupload_settings['heic_upload_error'] = true;
     4702    return $plupload_settings;
     4703}
  • trunk/src/wp-includes/script-loader.php

    r48285 r48288  
    847847        /* translators: %s: File name. */
    848848        'error_uploading'           => __( '“%s” has failed to upload.' ),
     849        'unsupported_image'         => __( 'This image cannot be displayed in a web browser. For best results convert it to JPEG before uploading.' ),
    849850    );
    850851
Note: See TracChangeset for help on using the changeset viewer.