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:
| Parameter | Type | Description |
|---|---|---|
$user_id | int | The new user’s ID |
$args | array | Submitted 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
- Go to WSMS → Groups in WordPress admin
- Hover over your desired group
- 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
Related
- wp_sms_add_subscriber - Action hook for new subscribers
- wp_sms_subscriber_form() - Display subscriber form
Last updated: December 23, 2024