wp_sms_single_dispatch_arguments
Modify SMS parameters before dispatching messages to individual recipients.
The wp_sms_single_dispatch_arguments filter allows you to customize SMS parameters before messages are dispatched to individual phone numbers. Use this to modify recipient details, message content, or add dynamic elements.
Syntax
add_filter('wp_sms_single_dispatch_arguments', 'your_callback');
Parameters
| Parameter | Type | Description |
|---|---|---|
$arguments | array | SMS dispatch configuration |
$arguments['to'] | string | Recipient’s phone number |
$arguments['msg'] | string | Message body text |
Requirements
For this filter to work properly, configure Settings → SMS Gateways → SMS Dispatch with delivery method set to Batch SMS Queue.
Examples
Add Unsubscribe Link
Append an opt-out URL to every message:
add_filter('wp_sms_single_dispatch_arguments', function($arguments) {
$unsubscribeLink = \WP_SMS\Newsletter::generateUnSubscribeUrlByNumber($arguments['to']);
$arguments['msg'] .= "\n" . $unsubscribeLink;
return $arguments;
});
Dynamic Placeholder Replacement
Replace custom tokens with subscriber or user information:
add_filter('wp_sms_single_dispatch_arguments', function($arguments) {
$subscriber = \WP_SMS\Newsletter::getSubscriberByMobile($arguments['to']);
$user = \WP_SMS\Helper::getUserByPhoneNumber($arguments['to']);
if ($subscriber) {
$arguments['msg'] = str_replace('{display_name}', $subscriber->name, $arguments['msg']);
} elseif ($user) {
$arguments['msg'] = str_replace('{display_name}', $user->display_name, $arguments['msg']);
}
return $arguments;
});
Add Message Prefix
add_filter('wp_sms_single_dispatch_arguments', function($arguments) {
$arguments['msg'] = "[MyCompany] " . $arguments['msg'];
return $arguments;
});
Log Outgoing Messages
add_filter('wp_sms_single_dispatch_arguments', function($arguments) {
error_log("SMS to {$arguments['to']}: {$arguments['msg']}");
return $arguments;
});
Use Cases
- Add unsubscribe links to comply with regulations
- Replace dynamic placeholders with user data
- Add company prefix or branding to messages
- Log outgoing messages for debugging
- Modify recipient numbers (add country code, etc.)
Related
- wp_sms_send (Action) - Action after SMS is sent
- wp_sms_send() - Function to send SMS
Last updated: December 23, 2024