wp_prevent_unsupported_mime_type_uploads
云策文档标注
概述
wp_prevent_unsupported_mime_type_uploads 是一个 WordPress 过滤器,用于控制服务器是否阻止上传其不支持的图像类型。默认值为 true,即阻止上传。
关键要点
- 此过滤器允许开发者通过修改布尔值来启用或禁用对服务器不支持图像类型的上传限制。
- 过滤器接受两个参数:$check_mime(布尔值,决定是否阻止上传)和 $mime_type(字符串或 null,表示上传文件的 MIME 类型)。
- 默认情况下,WordPress 会阻止上传服务器不支持的图像类型,但开发者可以自定义此行为以允许特定类型。
代码示例
$prevent_unsupported_uploads = apply_filters( 'wp_prevent_unsupported_mime_type_uploads', true, isset( $files['file']['type'] ) ? $files['file']['type'] : null );注意事项
- 此过滤器在 WordPress 6.8.0 版本中引入,使用时需确保版本兼容性。
- 相关函数包括 WP_REST_Attachments_Controller::create_item_permissions_check() 和 media_upload_form(),用于权限检查和媒体上传表单输出。
原文内容
Filter whether the server should prevent uploads for image types it doesn’t support. Default true.
Description
Developers can use this filter to enable uploads of certain image types. By default image types that are not supported by the server are prevented from being uploaded.
Parameters
$check_mimebool-
Whether to prevent uploads of unsupported image types.
$mime_typestring|null-
The mime type of the file being uploaded (if available).
Source
$prevent_unsupported_uploads = apply_filters( 'wp_prevent_unsupported_mime_type_uploads', true, isset( $files['file']['type'] ) ? $files['file']['type'] : null );
Changelog
| Version | Description |
|---|---|
| 6.8.0 | Introduced. |