wp_sms_api_message_content

Modify SMS message content before transmission through the REST API.

The wp_sms_api_message_content filter allows you to modify SMS message content before transmission through the WSMS REST API.

Syntax

add_filter('wp_sms_api_message_content', 'your_callback', 10, 2);

Parameters

ParameterTypeDescription
$messagestringThe original message text
$argsarrayRequest parameters passed to the SMS API

Return Value

Must return the modified message string.

Examples

Add Unsubscribe Instructions

add_filter('wp_sms_api_message_content', function($message, $args) {
    if (!empty($args['group_ids'])) {
        $message .= "\nReply STOP to unsubscribe from this group.";
    } else {
        $message .= "\nReply STOP to unsubscribe.";
    }

    return $message;
}, 10, 2);

Add Timestamp

add_filter('wp_sms_api_message_content', function($message, $args) {
    $timestamp = date('Y-m-d H:i:s');
    $message .= "\n[Sent: {$timestamp}]";

    return $message;
}, 10, 2);

Conditional Formatting

add_filter('wp_sms_api_message_content', function($message, $args) {
    if (strpos($message, 'SPECIALOFFER') !== false) {
        $message = "šŸŽ‰ " . $message . " šŸŽ‰";
    }

    return $message;
}, 10, 2);

Add Sender Branding

add_filter('wp_sms_api_message_content', function($message, $args) {
    return "[MyStore] " . $message;
}, 10, 2);

Character Limit Warning

add_filter('wp_sms_api_message_content', function($message, $args) {
    if (strlen($message) > 160) {
        error_log("SMS exceeds 160 chars: " . strlen($message));
    }

    return $message;
}, 10, 2);

Use Cases

  • Add unsubscribe instructions for compliance
  • Append timestamps for tracking
  • Add branding or prefix to messages
  • Apply conditional formatting based on content
  • Log or validate message length
FilterDescription
wp_sms_msgModify message content (general)
wp_sms_toModify recipient numbers
wp_sms_fromModify sender ID

Last updated: December 23, 2024