wp_image_editor_supports()
云策文档标注
概述
wp_image_editor_supports() 函数用于检测 WordPress 中是否存在支持指定 MIME 类型或图像处理方法的图像编辑器。它基于 _wp_image_editor_choose() 函数实现,返回布尔值表示是否找到符合条件的编辑器。
关键要点
- 函数接受一个可选的 $args 参数,类型为字符串或数组,默认为空数组,用于指定要检测的 MIME 类型或方法。
- 返回值为布尔类型:true 表示找到支持指定条件的编辑器,false 表示未找到。
- 该函数在 WordPress 3.5.0 版本中引入,常用于图像上传、编辑和权限检查等场景。
代码示例
$args = array(
'mime_type' => 'image/png',
'methods' => array(
'rotate',
'resize',
'save'
)
);
$img_editor_test = wp_image_editor_supports( $args );
if ( $img_editor_test ) {
// mime_type and method(s) supported!
}
原文内容
Tests whether there is an editor that supports a given mime type or methods.
Parameters
$argsstring|arrayoptional-
Array of arguments to retrieve the image editor supports.
Default:
array()
Source
function wp_image_editor_supports( $args = array() ) {
return (bool) _wp_image_editor_choose( $args );
}
Changelog
| Version | Description |
|---|---|
| 3.5.0 | Introduced. |
Skip to note 2 content
Codex
Example:
$args = array( 'mime_type' => 'image/png', 'methods' => array( 'rotate', 'resize', 'save' ) ); $img_editor_test = wp_image_editor_supports( $args ); if ( $img_editor_test ) { // mime_type and method(s) supported! }