sanitize_user
云策文档标注
概述
sanitize_user 是一个 WordPress 过滤器,用于在用户名被 sanitize_user() 函数清理后进一步过滤。它允许开发者自定义用户名处理逻辑,例如转换为小写。
关键要点
- sanitize_user 过滤器在用户名清理后触发,用于修改或调整用户名字符串。
- 参数包括 $username(已清理的用户名)、$raw_username(原始用户名)和 $strict(是否严格限制字符)。
- 常用于添加自定义清理规则,如通过 add_filter('sanitize_user', 'strtolower') 将用户名转换为小写。
代码示例
add_filter('sanitize_user', 'strtolower');
原文内容
Filters a sanitized username string.
Parameters
$usernamestring-
Sanitized username.
$raw_usernamestring-
The username prior to sanitization.
$strictbool-
Whether to limit the sanitization to specific characters.
Source
return apply_filters( 'sanitize_user', $username, $raw_username, $strict );
Changelog
| Version | Description |
|---|---|
| 2.0.1 | Introduced. |
Skip to note 2 content
Steven Lin
Example migrated from Codex:
Filters a user name to be lower-cased after sanitization by sanitize_user()
add_filter('sanitize_user', 'strtolower');