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
| Parameter | Type | Description |
|---|---|---|
$message | string | The original message text |
$args | array | Request 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
Related Filters
| Filter | Description |
|---|---|
wp_sms_msg | Modify message content (general) |
wp_sms_to | Modify recipient numbers |
wp_sms_from | Modify sender ID |
Related
- Send SMS Endpoint - REST API to send SMS
- wp_sms_single_dispatch_arguments - Modify dispatch arguments
Last updated: December 23, 2024