函数文档

wp_show_heic_upload_error()

💡 云策文档标注

概述

wp_show_heic_upload_error() 是一个回调函数,用于在用户上传 .heic 图像时启用错误显示。它检查服务器是否支持编辑 HEIC 图像,并相应修改 Plupload.js 设置。

关键要点

  • 函数接受一个数组参数 $plupload_settings,表示 Plupload.js 的设置,并返回修改后的数组。
  • 通过 wp_image_editor_supports() 检查是否有图像编辑器支持 'image/heic' MIME 类型,如果不支持,则设置 $plupload_init['heic_upload_error'] 为 true。
  • 从 WordPress 5.5.0 版本引入,6.7.0 版本后默认行为是启用 HEIC 上传(如果服务器支持),并自动转换为 JPEG。

代码示例

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;
	}
	return $plupload_settings;
}

注意事项

  • 此函数主要用于处理上传错误,确保用户在上传不支持格式时收到适当反馈。
  • 相关函数 wp_image_editor_supports() 用于测试编辑器对 MIME 类型的支持。

📄 原文内容

Callback to enable showing of the user error when uploading .heic images.

Parameters

$plupload_settingsarray[]required
The settings for Plupload.js.

Return

array[] Modified settings for Plupload.js.

Source

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;
	}
	return $plupload_settings;
}

Changelog

Version Description
6.7.0 The default behavior is to enable heic uploads as long as the server supports the format. The uploads are converted to JPEG’s by default.
5.5.0 Introduced.