Ultimate Member Auto-Subscribe

Automatically subscribe Ultimate Member users to SMS newsletter upon registration.

Automatically add newly registered Ultimate Member users to your SMS newsletter list. This ensures you can reach them instantly with announcements, offers, or important updates.

Requirements

  • WSMS plugin
  • Ultimate Member (UM) plugin
  • At least one SMS Group configured in WSMS → Groups

How It Works

Ultimate Member fires the um_registration_complete action after a user completes registration. This hook provides:

ParameterTypeDescription
$user_idintThe new user’s ID
$argsarraySubmitted form fields (first_name, phone, etc.)

Implementation

Add this code to your theme’s functions.php:

add_action('um_registration_complete', 'wp_sms_subscribe_on_registration', 10, 2);

function wp_sms_subscribe_on_registration($user_id, $args) {
    $first_name_field = 'first_name'; // Change to your field name
    $phone_field = 'phone';           // Change to your field name

    $name = !empty($args[$first_name_field])
        ? sanitize_text_field($args[$first_name_field])
        : "um_user_{$user_id}";

    $mobile = preg_replace('/\D+/', '', $args[$phone_field] ?? '');

    if (empty($mobile)) {
        return; // No phone provided, skip subscription
    }

    $group_id = 1; // Change to your Group ID

    try {
        \WP_SMS\Newsletter::addSubscriber($name, $mobile, $group_id);
    } catch (Exception $e) {
        error_log("WSMS subscribe failed for user {$user_id}: " . $e->getMessage());
    }
}

Configuration

Find Your Group ID

  1. Go to WSMS → Groups in WordPress admin
  2. Hover over your desired group
  3. Note the ID in the URL or the ID column

Customize Field Names

Update these variables to match your Ultimate Member form fields:

$first_name_field = 'first_name'; // Your UM first name field
$phone_field = 'phone';           // Your UM phone field

Last updated: December 23, 2024