Using WordPress ‘make_ham_user’ PHP action

The make_ham_user WordPress PHP action fires after a user is marked as a HAM user, which is the opposite of being marked as SPAM.

Usage

add_action('make_ham_user', 'your_custom_function');
function your_custom_function($user_id) {
    // your custom code here
}

Parameters

  • $user_id (int) – ID of the user marked as HAM.

More information

See WordPress Developer Resources: make_ham_user

Examples

Send a welcome email to the HAM user

Send a welcome email to the user when they are marked as HAM.

add_action('make_ham_user', 'send_welcome_email_to_ham_user');
function send_welcome_email_to_ham_user($user_id) {
    $user = get_userdata($user_id);
    $email_subject = 'Welcome to our website!';
    $email_body = 'Hello ' . $user->display_name . ', you are now a HAM user on our website. Enjoy your stay!';
    wp_mail($user->user_email, $email_subject, $email_body);
}

Log HAM user status change

Log when a user’s status changes to HAM.

add_action('make_ham_user', 'log_ham_user_status_change');
function log_ham_user_status_change($user_id) {
    $message = 'User ID ' . $user_id . ' has been marked as HAM.';
    error_log($message);
}

Assign a default role to HAM user

Assign a default role to the user when they are marked as HAM.

add_action('make_ham_user', 'assign_default_role_to_ham_user');
function assign_default_role_to_ham_user($user_id) {
    $default_role = 'subscriber';
    $user = new WP_User($user_id);
    $user->set_role($default_role);
}

Add a custom note to the HAM user’s profile

Add a custom note to the user’s profile when they are marked as HAM.

add_action('make_ham_user', 'add_custom_note_to_ham_user_profile');
function add_custom_note_to_ham_user_profile($user_id) {
    $custom_note = 'This user is marked as HAM.';
    update_user_meta($user_id, 'custom_note', $custom_note);
}

Notify admin when a user is marked as HAM

Send an email notification to the admin when a user is marked as HAM.

add_action('make_ham_user', 'notify_admin_about_ham_user');
function notify_admin_about_ham_user($user_id) {
    $user = get_userdata($user_id);
    $admin_email = get_option('admin_email');
    $email_subject = 'New HAM user on your website';
    $email_body = 'User ID: ' . $user_id . ' and username: ' . $user->user_login . ' has been marked as HAM.';
    wp_mail($admin_email, $email_subject, $email_body);
}