gform_merge_tag_data

gform_merge_tag_data

DescriptionUsageParametersExamples1. Provide Custom Data2. Entry creatorChangelogSource Code

Description
Use this filter to add, remove or modify the data that will be used to replace merge tags found in the specified string. This includes the $entry data used to replace field-based merge tags. Note: this filter is not triggered during form display, it is intended for implementing custom merge tags which are used in notifications, confirmations, and feed add-ons.
Usage
The following would apply to all forms.
add_filter( 'gform_merge_tag_data', 'your_function_name', 10, 4 );

Parameters

$data array
Data that will be used to replace merge tags. Array keys represent available merge tags. Values can be accessed by specifying a property: {entry:date_created}. Value can be an array of data or a callable function.
$data['customTag'] = 'my_func_to_retrieve_data';
$data['anotherTag'] = array(
'testKey' => 'Test Value'
);
Callable functions will be passed the current $entry and $form objects.
function my_func_to_retrieve_data( $entry, $form ) {
return array(
'key1' => 'value1',
'key2' => 'value2'
);
}
This data can be accessed with merge tags by specifying the data key and the desired property. Examples:

{customTag:key1} outputs 「value1」
{anotherTag:testKey} outputs 「Test Value」

$text string
The current text that will be parsed for merge tags.

$form Form Object
The current form object.

$entry Entry Object
The current form object.

Examples
1. Provide Custom Data
add_filter( 'gform_merge_tag_data', 'my_custom_merge_tag_data', 10, 4 );
function my_custom_merge_tag_data( $data, $text, $form, $entry ) {
$data['myCustomTag'] = array(
'key1' => 'Value One',
'key2' => 'Value Two'
);
return $data;
}

2. Entry creator
This example shows how to add a {created_by} merge tag e.g. {created_by:roles} to return a comma separated string containing the roles assigned to the user who created the entry.
add_filter( 'gform_merge_tag_data', function ( $data, $text, $form, $entry ) {
$data['created_by'] = array();
if ( ! empty( $entry['created_by'] ) ) {
$user = new WP_User( $entry['created_by'] );
$data['created_by'] = get_object_vars( $user->data );
$data['created_by']['first_name'] = $user->get( 'first_name' );
$data['created_by']['last_name'] = $user->get( 'last_name' );
$data['created_by']['roles'] = implode( ', ', $user->roles );
}

return $data;
}, 10, 4 );

Changelog

2.1.1.11
Added the $entry parameter.
2.0
Introduced.

Source Code
This filter is located in GFCommon::replace_variables() in common.php.

gform_menu_position

gform_menu_position

DescriptionUsageParametersExamplesSource Code

Description
Modify the position the Gravity Forms menu should appear in the WordPress admin menu.
Usage
1add_filter( 'gform_menu_position', 'my_custom_function', 10, 1 );
Parameters

$position integer
Default value 『16.9』, Position at which to output the Gravity Forms』 「Forms」 menu in the WordPress admin menu.

Examples
In this example we demonstrate how to move the Gravity Forms』 「Forms」 menu in the WordPress admin menu below the 「Comments」 menu item.
1234add_filter( 'gform_menu_position', 'my_gform_menu_position' );function my_gform_menu_position( $position ) {    return 50;}
Source Code
This filter is located in GFForms::create_menu() in gravityforms.php

gform_media_upload_path

gform_media_upload_path

DescriptionUsageParametersExamples1. Log the current path2. Change the path and urlPlacementSource CodeSince

Description

This filter can be used to change the location where files uploaded using the Post Image field are copied to when the post is created.

Usage

The following would apply to all forms.

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

To limit the scope of your function to a specific form, append the form id to the end of the hook name. (format: gform_media_upload_path_FORMID)

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

Parameters

$upload_dir array
The upload directory path and url to be filtered.

$upload_dir[『path』] string
Full physical path to the folder.

$upload_dir[『url』] string
Full URL to the folder.

$form_id integer
The ID of the form currently being processed.

$post_id integer
The ID of the post created from the entry currently being processed.

Examples

1. Log the current path

You can use this example with logging enabled to find out what the current path is before using the next example to change the path.

add_filter( 'gform_media_upload_path', function ( $upload_dir, $form_id ) {
GFCommon::log_debug( "gform_media_upload_path(): upload_dir for form #{$form_id} => " . print_r( $upload_dir, true ) );

return $path_info;
}, 1, 2 );

2. Change the path and url

This example changes the upload path and url for the File Upload field.

add_filter( 'gform_media_upload_path', 'change_media_upload_path', 10, 3 );
function change_media_upload_path( $upload_dir, $form_id, $post_id ) {
$upload_dir['path'] = '/home/public_html/yourdomainfolder/new/path/';
$upload_dir['url'] = 'http://yourdomainhere.com/new/path/';

return $upload_dir;
}

Placement

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

Source Code

This filter is located in GFFormsModel::copy_post_image() in forms_model.php

Since

This filter was added in Gravity Forms 1.9.14.19.

gform_max_async_feed_attempts

gform_max_async_feed_attempts

DescriptionUsageParametersExamplesPlacementSinceSource Code

Description
Allows the number of retries to be modified before the feed is abandoned.
Usage
add_filter( 'gform_max_async_feed_attempts', 'your_filter_name', 10, 5 );

Parameters

$max_attempts int
The maximum number of retries allowed. The default is 1.

$form Form Object
The form object.

$entry Entry Object
The entry object.

$addon_slug string
The add-on slug.

$feed Feed Object
The feed object.

Examples
add_filter( 'gform_max_async_feed_attempts', 'filter_gform_max_async_feed_attempts', 10, 5 );
function filter_gform_max_async_feed_attempts( $max_attempts, $form, $entry, $addon_slug, $feed ) {
if ( $addon_slug == 'gravityformswebhooks' ) {
$max_attempts = 2;
}

return $max_attempts;
}

Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in Gravity Forms 2.4.
Source Code
This filter is located in GF_Feed_Processor::task() in class-gf-feed-processor.php.

gform_mailgun_send_email_failed

gform_mailgun_send_email_failed

DescriptionUsageParametersExamplesPlacementSinceSource Code

Description
The gform_mailgun_send_email_failed action hook is triggerd when MailGun API reports it is unable to send the email.
Usage
add_action( 'gform_mailgun_send_email_failed', 'my_function', 10, 6 );

Parameters

$error_message string
The error message returned by the API.

$mailgun_email array
The Mailgun email arguments.

$email array
The original email details.

$message_format string
The message format, html or text.

$notification array
An array of properties which make up a notification object. See Notifications Object for possible properties.

$entry array
The entry object.

Examples
function my_function( $error_message, $mailgun_email, $email, $message_format, $notification, $entry ) {
//Do something here
}
add_action( 'gform_mailgun_send_email_failed', 'my_function', 10, 6 );

Placement
This code should be placed in the functions.php file of your active theme or a custom functions plugin.
Since
This filter was added in Mailgun version 1.2.
Source Code
This filter is located in class-gf-mailgun.php.

gform_mailgun_email

gform_mailgun_email

DescriptionUsageParametersPlacementSinceSource Code

Description
Allows modification of the email arguments which are passed to the Mailgun API.
Usage
add_filter( 'gform_mailgun_email', function( $mailgun_email, $email, $message_format, $notification, $entry ) {
$mailgun_email['h:x-mailgun-native-send'] = false;
return $mailgun_email;
}, 10, 5 );

Parameters

$mailgun_email array
The Mailgun email arguments.

$email array
The original email details.

$message_format array
The message format, html or text.

$notification array
The Notification object.

$entry array
The current Entry object.

Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in Mailgun version 1.0.
Source Code
This filter is located in class-gf-mailgun.php.

gform_mailchimp_subscription

gform_mailchimp_subscription

DescriptionUsageParametersExamples1. If a subscriber already exists, set them as subscribed2. Set the signup timestamp2. Set the Subscriber languageSinceSource Code

Description
The 「gform_mailchimp_subscription」 filter in Gravity Forms Mailchimp Add-On modifies the subscription object before it is executed.
Usage
1add_filter( 'gform_mailchimp_subscription', 'my_function', 10, 6 );

Parameters

$subscription array
Subscription arguments. See the Mailchimp API documentation for a full list of supported properties.

$list_id string
Mailchimp list ID.

$form array
The form object.

$entry array
The entry object.

$feed array
The feed object.

$member array
The existing member object. False if member does not currently exist in Mailchimp.

Examples
1. If a subscriber already exists, set them as subscribed
Doing this will avoid the double opt-in for existing members.
123456789add_filter( 'gform_mailchimp_subscription', 'update_existing', 10, 6 ); function update_existing( $subscription, $list_id, $form, $entry, $feed, $member ) {    if ( $member ) {        $subscription['status'] = 'subscribed';    }     return $subscription;}
2. Set the signup timestamp
1234567add_filter( 'gform_mailchimp_subscription', function( $subscription, $list_id, $form, $entry, $feed, $member ) {    if ( ! $member ) {        $subscription['timestamp_signup'] = date( DATE_ATOM );    }     return $subscription;}, 10, 6 );
2. Set the Subscriber language
The follow example uses the ICL_LANGUAGE_CODE constant provided by the WPML plugin to set the subscriber language.
1234567891011add_filter( 'gform_mailchimp_subscription', 'gf_set_subscriber_language' );function gf_set_subscriber_language( $subscription ) {    GFCommon::log_debug( __METHOD__ . '(): running.' );    // Use the language code provided by WPML to set the subscriber language.    if ( defined( 'ICL_LANGUAGE_CODE' ) ) {        GFCommon::log_debug( __METHOD__ . '(): Setting value for ICL_LANGUAGE_CODE as subscriber language: ' . ICL_LANGUAGE_CODE );        $subscription['language'] = ICL_LANGUAGE_CODE;    }     return $subscription;}
Since
Added existing member object as $member parameter in 4.1.9.
Source Code
This filter is located in includes/addon/class-gf-mailchimp.php.

gform_mailchimp_request_args

gform_mailchimp_request_args

DescriptionUsageParametersExamplesPlacementSource Code

Description
The 「gform_mailchimp_request_args」 filter in the Gravity Forms Mailchimp Add-On allows the request arguments to be modified before sent to Mailchimp.
Usage
add_filter( 'gform_mailchimp_request_args', 'your_function_name', 10, 2 );

Parameters

$args array
The request arguments sent to Mailchimp.

$path string
The request path.

Examples
add_filter( 'gform_mailchimp_request_args', 'change_request_args', 10, 2 );
function change_request_args( $args, $path ){
//change method
$args['method'] = 'POST';
return $args;
}

Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GF_Mail_Chimp::process_request() in gravityformsmailchimp/includes/class-gf-mailchimp-api.php.

gform_mailchimp_override_empty_fields

gform_mailchimp_override_empty_fields

DescriptionUsageParametersExamples1. Override all feeds2. Override specific feedPlacementSource Code

Description
This filter can be used to prevent empty form fields erasing values already stored in the mapped Mailchimp MMERGE fields when updating an existing subscriber.
Usage
The filter which would run for all Mailchimp feeds can be used like so:
add_filter( 'gform_mailchimp_override_empty_fields', 'your_function_name', 10, 4 );

To target a specific form append the form id to the hook name. (format: gform_mailchimp_override_empty_fields_FORMID)
add_filter( 'gform_mailchimp_override_empty_fields_10', 'your_function_name', 10, 4 );

Parameters

$override boolean
The default is true.

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

$entry Entry Object
The entry which is currently being processed.

$feed Feed Object
The feed which is currently being processed.

Examples
1. Override all feeds
The following example shows how you can apply the filter to all Mailchimp feeds.
add_filter( 'gform_mailchimp_override_empty_fields', '__return_false' );

2. Override specific feed
The following example shows how you can target a specific Mailchimp feed.
add_filter( 'gform_mailchimp_override_empty_fields', function ( $override, $form, $entry, $feed ) {
$feed_name = rgars( $feed, 'meta/feedName' );

return $feed_name == 'Your feed name' ? false : $override;
}, 10, 4 );

Placement
Your code snippet should be placed in the functions.php file of your active theme.
Source Code
apply_filters( "gform_mailchimp_override_empty_fields_{$form['id']}", apply_filters( 'gform_mailchimp_override_empty_fields', true, $form, $entry, $feed ), $form, $entry, $feed )

This filter is located in GFMailChimp::process_feed() in class-gf-mailchimp.php.

gform_mailchimp_lists_params

gform_mailchimp_lists_params

DescriptionUsageParametersExamples1. Increase limitPlacementSinceSource Code

Description
The 「gform_mailchimp_lists_params」 filter in Gravity Forms Mailchimp Add-On allows the request parameters to be modified when getting Mailchimp lists/audiences.
Usage
add_filter( 'gform_mailchimp_lists_params', 'my_function' );

Parameters

$params array
Contains the parameters being sent.
$params = array( 'start' => 0, 'limit' => 100 );

Examples
1. Increase limit
This example shows how you can increase the maximum number of lists/audiences that can be retrieved.
add_filter( 'gform_mailchimp_lists_params', function ( $params ) {
$params['limit'] = 200;

return $params;
} );

Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in Gravity Forms version 3.0.
Source Code
This filter is located in class-gf-mailchimp.php.