Skip to content
Mehmet edited this page Oct 15, 2025 · 1 revision

This comprehensive guide covers all available WordPress actions and filters in the WP SMS plugin, organized by functionality.

Table of Contents


SMS Sending Hooks

Actions

wp_sms_send

Description: Fired after an SMS is successfully sent through any gateway.
Parameters:

  • $response (mixed) - The response from the SMS gateway

Example:

function my_sms_sent_callback($response) {
    // Log the response or perform additional actions
    error_log('SMS sent successfully: ' . print_r($response, true));
}
add_action('wp_sms_send', 'my_sms_sent_callback');

wp_sms_after_gateway

Description: Allows adding content after the gateway configuration section in admin.
Parameters: None

Example:

function add_gateway_help_text() {
    echo '<p class="description">Custom gateway help text here.</p>';
}
add_action('wp_sms_after_gateway', 'add_gateway_help_text');

Filters

wp_sms_from

Description: Modify the sender number before sending SMS.
Parameters:

  • $from (string) - The sender number

Example:

function modify_sender_number($from) {
    // Add prefix to sender number
    return 'WP-' . $from;
}
add_filter('wp_sms_from', 'modify_sender_number');

wp_sms_to

Description: Modify the recipient numbers before sending SMS.
Parameters:

  • $to (array) - Array of recipient numbers

Example:

function add_admin_to_recipients($to) {
    // Add admin number to all SMS sends
    $admin_number = get_option('admin_mobile_number');
    if ($admin_number) {
        $to[] = $admin_number;
    }
    return $to;
}
add_filter('wp_sms_to', 'add_admin_to_recipients');

wp_sms_msg

Description: Modify the SMS message content before sending.
Parameters:

  • $msg (string) - The message text

Example:

function add_signature_to_sms($msg) {
    // Add signature to all messages
    return $msg . "\n\nPowered by WP-SMS";
}
add_filter('wp_sms_msg', 'add_signature_to_sms');

wp_sms_send_request_body

Description: Modify the request body before sending SMS via AJAX (frontend).
Parameters:

  • $requestBody (array) - The request body array

Example:

function modify_sms_request($requestBody) {
    // Add custom data to request
    $requestBody['custom_field'] = 'custom_value';
    return $requestBody;
}
add_filter('wp_sms_send_request_body', 'modify_sms_request');

Subscriber Management Hooks

Actions

wp_sms_add_subscriber

Description: Fired when a new subscriber is added to the newsletter.
Parameters:

  • $name (string) - Subscriber name
  • $mobile (string) - Subscriber mobile number
  • $status (int) - Subscription status (0 = inactive, 1 = active)
  • $id (int) - Subscriber ID in database

Example:

function welcome_new_subscriber($name, $mobile, $status, $id) {
    if ($status == 1) {
        // Send welcome SMS to new active subscriber
        $message = "Welcome {$name}! Thank you for subscribing to our newsletter.";
        wp_sms_send($mobile, $message);
    }
}
add_action('wp_sms_add_subscriber', 'welcome_new_subscriber', 10, 4);

wp_sms_verify_subscriber

Description: Fired when a subscriber verifies their subscription.
Parameters:

  • $name (string) - Subscriber name
  • $mobile (string) - Subscriber mobile number
  • $status (int) - Subscription status (always 1 for verified)
  • $id (int) - Subscriber ID in database

Example:

function send_verification_confirmation($name, $mobile, $status, $id) {
    $message = "Hi {$name}, your subscription has been verified successfully!";
    wp_sms_send($mobile, $message);
}
add_action('wp_sms_verify_subscriber', 'send_verification_confirmation', 10, 4);

wp_sms_update_subscriber

Description: Fired when a subscriber is updated.
Parameters:

  • $result (mixed) - Update result

Example:

function log_subscriber_update($result) {
    error_log('Subscriber updated: ' . print_r($result, true));
}
add_action('wp_sms_update_subscriber', 'log_subscriber_update');

wp_sms_delete_subscriber

Description: Fired when a subscriber is deleted.
Parameters:

  • $deleted_rows (int) - Number of deleted rows

Example:

function log_subscriber_deletion($deleted_rows) {
    error_log("Deleted {$deleted_rows} subscriber(s)");
}
add_action('wp_sms_delete_subscriber', 'log_subscriber_deletion');

wp_sms_number_unsubscribed_through_url

Description: Fired when a subscriber unsubscribes via URL.
Parameters:

  • $number (string) - The unsubscribed mobile number

Example:

function track_unsubscribe($number) {
    // Track unsubscribe analytics
    update_option('total_unsubscribes', get_option('total_unsubscribes', 0) + 1);
}
add_action('wp_sms_number_unsubscribed_through_url', 'track_unsubscribe');

Filters

wpsms_welcome_sms_message

Description: Modify the welcome SMS message sent to new subscribers.
Parameters:

  • $message (string) - The welcome message
  • $mobile (string) - Subscriber mobile number

Example:

function customize_welcome_message($message, $mobile) {
    // Add subscriber's name to welcome message
    $subscriber = get_subscriber_by_mobile($mobile);
    if ($subscriber) {
        return str_replace('[name]', $subscriber->name, $message);
    }
    return $message;
}
add_filter('wpsms_welcome_sms_message', 'customize_welcome_message', 10, 2);

wpsms_unsubscribe_query_string

Description: Modify the query string parameter for unsubscribe URLs.
Parameters:

  • $query_string (string) - The query string parameter (default: 'wpsms_unsubscribe')

Example:

function change_unsubscribe_param($query_string) {
    return 'unsubscribe_sms';
}
add_filter('wpsms_unsubscribe_query_string', 'change_unsubscribe_param');

wpsms_unsubscribe_csrf_enabled

Description: Control whether CSRF protection is enabled for unsubscribe URLs.
Parameters:

  • $enabled (bool) - Whether CSRF is enabled (default: true)

Example:

function disable_unsubscribe_csrf($enabled) {
    // Disable CSRF for custom implementation
    return false;
}
add_filter('wpsms_unsubscribe_csrf_enabled', 'disable_unsubscribe_csrf');

Gateway Hooks

Filters

wpsms_gateway_list

Description: Modify the list of available SMS gateways.
Parameters:

  • $gateways (array) - Array of gateway classes

Example:

function add_custom_gateway($gateways) {
    $gateways['custom'] = 'CustomGateway';
    return $gateways;
}
add_filter('wpsms_gateway_list', 'add_custom_gateway');

wp_sms_gateway_settings

Description: Modify gateway settings configuration.
Parameters:

  • $filter (array) - Gateway settings array

Example:

function modify_gateway_settings($filter) {
    // Modify gateway settings based on conditions
    return $filter;
}
add_filter('wp_sms_gateway_settings', 'modify_gateway_settings');

Admin Interface Hooks

Actions

wp_sms_form_send_to_select_option

Description: Add custom options to the "Send To" dropdown in admin SMS form.
Parameters:

  • $smsObject (object) - SMS object
  • $proIsActive (bool) - Whether pro version is active

Example:

function add_custom_send_to_option($smsObject, $proIsActive) {
    echo '<option value="custom_group">Custom Group</option>';
}
add_action('wp_sms_form_send_to_select_option', 'add_custom_send_to_option', 10, 2);

wp_sms_form_send_to_value

Description: Add custom fields to the "Send To" value section in admin SMS form.
Parameters:

  • $smsObject (object) - SMS object
  • $proIsActive (bool) - Whether pro version is active

Example:

function add_custom_send_to_field($smsObject, $proIsActive) {
    echo '<div class="wpsms-value wpsms-custom-field">Custom Field HTML</div>';
}
add_action('wp_sms_form_send_to_value', 'add_custom_send_to_field', 10, 2);

wp_sms_after_admin_page_title

Description: Add content after the admin page title.
Parameters: None

Example:

function add_admin_page_notice() {
    echo '<div class="notice notice-info"><p>Custom admin notice here.</p></div>';
}
add_action('wp_sms_after_admin_page_title', 'add_admin_page_notice');

Filters

wp_sms_send_sms_page_content

Description: Modify the content of the Send SMS admin page.
Parameters:

  • $content (string) - The page content
  • $args (array) - Page arguments

Example:

function customize_send_sms_page($content, $args) {
    // Add custom content to send SMS page
    $custom_content = '<div class="custom-section">Custom content</div>';
    return $custom_content . $content;
}
add_filter('wp_sms_send_sms_page_content', 'customize_send_sms_page', 10, 2);

wp_sms_enable_footer_text

Description: Control whether footer text is displayed in admin.
Parameters:

  • $enabled (bool) - Whether footer text is enabled (default: true)

Example:

function disable_admin_footer_text($enabled) {
    return false;
}
add_filter('wp_sms_enable_footer_text', 'disable_admin_footer_text');

wp_sms_enable_footer_logo

Description: Control whether footer logo is displayed in admin.
Parameters:

  • $enabled (bool) - Whether footer logo is enabled (default: true)

Example:

function disable_admin_footer_logo($enabled) {
    return false;
}
add_filter('wp_sms_enable_footer_logo', 'disable_admin_footer_logo');

wp_sms_header_url

Description: Modify the header logo URL in admin.
Parameters:

  • $url (string) - The header logo URL

Example:

function custom_header_logo($url) {
    return 'https://example.com/custom-logo.svg';
}
add_filter('wp_sms_header_url', 'custom_header_logo');

wp_sms_enable_upgrade_to_bundle

Description: Control whether upgrade to bundle options are displayed.
Parameters:

  • $enabled (bool) - Whether upgrade options are enabled (default: true)

Example:

function hide_upgrade_options($enabled) {
    return false;
}
add_filter('wp_sms_enable_upgrade_to_bundle', 'hide_upgrade_options');

wp_sms_enable_help_icon

Description: Control whether help icon is displayed in admin header.
Parameters:

  • $enabled (bool) - Whether help icon is enabled (default: true)

Example:

function hide_help_icon($enabled) {
    return false;
}
add_filter('wp_sms_enable_help_icon', 'hide_help_icon');

wp_sms_enable_header_addons_menu

Description: Control whether addons menu is displayed in admin header.
Parameters:

  • $enabled (bool) - Whether addons menu is enabled (default: true)

Example:

function hide_addons_menu($enabled) {
    return false;
}
add_filter('wp_sms_enable_header_addons_menu', 'hide_addons_menu');

wp_sms_stats_widget_data

Description: Modify the stats widget data for admin dashboard.
Parameters:

  • $data (array) - Stats widget data

Example:

function add_custom_stats($data) {
    $data['custom_stat'] = 'Custom value';
    return $data;
}
add_filter('wp_sms_stats_widget_data', 'add_custom_stats');

wp_sms_admin_menu_list

Description: Modify the admin menu list.
Parameters:

  • $menu_list (array) - Admin menu items

Example:

function add_custom_admin_menu($menu_list) {
    $menu_list['custom_page'] = 'Custom Page';
    return $menu_list;
}
add_filter('wp_sms_admin_menu_list', 'add_custom_admin_menu');

Notification Hooks

Filters

wp_sms_output_variables

Description: Modify the available variables for SMS notifications.
Parameters:

  • $variables (array) - Available variables
  • $message (string) - The message template

Example:

function add_custom_variables($variables, $message) {
    $variables['%custom_var%'] = 'Custom Value';
    return $variables;
}
add_filter('wp_sms_output_variables', 'add_custom_variables', 10, 2);

wp_sms_output_variables_message

Description: Modify the final message after variable replacement.
Parameters:

  • $finalMessage (string) - The final message
  • $message (string) - Original message template
  • $variables (array) - Available variables

Example:

function finalize_message($finalMessage, $message, $variables) {
    // Apply final formatting or validation
    return trim($finalMessage);
}
add_filter('wp_sms_output_variables_message', 'finalize_message', 10, 3);

wp_sms_admin_notify_registration

Description: Modify admin notification recipients for new user registration.
Parameters:

  • $recipients (array) - Array of admin mobile numbers

Example:

function add_additional_admin_notification($recipients) {
    $recipients[] = '+1234567890'; // Additional admin number
    return $recipients;
}
add_filter('wp_sms_admin_notify_registration', 'add_additional_admin_notification');

Webhook Hooks

Actions

wp_sms_two_new_incoming_message

Description: Fired when a new incoming SMS is received (Two-Way SMS).
Parameters:

  • $incomingMessage (object) - Incoming message object

Example:

function handle_incoming_sms($incomingMessage) {
    // Process incoming SMS
    error_log('Incoming SMS from: ' . $incomingMessage->sender_number);
    error_log('Message: ' . $incomingMessage->text);
}
add_action('wp_sms_two_new_incoming_message', 'handle_incoming_sms');

User Management Hooks

Filters

wp_sms_registration_username

Description: Modify the username generated for phone-based user registration.
Parameters:

  • $username (string) - Generated username
  • $mobileNumber (string) - Mobile number

Example:

function customize_registration_username($username, $mobileNumber) {
    // Add custom prefix
    return 'user_' . $username;
}
add_filter('wp_sms_registration_username', 'customize_registration_username', 10, 2);

wp_sms_registration_email

Description: Modify the email generated for phone-based user registration.
Parameters:

  • $email (string) - Generated email address
  • $mobileNumber (string) - Mobile number

Example:

function customize_registration_email($email, $mobileNumber) {
    // Use custom domain
    return str_replace('@example.com', '@mysite.com', $email);
}
add_filter('wp_sms_registration_email', 'customize_registration_email', 10, 2);

wp_sms_user_id

Description: Modify the user ID for SMS operations.
Parameters:

  • $userId (int) - User ID

Example:

function get_current_user_for_sms($userId) {
    // Always use current logged-in user
    return get_current_user_id();
}
add_filter('wp_sms_user_id', 'get_current_user_for_sms');

OTP and Authentication Hooks

Actions

wp_sms_otp_generated

Description: Fired when an OTP (One-Time Password) is generated.
Parameters:

  • $code (string) - Generated OTP code
  • $phoneNumber (string) - Phone number
  • $agent (string) - User agent

Example:

function log_otp_generation($code, $phoneNumber, $agent) {
    // Log OTP generation for security
    error_log("OTP generated for {$phoneNumber}: {$code}");
}
add_action('wp_sms_otp_generated', 'log_otp_generation', 10, 3);

Report and Logging Hooks

Actions

wp_sms_before_report_email

Description: Fired before sending email reports.
Parameters:

  • $reportData (array) - Report data
  • $content (string) - Email content

Example:

function modify_report_email($reportData, $content) {
    // Add custom data to report
    $reportData['custom_metric'] = get_custom_metric();
}
add_action('wp_sms_before_report_email', 'modify_report_email', 10, 2);

wp_sms_log_after_save

Description: Fired after SMS log entry is saved.
Parameters:

  • $result (mixed) - Log save result
  • $sender (string) - Sender number
  • $message (string) - Message content
  • $to (array) - Recipients
  • $response (mixed) - Gateway response
  • $status (string) - Send status
  • $media (array) - Media URLs (if any)

Example:

function custom_sms_logging($result, $sender, $message, $to, $response, $status, $media) {
    // Custom logging logic
    error_log("SMS logged: {$sender} -> " . implode(',', $to) . " Status: {$status}");
}
add_action('wp_sms_log_after_save', 'custom_sms_logging', 10, 7);

wp_sms_before_register_notice

Description: Fired before registering admin notices.
Parameters:

  • $noticeManager (object) - Notice manager instance

Example:

function before_notice_registration($noticeManager) {
    // Add custom notices or modify existing ones
}
add_action('wp_sms_before_register_notice', 'before_notice_registration');

Template and Display Hooks

Filters

wp_sms_mobile_number_validity

Description: Modify mobile number validation result.
Parameters:

  • $valid (bool) - Whether number is valid
  • $mobileNumber (string) - Mobile number to validate

Example:

function custom_mobile_validation($valid, $mobileNumber) {
    // Custom validation logic
    if (strpos($mobileNumber, '999') === 0) {
        return false; // Block test numbers
    }
    return $valid;
}
add_filter('wp_sms_mobile_number_validity', 'custom_mobile_validation', 10, 2);

wp_sms_sanitize_mobile_number

Description: Modify mobile number sanitization.
Parameters:

  • $mobile (string) - Sanitized mobile number

Example:

function custom_mobile_sanitization($mobile) {
    // Remove specific characters
    return str_replace(['(', ')', '-'], '', $mobile);
}
add_filter('wp_sms_sanitize_mobile_number', 'custom_mobile_sanitization');

Request and API Hooks

Filters

wp_sms_request_arguments

Description: Modify HTTP request arguments for API calls.
Parameters:

  • $arguments (array) - Request arguments

Example:

function add_request_timeout($arguments) {
    $arguments['timeout'] = 30; // Increase timeout
    return $arguments;
}
add_filter('wp_sms_request_arguments', 'add_request_timeout');

wp_sms_request_params

Description: Modify request parameters for API calls.
Parameters:

  • $params (array) - Request parameters

Example:

function add_custom_params($params) {
    $params['custom_header'] = 'custom_value';
    return $params;
}
add_filter('wp_sms_request_params', 'add_custom_params');

Utility and Helper Hooks

Filters

wp_sms_mobile_numbers_query_args

Description: Modify query arguments for fetching mobile numbers from users.
Parameters:

  • $args (array) - WP_User_Query arguments

Example:

function filter_mobile_numbers_query($args) {
    // Only get users with specific role
    $args['role'] = 'subscriber';
    return $args;
}
add_filter('wp_sms_mobile_numbers_query_args', 'filter_mobile_numbers_query');

wp_sms_wc_mobile_numbers_query_args

Description: Modify query arguments for fetching mobile numbers from WooCommerce customers.
Parameters:

  • $args (array) - Query arguments

Example:

function filter_wc_mobile_query($args) {
    // Add custom meta query
    $args['meta_query'][] = [
        'key' => 'customer_status',
        'value' => 'active',
        'compare' => '='
    ];
    return $args;
}
add_filter('wp_sms_wc_mobile_numbers_query_args', 'filter_wc_mobile_query');

Usage Examples

Complete SMS Workflow Example

// 1. Modify SMS content before sending
function add_company_signature($msg) {
    return $msg . "\n\nBest regards,\nYour Company";
}
add_filter('wp_sms_msg', 'add_company_signature');

// 2. Track successful sends
function track_sms_sends($response) {
    $count = get_option('total_sms_sent', 0);
    update_option('total_sms_sent', $count + 1);
}
add_action('wp_sms_send', 'track_sms_sends');

// 3. Handle new subscribers
function welcome_subscriber($name, $mobile, $status, $id) {
    if ($status == 1) {
        $message = "Welcome {$name}! You're now subscribed to our updates.";
        wp_sms_send($mobile, $message);
    }
}
add_action('wp_sms_add_subscriber', 'welcome_subscriber', 10, 4);

Custom Gateway Integration Example

// Add custom gateway to the list
function register_custom_gateway($gateways) {
    $gateways['custom_api'] = 'CustomAPIGateway';
    return $gateways;
}
add_filter('wpsms_gateway_list', 'register_custom_gateway');

// Modify gateway settings
function custom_gateway_settings($settings) {
    // Add custom settings for your gateway
    return $settings;
}
add_filter('wp_sms_gateway_settings', 'custom_gateway_settings');

Best Practices

  1. Hook Priority: Use appropriate priority values (10, 20, etc.) to control execution order
  2. Parameter Count: Always specify the correct number of parameters in add_action() and add_filter()
  3. Error Handling: Implement proper error handling in your hook callbacks
  4. Performance: Avoid heavy operations in frequently called hooks like wp_sms_from, wp_sms_to, wp_sms_msg
  5. Security: Validate and sanitize data in your hook callbacks
  6. Documentation: Document your custom hooks for other developers

Version Compatibility

This documentation is based on WP-SMS version 7.0.3. Some hooks may not be available in older versions, and new hooks may be added in future versions. Always check the plugin changelog for updates.


Support

For more information about WP-SMS plugin and its hooks, visit:


Last updated: December 2024

Clone this wiki locally