Filter: wp_sms_single_dispatch_arguments

Updated on Jul 18, 2024

The wp_sms_single_dispatch_arguments filter allows developers to modify the arguments used before dispatching an SMS to a single number. This can be useful for customizing the SMS parameters, such as the recipient’s number, message content, or any other related argument.

Parameters

  • $arguments (array): The arguments for sending an SMS.
  • to (string): The recipient’s phone number.
  • msg (string): The SMS message content.

Example 1: Appending an Unsubscribe Link

This example demonstrates how to append an unsubscribe link to each SMS message before it is sent.

add_filter('wp_sms_single_dispatch_arguments', function ($arguments) {
    // Generate the unsubscribe link based on the recipient's phone number
    $unsubscribeLink = \WP_SMS\Newsletter::generateUnSubscribeUrlByNumber($arguments['to']);

    // Append the unsubscribe link to the message content
    $arguments['msg'] .= "\r" . $unsubscribeLink;

    // Return the modified arguments
    return $arguments;
});

Example 2: Replacing {display_name} Placeholder

This example demonstrates how to replace the {display_name} placeholder with the subscriber’s name or the user’s display name before the SMS message is sent.

add_filter('wp_sms_single_dispatch_arguments', function ($arguments) {
    // Retrieve the subscriber by mobile number
    $subscriber = \WP_SMS\Newsletter::getSubscriberByMobile($arguments['to']);
    // Retrieve the user by phone number
    $user = \WP_SMS\Helper::getUserByPhoneNumber($arguments['to']);

    // If the subscriber exists, replace {display_name} with the subscriber's name
    if ($subscriber) {
        $arguments['msg'] = str_replace('{display_name}', $subscriber->name, $arguments['msg']);
    }
    // If the user exists, replace {display_name} with the user's display name
    elseif ($user) {
        $arguments['msg'] = str_replace('{display_name}', $user->display_name, $arguments['msg']);
    }

    // Return the modified arguments
    return $arguments;
});

Notes

  • Make sure for these examples the option Delivery Method in Settings → SMS Gateways → SMS Dispatch is set to Batch SMS Queue.

Get our special CHRISTMAS Offer

20% OFF on all packages

CLAIM NOW

Coupon Code: