is_avatar_comment_type()
云策文档标注
概述
is_avatar_comment_type() 函数用于检查指定评论类型是否允许获取头像。它通过过滤钩子 get_avatar_comment_types 来管理允许的评论类型列表。
关键要点
- 函数接受一个字符串参数 $comment_type,表示要检查的评论类型。
- 返回布尔值,指示该评论类型是否在允许获取头像的列表中。
- 默认允许的评论类型包括 'comment' 和 'note'(自 WordPress 6.9.0 起添加 'note')。
- 可通过 apply_filters('get_avatar_comment_types', $types) 钩子自定义允许的评论类型数组。
代码示例
function is_avatar_comment_type( $comment_type ) {
$allowed_comment_types = apply_filters( 'get_avatar_comment_types', array( 'comment', 'note' ) );
return in_array( $comment_type, (array) $allowed_comment_types, true );
}注意事项
- 函数自 WordPress 5.1.0 版本引入。
- get_avatar_comment_types 过滤钩子允许开发者扩展或修改允许的评论类型。
- 相关函数 get_avatar_data() 使用此函数来检索头像数据。
原文内容
Check if this comment type allows avatars to be retrieved.
Parameters
$comment_typestringrequired-
Comment type to check.
Source
function is_avatar_comment_type( $comment_type ) {
/**
* Filters the list of allowed comment types for retrieving avatars.
*
* @since 3.0.0
*
* @since 6.9.0 The 'note' comment type was added.
*
* @param array $types An array of content types. Default contains 'comment' and 'note'.
*/
$allowed_comment_types = apply_filters( 'get_avatar_comment_types', array( 'comment', 'note' ) );
return in_array( $comment_type, (array) $allowed_comment_types, true );
}
Hooks
- apply_filters( ‘get_avatar_comment_types’, array $types )
-
Filters the list of allowed comment types for retrieving avatars.
Changelog
| Version | Description |
|---|---|
| 5.1.0 | Introduced. |