gform_akismet_enabled

gform_akismet_enabled

DescriptionUsageParametersExamplesDisable globallyDisable for a specific form onlyUsing one function with multiple formsPlacementSource Code

Description
This filter allows default Akismet integration to be disabled globally or per form.
Usage
add_filter( 'gform_akismet_enabled', 'your_function_name', 10, 2 );

To limit the scope of your function to a specific form, append the form id to the end of the hook name. (format: gform_akismet_enabled_FORMID)
add_filter( 'gform_akismet_enabled_6', 'your_function_name', 10, 2 );

Parameters

$is_enabled bool
Defaults to true; return false to disable Akismet.

$form_id int
The ID of the form being processed. Since 2.4.18.5.

Examples
Disable globally
This example will globally disable Akismet integration with Gravity Forms:
add_filter( 'gform_akismet_enabled', '__return_false' );

Disable for a specific form only
This example will disable Akismet integration with Gravity Forms only for form id 1:
add_filter( 'gform_akismet_enabled_1', '__return_false' );

Using one function with multiple forms
add_filter( 'gform_akismet_enabled', function( $is_enabled, $form_id ) {
if ( in_array( $form_id, array( 1, 3, 5 ) ) ) {
$is_enabled = false;
}

return $is_enabled;
}, 10, 2 );

Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GFCommon::akismet_enabled() in common.php.

gform_authorizenet_post_capture

gform_authorizenet_post_capture

DescriptionUsageParametersExamplesPlacementSource Code

Description
Action hook used by Authorize.Net that fires after the payment has been captured.
Usage
add_action( 'gform_authorizenet_post_capture', 'your_function_name', 10, 6 )

Parameters

$is_authorized bool
Indicates if the payment was authorized.

$amount string
The payment amount captured.

$entry Entry Object
The current entry.

$form Form Object
The current form.

$config Feed Object
The feed configuration.

$response object
The capture response from Authorize.Net.

Examples
add_action( 'gform_authorizenet_post_capture', 'notify_of_capture', 10, 6 );
function notify_of_capture( $is_authorized, $amount, $entry, $form, $config, $response ){
GFCommon::send_email( '[email protected]', '[email protected]','','','testing', 'Funds were captured.');
}

Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GFAuthorizeNet::process_capture() in gravityformsauthorizenet/class-gf-authorizenet.php.

gform_after_save_form

gform_after_save_form

DescriptionUsageParametersExamples1. Log form creation/update2. Add default fields on form creation3. Set default notification propertiesSource Code

Description
Use this action hook to perform actions right after a form is created or updated.
Usage
1add_action( 'gform_after_save_form', 'log_form_save', 10, 2 );

Parameters

$form Form Object
Current form.

$is_new bool
True if this is a new form being created. False if this is an existing form being updated.

Examples
1. Log form creation/update
This example adds a log file entry when a form is updated or created.
123456789101112add_action( 'gform_after_save_form', 'log_form_saved', 10, 2 );function log_form_saved( $form, $is_new ) {    $log_file = ABSPATH . '/gf_saved_forms.log';    $f = fopen( $log_file, 'a' );    $user = wp_get_current_user();    if ( $is_new ) {        fwrite( $f, date( 'c' ) . " - Form created by {$user->user_login}. Form ID: {$form["id"]}. n" );    } else {        fwrite( $f, date( 'c' ) . " - Form updated by {$user->user_login}. Form ID: {$form["id"]}. n" );    }    fclose( $f );}
2. Add default fields on form creation
This example shows how you can add some default fields to the form when creating new forms.
12345678910111213141516171819202122add_action( 'gform_after_save_form', 'add_default_fields', 10, 2 );function add_default_fields( $form, $is_new ) {    if ( $is_new ) {        $form['fields'] = array(            array(                'type'         => 'hidden',                'label'        => 'First Name',                'id'           => 1,                'defaultValue' => '{user:first_name}',                'formId'       => $form['id'],            ),            array(                'type'         => 'hidden',                'label'        => 'Email',                'id'           => 2,                'defaultValue' => 'user:user_email',                'formId'       => $form['id'],            ),        );        GFAPI::update_form( $form );    }}
3. Set default notification properties
This example shows how you can set the default notification properties when creating new forms.
123456789101112add_action( 'gform_after_save_form', 'set_default_notification_to', 10, 2 );function set_default_notification_to( $form, $is_new ) {    if ( $is_new ) {        foreach ( $form['notifications'] as &$notification ) {            $notification['to'] = '[email protected]';        }         $form['is_active'] = '1';         GFAPI::update_form( $form );    }}
Source Code
This action hook is located in GFFormDetail::save_form_info() in form_detail.php.

GFORM_AUTO_DB_MIGRATION_DISABLED

GFORM_AUTO_DB_MIGRATION_DISABLED

DescriptionUsagePlacement

Description
If the database schema has been updated, setting this constant to true will prevent entries from being migrated in the background.
Usage
1define( 'GFORM_AUTO_DB_MIGRATION_DISABLED', true );
Placement
This constant should be set in your wp-config.php. See the article Wp Config Options for more details.

gform_authorizenet_amount_pre_authorize

gform_authorizenet_amount_pre_authorize

DescriptionUsageParametersExamplePlacementSource Code

Description
This filter can be used to modify the authorization amount before it is sent to Authorize.net.
Usage
The filter which would run for all 『product and services』 type Authorize.net feeds can be used like so:
1add_filter( 'gform_authorizenet_amount_pre_authorize', 'your_function_name', 10, 6 );

Parameters

$auth_amount float
The authorization amount. Defaults to value of $config[『amount』].

$transaction object
The Authorize.net transaction object.

$form_data Form Data
An associative array containing the form title, billing address, payment amount, setup fee amount, line items created using the submitted pricing field values and any discounts from coupons.

$config Authorize Net Config
The feed which is currently being processed.

$form Form Object
The form which is currently being processed.

$entry Entry Object
The entry which is currently being processed. Since version 2.1.8.

Example
The following example shows how you can override the authorization amount.
12345678add_filter( 'gform_authorizenet_amount_pre_authorize', 'change_amount', 10, 4 );function change_amount( $auth_amount, $transaction, $form_data, $config, $form ) {    if ( $form['id'] == 10 ) {        $auth_amount = 1;    }     return $auth_amount;}
Placement
Your code snippet should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GFAuthorizeNet::authorize() in class-gf-authorizenet.php.

gform_authorizenet_subscription_pre_create

gform_authorizenet_subscription_pre_create

DescriptionUsageParametersExamples1. Change startDate2. Change Trial Period Cycles3. Add a Description4. Set the invoice number4. Use Name field for subscription detailsPlacementSource Code

Description

This filter can be used to modify the subscription object before it is sent to Authorize.net.

Usage

The filter which would run for all 『subscription』 type Authorize.net feeds can be used like so:

add_filter( 'gform_authorizenet_subscription_pre_create', 'your_function_name', 10, 5 );

Parameters

$subscription object
The Authorize.net subscription object.

$form_data Form Data
An associative array containing the form title, billing address, payment amount, setup fee amount, line items created using the submitted pricing field values and any discounts from coupons.

$config Authorize Net Config
The feed which is currently being processed.

$form Form Object
The form which is currently being processed.

$entry Entry Object
The entry which is currently being processed. Since version 2.1.8.

Examples

1. Change startDate

The following example shows how you can set the start date. Please note Authorize.net requires the startDate be in the YYYY-MM-DD format.

add_filter( 'gform_authorizenet_subscription_pre_create', function ( $subscription, $form_data, $config, $form, $entry ) {
if ( $form['id'] != 30 ) { // Update 30 to your form id number
return $subscription;
}

$subscription->startDate = rgar( $entry, '10' );

return $subscription;
}, 10, 5 );

2. Change Trial Period Cycles

The following example shows how you can set the Trial Period Cycles. Please check the following doc page from Authorize.net to understand how they handle Trial periods: What is a Trial Period?

add_filter( 'gform_authorizenet_subscription_pre_create', function ( $subscription, $form_data, $config, $form, $entry ) {
if ( $form['id'] != 30 ) { // Update 30 to your form id number
return $subscription;
}

$subscription->trialOccurrences = 15; // This will set a 15 days trial period if Billing Cycle is using Days
return $subscription;
}, 10, 5 );

3. Add a Description

The following example shows how you can set a description (up to 255 characters) for the subscription being created in a form with id 30. According to Authorize.net API documentation the description will be associated with each payment in the subscription.

add_filter( 'gform_authorizenet_subscription_pre_create', function ( $subscription, $form_data, $config, $form, $entry ) {
if ( $form['id'] != 30 ) { // Update 30 to your form id number
return $subscription;
}

$subscription->orderDescription = 'This is my custom description...';
return $subscription;
}, 10, 5 );

4. Set the invoice number

This example shows how to pass an entry value as the subscription invoice number.

add_filter( 'gform_authorizenet_subscription_pre_create', function ( $subscription, $form_data, $config, $form, $entry ) {
if ( $form['id'] != 1 ) { // Update 1 to your form id number
return $subscription;
}

GFCommon::log_debug( __METHOD__ . '(): Setting custom invoice number.' );

// Update 46 to the id number of the field containing your invoice number
$subscription->orderInvoiceNumber = rgar( $entry, '46' );
return $subscription;
}, 10, 5 );

4. Use Name field for subscription details

This example shows how to use a Name field as source for Authorize.net』s subscription details.

add_filter( 'gform_authorizenet_subscription_pre_create', function ( $subscription, $form_data, $config, $form, $entry ) {
GFCommon::log_debug( __METHOD__ . '(): running.' );
if ( $form['id'] != 1 ) { // Update 1 to your form id number
GFCommon::log_debug( __METHOD__ . '(): Not our desired form, leaving without changes.' );
return $subscription;
}

// Set values for subscription First Name and Last Name from a name field with ID 1.
$subscription->first_name = rgar( $entry, '1.3' );
$subscription->last_name = rgar( $entry, '1.6' );

return $subscription;
}, 10, 5 );

Placement

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

Source Code

This filter is located in GFAuthorizeNet::subscribe() in class-gf-authorizenet.php.

gform_akismet_fields

gform_akismet_fields

DescriptionUsageParametersExamples1. Override the comment_content2. Provide the IP addressPlacementSource Code

Description
Use this filter to specify the fields that are sent to the Akismet anti-spam service.
Usage
add_filter( 'gform_akismet_fields', 'set_akismet_fields', 10, 4 );

You can also target a specific form by adding the form id after the hook name.
add_filter( 'gform_akismet_fields_6', 'set_akismet_fields', 10, 4 );

Parameters

$akismet_fields array
The data to be sent to Akismet, in the following format:
array(
'comment_type' => 'gravity_form',
'comment_author' => 'Author name',
'comment_author_email' => '[email protected]',
'comment_author_url' => 'http://www.someurl.com',
'comment_content' => 'Some text',
'contact_form_subject' => 'Contact Us',
'comment_author_ip' => '127.0.0.1',
'permalink' => 'http://www.someurl.com/contactus',
'user_ip' => '127.0.0.1',
'user_agent' => 'user agent string',
'referrer' => 'http://www.referrer.com',
'blog' => 'http://www.someurl.com',
);

Property
Default Source

comment_author
The first Name type field found on the form

comment_author_email
The first Email type field found on the form

comment_author_url
The first Website type field found on the form

comment_content
The first Paragraph type field found on the form

contact_form_subject
The form title

$form Form Object
The form which created the entry.

$entry Entry Object
The entry being processed.

$action string
The action triggering the Akismet request: submit, spam, or ham. Since version 2.4.18.5.

Examples
1. Override the comment_content
This example overrides the value in the 「comment_content」 Akismet field so that is is pulled from another field. (field ID: 1).
add_filter( 'gform_akismet_fields', 'set_akismet_fields', 10, 3 );
function set_akismet_fields( $akismet_fields, $form, $entry ) {
$akismet_fields['comment_content'] = rgar( $entry, '1' );

return $akismet_fields;
}

2. Provide the IP address
This example shows how you can pass the IP address to Akismet when it has been removed from the entry using the gform_ip_address filter.
add_filter( 'gform_akismet_fields', 'set_akismet_fields', 10, 3 );
function set_akismet_fields( $akismet_fields, $form, $entry ) {
remove_filter( 'gform_ip_address', '__return_empty_string' );
$ip = GFFormsModel::get_ip();
$akismet_fields['comment_author_IP'] = $ip;
$akismet_fields['user_ip'] = preg_replace( '/[^0-9., ]/', '', $ip );

return $akismet_fields;
}

Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GFCommon::get_akismet_fields() in common.php.

gform_after_submission

gform_after_submission

DescriptionUsageParametersExamples1. Update post after its creation2. Perform a custom action after creating posts with the Advanced Post Creation add-on3. Send entry data to third-party4. Access the entry by looping through the form fields5. Create a ticket in WSDesk6. Submit entries to Tripleseat7. Submit entries to SharpSpring8. Create an Events Calendar plugin event9. Check entry spam statusPlacementSource Code

Description

The gform_after_submission action hook is executed at the end of the submission process (after form validation, notification, and entry creation). Use this hook to perform actions after the entry has been created (i.e. feed data to third party applications).

The Entry Object is available to this hook and contains all submitted values.

This hook also runs for entries which are marked as spam. It does not run for submissions which fail the honeypot validation.

Usage

Applies to all forms.

add_action( 'gform_after_submission', 'after_submission', 10, 2 );

Applies to a specific form. In this case, form id 5.

add_action( 'gform_after_submission_5', 'after_submission', 10, 2 );

Parameters

$entry Entry Object The entry that was just created.$form Form Object The current form.

Examples

1. Update post after its creation

This example uses the gform_after_submission hook to change the post content, adding values from submitted fields, including an image field, to the post created as result of the form submission.

add_action( 'gform_after_submission', 'set_post_content', 10, 2 );
function set_post_content( $entry, $form ) {

//getting post
$post = get_post( $entry['post_id'] );

//changing post content
$post->post_content = 'Blender Version:' . rgar( $entry, '7' ) . "

" . rgar( $entry, '13' ) . "
";

//updating post
wp_update_post( $post );
}

2. Perform a custom action after creating posts with the Advanced Post Creation add-on

This example shows how to get the post ids when using the Advanced Post Creation Add-On.

add_action( 'gform_after_submission', 'custom_action_after_apc', 10, 2 );
function custom_action_after_apc( $entry, $form ) {

//if the Advanced Post Creation add-on is used, more than one post may be created for a form submission
//the post ids are stored as an array in the entry meta
$created_posts = gform_get_meta( $entry['id'], 'gravityformsadvancedpostcreation_post_id' );
foreach ( $created_posts as $post )
{
$post_id = $post['post_id'];
// Do your stuff here.
}
}

3. Send entry data to third-party

This example demonstrates a simple approach to posting submitted entry data to a third party application.

Note: The Webhooks Add-On can be used to perform requests like this with little or no coding required. See the Triggering Webhooks On Form Submissions article.

add_action( 'gform_after_submission', 'post_to_third_party', 10, 2 );
function post_to_third_party( $entry, $form ) {

$endpoint_url = 'https://thirdparty.com';
$body = array(
'first_name' => rgar( $entry, '1.3' ),
'last_name' => rgar( $entry, '1.6' ),
'message' => rgar( $entry, '3' ),
);
GFCommon::log_debug( 'gform_after_submission: body => ' . print_r( $body, true ) );

$response = wp_remote_post( $endpoint_url, array( 'body' => $body ) );
GFCommon::log_debug( 'gform_after_submission: response => ' . print_r( $response, true ) );
}

4. Access the entry by looping through the form fields

This example demonstrates a simple approach to accessing the field values in the entry when you don』t know the field ids.

add_action( 'gform_after_submission', 'access_entry_via_field', 10, 2 );
function access_entry_via_field( $entry, $form ) {
foreach ( $form['fields'] as $field ) {
$inputs = $field->get_entry_inputs();
if ( is_array( $inputs ) ) {
foreach ( $inputs as $input ) {
$value = rgar( $entry, (string) $input['id'] );
// do something with the value
}
} else {
$value = rgar( $entry, (string) $field->id );
// do something with the value
}
}
}

5. Create a ticket in WSDesk

See the How to use WSDesk create ticket API with third-party forms and plugins? article for an example showing how to use the gform_after_submission hook to create WSDesk tickets.

See the Creating Tickets in WSDesk using the Webhooks Add-On article if you would prefer not to use custom code.

6. Submit entries to Tripleseat

See the Using the API Lead Form with Gravity Forms in WordPress article by Tripleseat for an example showing how to use the gform_after_submission hook.

7. Submit entries to SharpSpring

See the Integrating Gravity Forms article by SharpSpring for an example showing how to use the gform_after_submission hook, they also have a tool for generating the code snippet for your form.

8. Create an Events Calendar plugin event

This example demonstrates how the gform_after_submission hook and the tribe_create_event function can be used to create an event in the Events Calendar plugin.

add_action( 'gform_after_submission', function ( $entry ) {
if ( ! function_exists( 'tribe_create_event' ) ) {
return;
}

$start_date = rgar( $entry, '4' );
$start_time = rgar( $entry, '5' );
$end_date = rgar( $entry, '6' );
$end_time = rgar( $entry, '7' );

$args = array(
'post_title' => rgar( $entry, '1' ),
'post_content' => rgar( $entry, '2' ),
'EventAllDay' => (bool) rgar( $entry, '3.1' ),
'EventHideFromUpcoming' => (bool) rgar( $entry, '3.2' ),
'EventShowInCalendar' => (bool) rgar( $entry, '3.3' ),
'feature_event' => (bool) rgar( $entry, '3.4' ),
'EventStartDate' => $start_date,
'EventStartTime' => $start_time ? Tribe__Date_Utils::reformat( $start_time, 'H:i:s' ) : null,
'EventEndDate' => $end_date,
'EventEndTime' => $end_time ? Tribe__Date_Utils::reformat( $end_time, 'H:i:s' ) : null,
);

GFCommon::log_debug( 'gform_after_submission: tribe_create_event args => ' . print_r( $args, 1 ) );
$event_id = tribe_create_event( $args );
GFCommon::log_debug( 'gform_after_submission: tribe_create_event result => ' . var_export( $event_id, 1 ) );
} );

9. Check entry spam status

This example shows how you can check if the entry has been marked as spam and prevent the rest of your function from running.

add_action( 'gform_after_submission', 'action_gform_after_submission_spam_check', 10, 2 );
function action_gform_after_submission_spam_check( $entry, $form ) {
if ( rgar( $entry, 'status' ) === 'spam' ) {
return;
}

// The code that you want to run for submissions which aren't spam.
}

Placement

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

Source Code

This action hook is located in GFFormDisplay::process_form() in form_display.php.

gform_autoresponder_email

gform_autoresponder_email

DescriptionUsageParametersExamplesSource Code

Description
This filter is executed before sending the user notification email. It can be used to route the notification to a different email address.

This hook has been deprecated in v.1.7. Please use gform_notification instead.

Usage
Applies to all forms
1add_filter( 'gform_autoresponder_email', 'change_notification_email', 10, 2 );
Applies to a specific form. In this case, form Id 5
1add_filter( 'gform_autoresponder_email_5', 'change_notification_email', 10, 2 );

Parameters

$email string
The email address to be filtered.

$form Form Object
The current form.

Examples
This example uses the gform_autoresponder_email filter to send the user notification to a test email address
12345678910add_filter( 'gform_autoresponder_email', 'change_notification_email', 10, 2 );function change_notification_email( $email, $form ) {     //applying notification routing to form Id 2    if ( $form['id'] != 2 )        return $email;     //creating email list from fields 2 and 3.    return $_POST['input_2'] . ',' . $_POST['input_3'];}
Source Code
This filter is located in GFCommon::prepare_user_notification() in form_display.php