gform_twilio_set_to_phone_number

gform_twilio_set_to_phone_number

DescriptionUsageParametersExample1. Override all feeds2. Override specific feedPlacementSource Code

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 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
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
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.

發表回覆

您的郵箱地址不會被公開。 必填項已用 * 標註