The is_user_spammy() WordPress PHP function determines whether a user is marked as a spammer, based on their user login.
Usage
To use the is_user_spammy() function, simply pass a WP_User
object or a user login name as a string. If no parameter is provided, it defaults to the current user.
$is_spammy = is_user_spammy($user);
Parameters
$user
(string|WP_User) – Optional. Defaults to the current user. Accepts aWP_User
object or a user login name as a string. Default: null.
More information
See WordPress Developer Resources: is_user_spammy()
Examples
Check if the current user is spammy
$is_spammy = is_user_spammy(); if ($is_spammy) { echo "The current user is marked as spammy."; } else { echo "The current user is not marked as spammy."; }
Check if a specific user is spammy by user login
$user_login = "john_doe"; $is_spammy = is_user_spammy($user_login); if ($is_spammy) { echo "User {$user_login} is marked as spammy."; } else { echo "User {$user_login} is not marked as spammy."; }
Check if a specific user is spammy by WP_User object
$user_id = 1; $user = get_userdata($user_id); $is_spammy = is_user_spammy($user); if ($is_spammy) { echo "User {$user->user_login} is marked as spammy."; } else { echo "User {$user->user_login} is not marked as spammy."; }
Display a list of spammy users
$all_users = get_users(); foreach ($all_users as $user) { if (is_user_spammy($user)) { echo "User {$user->user_login} is marked as spammy.<br>"; } }
Remove posts of spammy users
$all_users = get_users(); foreach ($all_users as $user) { if (is_user_spammy($user)) { $user_posts = get_posts(array('author' => $user->ID)); foreach ($user_posts as $post) { wp_delete_post($post->ID, true); } } }