Skip to content

Commit 5313cf1

Browse files
authored
Fix heic upload bugs/ errors on WPCOM (#45426)
* test a method to support heic conversion for images uploaded in the block editor * changelog * Remove bogus filters after checking cursors work * bit of cleanup * only introduce heic filter on rest api init * polish * disable the heic upload error in plupload script * re-add arg count
1 parent 8245050 commit 5313cf1

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: fixed
3+
4+
uploads of heic in the block editor

projects/packages/jetpack-mu-wpcom/src/features/media/heif-support.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,41 @@ function jetpack_wpcom_add_heif_mimes_to_supported_upload_types( $mimes ) {
183183
return $mimes;
184184
}
185185
add_filter( 'upload_mimes', 'jetpack_wpcom_add_heif_mimes_to_supported_upload_types' );
186+
187+
/**
188+
* Prevent WordPress from blocking HEIF/HEIC uploads in REST API.
189+
*
190+
* This allows HEIF/HEIC files to pass through the REST API validation
191+
* so they can be converted to JPEG by our conversion filter.
192+
*
193+
* @param bool $check_mime Whether to check the mime type.
194+
* @param string|null $mime_type The mime type being uploaded.
195+
* @return bool
196+
*/
197+
function jetpack_wpcom_allow_heif_uploads_in_rest_api( $check_mime, $mime_type ) {
198+
if ( wp_is_heic_image_mime_type( $mime_type ) ) {
199+
return false;
200+
}
201+
202+
return $check_mime;
203+
}
204+
205+
/**
206+
* Add the HEIF/HEIC upload filter on REST API initialization.
207+
*/
208+
function jetpack_wpcom_add_heif_rest_api_filter() {
209+
add_filter( 'wp_prevent_unsupported_mime_type_uploads', 'jetpack_wpcom_allow_heif_uploads_in_rest_api', 10, 2 );
210+
}
211+
add_action( 'rest_api_init', 'jetpack_wpcom_add_heif_rest_api_filter' );
212+
213+
/**
214+
* Disable HEIC upload error in plupload settings for WordPress.com.
215+
*
216+
* @param array $defaults The default plupload settings.
217+
* @return array The modified settings.
218+
*/
219+
function jetpack_wpcom_disable_heic_plupload_error( $defaults ) {
220+
$defaults['heic_upload_error'] = false;
221+
return $defaults;
222+
}
223+
add_filter( 'plupload_default_settings', 'jetpack_wpcom_disable_heic_plupload_error' );

0 commit comments

Comments
 (0)