rest_get_avatar_sizes()
云策文档标注
概述
rest_get_avatar_sizes() 函数用于获取头像的像素尺寸数组,默认返回 [24, 48, 96]。该函数通过 rest_avatar_sizes 过滤器允许开发者自定义尺寸。
关键要点
- 函数返回一个整数数组,表示头像的像素尺寸,默认值为 [24, 48, 96]。
- 可通过 apply_filters('rest_avatar_sizes', $sizes) 钩子过滤尺寸数组,用于自定义调整。
- 该函数在 WordPress 4.7.0 版本中引入,常用于 REST API 相关功能。
代码示例
function rest_get_avatar_sizes() {
return apply_filters( 'rest_avatar_sizes', array( 24, 48, 96 ) );
}注意事项
- 过滤器 rest_avatar_sizes 的参数 $sizes 是一个整数数组,开发者应确保返回有效尺寸值。
- 此函数被 rest_get_avatar_urls() 和多个 REST 控制器(如 WP_REST_Users_Controller、WP_REST_Comments_Controller)调用,用于生成头像 URL 或模式定义。
原文内容
Retrieves the pixel sizes for avatars.
Source
function rest_get_avatar_sizes() {
/**
* Filters the REST avatar sizes.
*
* Use this filter to adjust the array of sizes returned by the
* `rest_get_avatar_sizes` function.
*
* @since 4.4.0
*
* @param int[] $sizes An array of int values that are the pixel sizes for avatars.
* Default `[ 24, 48, 96 ]`.
*/
return apply_filters( 'rest_avatar_sizes', array( 24, 48, 96 ) );
}
Hooks
- apply_filters( ‘rest_avatar_sizes’, int[] $sizes )
-
Filters the REST avatar sizes.
Changelog
| Version | Description |
|---|---|
| 4.7.0 | Introduced. |