wp_authenticate_spam_check()
云策文档标注
概述
wp_authenticate_spam_check() 是 WordPress 多站点环境下的一个函数,用于在用户认证过程中检查用户是否被标记为垃圾用户或其主博客是否被标记为垃圾。
关键要点
- 函数仅在多站点(is_multisite())环境下生效,并接受一个 WP_User 或 WP_Error 对象作为参数。
- 通过 apply_filters('check_is_user_spammed', ...) 钩子允许开发者自定义垃圾用户检查逻辑。
- 如果用户被判定为垃圾用户,函数返回一个 WP_Error 对象,错误代码为 'spammer_account',否则返回原始 WP_User 对象。
代码示例
function wp_authenticate_spam_check( $user ) {
if ( $user instanceof WP_User && is_multisite() ) {
$spammed = apply_filters( 'check_is_user_spammed', is_user_spammy( $user ), $user );
if ( $spammed ) {
return new WP_Error( 'spammer_account', __( 'Error: Your account has been marked as a spammer.' ) );
}
}
return $user;
}
原文内容
For Multisite blogs, checks if the authenticated user has been marked as a spammer, or if the user’s primary blog has been marked as spam.
Parameters
Source
function wp_authenticate_spam_check( $user ) {
if ( $user instanceof WP_User && is_multisite() ) {
/**
* Filters whether the user has been marked as a spammer.
*
* @since 3.7.0
*
* @param bool $spammed Whether the user is considered a spammer.
* @param WP_User $user User to check against.
*/
$spammed = apply_filters( 'check_is_user_spammed', is_user_spammy( $user ), $user );
if ( $spammed ) {
return new WP_Error( 'spammer_account', __( '<strong>Error:</strong> Your account has been marked as a spammer.' ) );
}
}
return $user;
}
Hooks
- apply_filters( ‘check_is_user_spammed’, bool $spammed, WP_User $user )
-
Filters whether the user has been marked as a spammer.
Changelog
| Version | Description |
|---|---|
| 3.7.0 | Introduced. |