Using Gravity Forms ‘gform_twilio_message’ PHP filter

The gform_twilio_message Gravity Forms PHP filter is used to modify the SMS message arguments before it is sent.

Usage

A generic example of how to use the filter:

add_filter('gform_twilio_message', 'your_function_name', 10, 4);

To target a specific form, append the form id to the hook name:

add_filter('gform_twilio_message_1', 'your_function_name', 10, 4);

To target a specific form’s feed, append the form id and feed id to the hook name:

add_filter('gform_twilio_message_1_1', 'your_function_name', 10, 4);

Parameters

  • $args (array): The arguments for the SMS message. Example: $args = {'to' => '7571234567', 'from' => '7571112222', 'body' => 'This is a test.', 'shorten_url' => '1'};
  • $feed (Feed Object): The Feed object.
  • $entry (Entry Object): The Entry object.
  • $form (Form Object): The Form object.

More information

See Gravity Forms Docs: gform_twilio_message

Examples

Append a string to the message body

This example appends the string ” – TEST!” to the body of the SMS message.

add_filter('gform_twilio_message', 'change_message', 10, 4);

function change_message($args, $feed, $entry, $form) {
    $args['body'] = $args['body'] . ' - TEST!';
    return $args;
}

Change the ‘to’ phone number

This example changes the ‘to’ phone number to ‘1234567890’.

add_filter('gform_twilio_message', 'change_to_phone_number', 10, 4);

function change_to_phone_number($args, $feed, $entry, $form) {
    $args['to'] = '1234567890';
    return $args;
}

Change the ‘from’ phone number

This example changes the ‘from’ phone number to ‘0987654321’.

add_filter('gform_twilio_message', 'change_from_phone_number', 10, 4);

function change_from_phone_number($args, $feed, $entry, $form) {
    $args['from'] = '0987654321';
    return $args;
}

Disable URL shortening

This example disables URL shortening in the SMS message.

add_filter('gform_twilio_message', 'disable_url_shortening', 10, 4);

function disable_url_shortening($args, $feed, $entry, $form) {
    $args['shorten_url'] = '0';
    return $args;
}

Conditionally modify the message body

This example appends a string ” – URGENT” to the message body if the form has a field with the label “Urgent” and its value is “Yes”.

add_filter('gform_twilio_message', 'conditionally_modify_message_body', 10, 4);

function conditionally_modify_message_body($args, $feed, $entry, $form) {
    foreach ($form['fields'] as $field) {
        if ($field->label == 'Urgent' && rgar($entry, $field->id)