bookmark_bordergform_twilio_set_to_phone_number

Description

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

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 string

    The 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

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;
}

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

Your code snippet should be placed in the functions.php file of your active theme.

Source Code

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