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

ParameterTypeDescription
$argumentsarraySMS dispatch configuration
$arguments['to']stringRecipient’s phone number
$arguments['msg']stringMessage body text

Requirements

For this filter to work properly, configure Settings → SMS Gateways → SMS Dispatch with delivery method set to Batch SMS Queue.

Examples

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.)

Last updated: December 23, 2024