Make WordPress Core

Changeset 63338


Ignore:
Timestamp:
08/21/2026 08:59:29 PM (10 hours ago)
Author:
westonruter
Message:

Media: Restore the HEIC upload error on the media upload form.

The wp_show_heic_upload_error() function assigned the heic_upload_error flag to an undeclared $plupload_init variable rather than to its $plupload_settings parameter, so the callback returned the settings untouched and the flag never reached Plupload.

Only the plupload_init path was affected: the wp_plupload_default_settings() function sets the same flag inline before applying plupload_default_settings, so screens fed by _wpPluploadSettings kept warning correctly. The regression was confined to media-new.php and the media-upload.php iframe, where media_upload_form() relies on this callback alone for HEIC.

Also correct the documented types for the settings array from array[] to array<string, mixed>, both on the function and on the plupload_init hook, and add regression tests for the callback.

Developed in https://github.com/WordPress/wordpress-develop/pull/12830.
Follow-up to r48288, r58849.

Props softglaze, westonruter, khokansardar, irozum.
See #53645.
Fixes #65802.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/media.php

    r62978 r63338  
    22352235         * @since 3.3.0
    22362236         *
    2237          * @param array $plupload_init An array of default settings used by Plupload.
     2237         * @param array<string, mixed> $plupload_init An array of default settings used by Plupload.
    22382238         */
    22392239        $plupload_init = apply_filters( 'plupload_init', $plupload_init );
  • trunk/src/wp-includes/media.php

    r63177 r63338  
    58745874 *              supports the format. The uploads are converted to JPEG's by default.
    58755875 *
    5876  * @param array[] $plupload_settings The settings for Plupload.js.
    5877  * @return array[] Modified settings for Plupload.js.
     5876 * @param array<string, mixed> $plupload_settings The settings for Plupload.js.
     5877 * @return array<string, mixed> Modified settings for Plupload.js.
    58785878 */
    58795879function wp_show_heic_upload_error( $plupload_settings ) {
    58805880        // Check if HEIC images can be edited.
    58815881        if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/heic' ) ) ) {
    5882                 $plupload_init['heic_upload_error'] = true;
     5882                $plupload_settings['heic_upload_error'] = true;
    58835883        }
    58845884        return $plupload_settings;
  • trunk/tests/phpunit/tests/media.php

    r63002 r63338  
    78447844                remove_filter( 'wp_editor_set_quality', $zero );
    78457845        }
     7846
     7847        /**
     7848         * Ensures the HEIC upload error flag is added when image editors do not support HEIC.
     7849         *
     7850         * @ticket 65802
     7851         *
     7852         * @covers ::wp_show_heic_upload_error
     7853         */
     7854        public function test_wp_show_heic_upload_error_adds_flag_when_not_supported() {
     7855                // Force the editor check to return false.
     7856                add_filter( 'wp_image_editors', '__return_empty_array' );
     7857
     7858                $settings = array( 'existing' => 'value' );
     7859                $result   = wp_show_heic_upload_error( $settings );
     7860
     7861                $this->assertArrayHasKey( 'heic_upload_error', $result, 'The heic_upload_error key is expected to be added to the array.' );
     7862                $this->assertTrue( $result['heic_upload_error'], 'The heic_upload_error flag is expected to be true.' );
     7863                $this->assertArrayHasKey( 'existing', $result, 'Existing array keys are expected to be preserved.' );
     7864                $this->assertSame( 'value', $result['existing'], 'Existing array values are expected to remain unmodified.' );
     7865        }
     7866
     7867        /**
     7868         * Ensures the HEIC upload error flag is absent when image editors support HEIC.
     7869         *
     7870         * @ticket 65802
     7871         *
     7872         * @covers ::wp_show_heic_upload_error
     7873         */
     7874        public function test_wp_show_heic_upload_error_omits_flag_when_supported() {
     7875                // Skip if the environment cannot support HEIC.
     7876                if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/heic' ) ) ) {
     7877                        $this->markTestSkipped( 'HEIC is not supported by the selected image editor.' );
     7878                }
     7879
     7880                $settings = array( 'existing' => 'value' );
     7881                $result   = wp_show_heic_upload_error( $settings );
     7882
     7883                $this->assertArrayNotHasKey( 'heic_upload_error', $result, 'The heic_upload_error key is not expected to be present when HEIC is supported.' );
     7884                $this->assertArrayHasKey( 'existing', $result, 'Existing array keys are expected to be preserved.' );
     7885                $this->assertSame( 'value', $result['existing'], 'Existing array values are expected to remain unmodified.' );
     7886        }
    78467887}
    78477888
Note: See TracChangeset for help on using the changeset viewer.