gform_twilio_set_to_phone_number

Description

This filter can be used to modify the TO number before the SMS is sent to Twilio.

This hook has been deprecated since Twilio version 2.4. Please use gform_twilio_message instead.

Usage

The filter which would run for all Twilio feeds can be used like so:

add_filter( 'gform_twilio_set_to_phone_number', 'your_function_name', 10, 3 );

Parameters

  • $to stringThe number the SMS will be sent TO. Formatted with a ‘+’ and country code e.g. +17571234567 (E.164 format).
  • $entry Entry Object

    The Entry which is currently being processed.

  • $feed_id integer

    The ID of the Feed Object which is currently being processed. Available since v2.1.

Example

1. Override all feeds

The following example shows how you can change the TO number for all Twilio feeds.

add_filter( 'gform_twilio_set_to_phone_number', 'change_to_number', 10, 2 );

function change_to_number( $to, $entry ) {
    // Grab phone number out of field 2, sample format "+17571234567"
    return ! rgblank( $entry['2'] ) ? $entry['2'] : $to;
}

2. Override specific feed

The following example shows how you can change the TO number for a specific Twilio feed.

add_filter( 'gform_twilio_set_to_phone_number', function ( $to, $entry, $feed_id ) {
    $feed = gf_twilio()->get_feed( $feed_id );

    if ( rgars( $feed, 'meta/feedName' ) == 'your feed name' ) {
        // Grab phone number out of field 2, sample format "+17571234567"
        return ! rgblank( $entry['2'] ) ? $entry['2'] : $to;
    }

    return $to;
}, 10, 3 );

Placement

This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.

See also the PHP section in this article: Where Do I Put This Code?

Source Code

This filter is located in GFTwilio::send_sms() in class-gf-twilio.php.