The check_is_user_spammed WordPress PHP filter allows you to determine if a user has been marked as a spammer.
Usage
add_filter('check_is_user_spammed', 'your_custom_function', 10, 2);
function your_custom_function($spammed, $user) {
// your custom code here
return $spammed;
}
Parameters
$spammed(bool): Whether the user is considered a spammer.$user(WP_User): User object to check against.
More information
See WordPress Developer Resources: check_is_user_spammed
Examples
Block all users with specific email domain
Block users whose email addresses belong to a specific domain.
add_filter('check_is_user_spammed', 'block_specific_email_domain', 10, 2);
function block_specific_email_domain($spammed, $user) {
if (strpos($user->user_email, '@example.com') !== false) {
$spammed = true;
}
return $spammed;
}
Allow certain usernames
Allow specific users even if they are marked as spammers.
add_filter('check_is_user_spammed', 'allow_certain_usernames', 10, 2);
function allow_certain_usernames($spammed, $user) {
$allowed_usernames = array('JohnDoe', 'JaneDoe');
if (in_array($user->user_login, $allowed_usernames)) {
$spammed = false;
}
return $spammed;
}
Check user’s registration date
Mark users as spammers if they registered before a certain date.
add_filter('check_is_user_spammed', 'mark_old_users_as_spammers', 10, 2);
function mark_old_users_as_spammers($spammed, $user) {
$cutoff_date = '2020-01-01';
if (strtotime($user->user_registered) < strtotime($cutoff_date)) {
$spammed = true;
}
return $spammed;
}
Check user’s post count
Mark users as spammers if they have more than a certain number of published posts.
add_filter('check_is_user_spammed', 'mark_users_with_high_post_count_as_spammers', 10, 2);
function mark_users_with_high_post_count_as_spammers($spammed, $user) {
$post_count = count_user_posts($user->ID, 'post', true);
if ($post_count > 50) {
$spammed = true;
}
return $spammed;
}
Combine multiple conditions
Mark users as spammers if they meet multiple conditions.
add_filter('check_is_user_spammed', 'mark_users_with_multiple_conditions_as_spammers', 10, 2);
function mark_users_with_multiple_conditions_as_spammers($spammed, $user) {
$post_count = count_user_posts($user->ID, 'post', true);
$is_old_user = strtotime($user->user_registered) < strtotime('2020-01-01');
if ($post_count > 50 && $is_old_user) {
$spammed = true;
}
return $spammed;
}