user_{$field}
云策文档标注
概述
本文档介绍 WordPress 中的 user_{$field} 过滤器,用于在标准上下文中过滤用户字段的值。该过滤器是动态命名的,$field 指代用户字段前缀,如 user_login、user_email 等。
关键要点
- user_{$field} 是一个动态过滤器,$field 参数指定要过滤的用户字段,例如 user_login 或 user_email。
- 过滤器接受三个参数:$value(用户对象值)、$user_id(用户 ID)和 $context(过滤上下文)。
- 主要用于 sanitize_user_field() 函数中,用于根据上下文清理用户字段。
- 自 WordPress 2.9.0 版本引入。
代码示例
$value = apply_filters( "user_{$field}", $value, $user_id, $context );
原文内容
Filters the value of a user field in a standard context.
Description
The dynamic portion of the hook name, $field, refers to the prefixed user field being filtered, such as ‘user_login’, ‘user_email’, ‘first_name’, etc.
Parameters
$valuemixed-
The user object value to sanitize.
$user_idint-
User ID.
$contextstring-
The context to filter within.
Source
$value = apply_filters( "user_{$field}", $value, $user_id, $context );
Changelog
| Version | Description |
|---|---|
| 2.9.0 | Introduced. |