From 13a584183b3beeaaf75b88830cd76685f9aa773e Mon Sep 17 00:00:00 2001 From: softglazee Date: Tue, 4 Aug 2026 09:49:14 +0500 Subject: [PATCH] Media: Fix wp_show_heic_upload_error() assigning to an undeclared variable. The function assigned the error flag to an undeclared $plupload_init variable instead of the $plupload_settings parameter, preventing the flag from reaching the returned array. This behavior was introduced in [58849] and shipped in WordPress 6.7.0. Adds unit tests covering both the supported and unsupported cases. See #65802. --- src/wp-includes/media.php | 2 +- tests/phpunit/tests/media.php | 37 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index a31e77b00e26c..c6c6a2cefeb6c 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -5879,7 +5879,7 @@ function _wp_add_additional_image_sizes() { function wp_show_heic_upload_error( $plupload_settings ) { // Check if HEIC images can be edited. if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/heic' ) ) ) { - $plupload_init['heic_upload_error'] = true; + $plupload_settings['heic_upload_error'] = true; } return $plupload_settings; } diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index 5aee3f8b6955f..dfe4838dc04f3 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -7843,6 +7843,43 @@ public function test_wp_get_image_encode_quality_clamps_out_of_range() { $this->assertSame( 1, wp_get_image_encode_quality( 'image/png' ) ); remove_filter( 'wp_editor_set_quality', $zero ); } + + /** + * Ensures the HEIC upload error flag is added when image editors do not support HEIC. + * + * @ticket 65802 + */ + public function test_wp_show_heic_upload_error_adds_flag_when_not_supported() { + // Force the editor check to return false. + add_filter( 'wp_image_editors', '__return_empty_array' ); + + $settings = array( 'existing' => 'value' ); + $result = wp_show_heic_upload_error( $settings ); + + $this->assertArrayHasKey( 'heic_upload_error', $result, 'The heic_upload_error key is expected to be added to the array.' ); + $this->assertTrue( $result['heic_upload_error'], 'The heic_upload_error flag is expected to be true.' ); + $this->assertArrayHasKey( 'existing', $result, 'Existing array keys are expected to be preserved.' ); + $this->assertSame( 'value', $result['existing'], 'Existing array values are expected to remain unmodified.' ); + } + + /** + * Ensures the HEIC upload error flag is absent when image editors support HEIC. + * + * @ticket 65802 + */ + public function test_wp_show_heic_upload_error_omits_flag_when_supported() { + // Skip if the environment cannot support HEIC. + if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/heic' ) ) ) { + $this->markTestSkipped( 'HEIC is not supported by the selected image editor.' ); + } + + $settings = array( 'existing' => 'value' ); + $result = wp_show_heic_upload_error( $settings ); + + $this->assertArrayNotHasKey( 'heic_upload_error', $result, 'The heic_upload_error key is not expected to be present when HEIC is supported.' ); + $this->assertArrayHasKey( 'existing', $result, 'Existing array keys are expected to be preserved.' ); + $this->assertSame( 'value', $result['existing'], 'Existing array values are expected to remain unmodified.' ); + } } /**