wp_create_thumbnail()
云策文档标注
概述
wp_create_thumbnail() 是一个已弃用的 WordPress 函数,用于根据最大边长创建图像缩略图。自 3.5.0 版本起,建议使用 image_resize() 替代。
关键要点
- 函数 wp_create_thumbnail() 已弃用,自 WordPress 3.5.0 起被 image_resize() 取代。
- 参数包括 $file(原始图像文件名或附件 ID)、$max_side(缩略图最大边长)和 $deprecated(未使用)。
- 返回成功时的缩略图路径或失败时的错误字符串。
- 内部调用 _deprecated_function() 标记弃用,并通过 apply_filters() 应用过滤器。
代码示例
function wp_create_thumbnail( $file, $max_side, $deprecated = '' ) {
_deprecated_function( __FUNCTION__, '3.5.0', 'image_resize()' );
return apply_filters( 'wp_create_thumbnail', image_resize( $file, $max_side, $max_side ) );
}注意事项
- 开发者应避免使用此函数,改用 image_resize() 以保持代码兼容性和最佳实践。
- 相关函数包括 image_resize()、_deprecated_function() 和 apply_filters()。
原文内容
This was once used to create a thumbnail from an Image given a maximum side size.
Description
See also
Parameters
$filemixedrequired-
Filename of the original image, Or attachment ID.
$max_sideintrequired-
Maximum length of a single side for the thumbnail.
$deprecatedmixedrequired-
Never used.
Source
function wp_create_thumbnail( $file, $max_side, $deprecated = '' ) {
_deprecated_function( __FUNCTION__, '3.5.0', 'image_resize()' );
return apply_filters( 'wp_create_thumbnail', image_resize( $file, $max_side, $max_side ) );
}
Changelog
| Version | Description |
|---|---|
| 3.5.0 | Deprecated. Use image_resize() |
| 1.2.0 | Introduced. |