gform_disable_auto_update

gform_disable_auto_update

DescriptionUsageParametersExampleSource Code

Description
The 「gform_disable_auto_update」 filter allows automatic updates to be turned off in Gravity Forms.
Usage
1add_filter( 'gform_disable_auto_update', __return_true );

Parameters

$disabled bool
Set to 『true』 to disable automatic updates. False to enable them. Defaults to the inverse of the gform_enable_background_updates option.

Example
1add_filter( 'gform_disable_auto_update', __return_true );
Source Code
This action hook is located in gravityforms.php

gform_currency_pre_save_entry

gform_currency_pre_save_entry

DescriptionUsageParametersExamplePlacementSource CodeSince

Description
This filter can be used to override the default currency code before the entry is saved.
Usage
The base filter which would run for all forms would be used like so:
add_filter( 'gform_currency_pre_save_entry', 'your_function_name', 10, 2 );

To target a specific form append the form id to the hook name. (format: gform_currency_pre_save_entry_FORMID)
add_filter( 'gform_currency_pre_save_entry_5', 'your_function_name', 10, 2 );

Parameters

$currency string
The three character ISO currency code to be stored in the entry. Default is value returned by GFCommon::get_currency()

$form Form Object
The form currently being processed.

Example
This example shows how you can override the currency code with a value from a form field.
add_filter( 'gform_currency_pre_save_entry', 'override_currency_code', 10, 2 );
function override_currency_code( $currency, $form ) {

return rgpost( 'input_7' );
}

Placement
This code should be placed in the functions.php file of your active theme.
Source Code
gf_apply_filters( 'gform_currency_pre_save_entry', $form['id'], GFCommon::get_currency(), $form )

This filter is located in GFFormsModel::create_lead and GFFormsModel::save_lead in forms_model.php.
Since
This filter was added in Gravity Forms 1.9.13.26.

gform_delete_entry

gform_delete_entry

DescriptionUsageParametersExamplesDelete PostDelete user signupDelete userSource Code

Description
The 「gform_delete_entry」 action fires right before an entry is deleted and is used to perform actions when an entry is deleted.
Note: This filter replaces the 「gform_delete_lead」 hook.
Usage
add_action( 'gform_delete_entry', 'your_function_name', 10, 1 );

Parameters

$entry_id integer
The ID of the entry that is about to be deleted.

Examples
Delete Post
This example deletes the post associated with the deleted entry.
add_action( 'gform_delete_entry', 'delete_entry_post' );
function delete_entry_post( $entry_id ) {
GFCommon::log_debug( __METHOD__ . '(): running.' );
// Getting entry object.
$entry = GFAPI::get_entry( $entry_id );
// If entry is associated with a post, delete it.
if ( isset( $entry['post_id'] ) ) {
GFCommon::log_debug( __METHOD__ . '(): Deleting post ID ' . $entry['post_id'] );
wp_delete_post( $entry['post_id'] );
}
}

Delete user signup
The following example shows how the record assiocated with an entry can be deleted from the WordPress signups table when the entry is deleted.
add_action( 'gform_delete_entry', function ( $entry_id ) {
if ( ! function_exists( 'gf_user_registration' ) ) {
return;
}

require_once( gf_user_registration()->get_base_path() . '/includes/signups.php' );
GFUserSignups::prep_signups_functionality();
$activation_key = GFUserSignups::get_lead_activation_key( $entry_id );
if ( $activation_key ) {
GFUserSignups::delete_signup( $activation_key );
}
} );

Delete user
The following example shows how the user can be deleted when the entry is deleted.
add_action( 'gform_delete_entry', function ( $entry_id ) {
if ( ! function_exists( 'gf_user_registration' ) ) {
return;
}

$user_id = gf_user_registration()->get_user_by_entry_id( $entry_id, true );
wp_delete_user( $user_id );
} );

Source Code
This filter is located in GFFormsModel::delete_entry() in forms_model.php.

gform_coupons_can_apply_coupon

gform_coupons_can_apply_coupon

DescriptionUsageParametersExamplesRestrict a coupon to a single formLimit a coupon to logged in users onlyPlacementSinceSource Code

Description
This PHP filter allows custom logic to be used to determine if the coupon code can be applied.
Usage
apply_filters( 'gform_coupons_can_apply_coupon', $can_apply, $coupon_code, $existing_coupon_codes, $feed, $form );

Parameters

$can_apply array
The coupon validation result.

$coupon_code string
The coupon code being validated.

$existing_coupon_codes string
The coupon codes which have already been applied.

$feed Feed Object
The feed (configuration) for the coupon code being validated.

$form Form Object
The current form.

Examples
Restrict a coupon to a single form
The following example restricts the usage of a coupon code to a form with id 1.
add_filter( 'gform_coupons_can_apply_coupon', function ( $can_apply, $coupon_code, $existing_coupon_codes, $feed, $form ) {
if ( $form['id'] == 1 && $coupon_code !== 'FREE' ) {
$can_apply['is_valid'] = false;
$can_apply['invalid_reason'] = 'the error message';
}

return $can_apply;
}, 10, 5 );

Limit a coupon to logged in users only
The following example restricts the usage of a coupon code only to logged in users.
add_filter( 'gform_coupons_can_apply_coupon', function ( $can_apply, $coupon_code, $existing_coupon_codes, $feed, $form ) {
if ( is_user_logged_in() === false && $coupon_code === 'TEST' ) {
$can_apply['is_valid'] = false;
$can_apply['invalid_reason'] = 'the error message';
}

return $can_apply;
}, 10, 5 );

Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in Coupons 2.9.
Source Code
This filter is located in apply_coupon_code() in class-gf-coupons.php.

gform_date_min_year

gform_date_min_year

DescriptionUsageParametersExamplesPlacementSource Code

Description
Use this filter to specify the minimum year displayed in the date field』s year drop down and the HTML5 min attribute for the date field』s year input.
Usage
add_filter( 'gform_date_min_year', 'set_min_year' );

Parameters

$min_date string
The minimum date to be filtered. Defaults to 1920.

$form Form Object
Current form object.

$field Field Object
Current field object.

Examples
This example changes the minimum date to 1900.
add_filter( 'gform_date_min_year', 'set_min_year' );
function set_min_year( $min_year ) {
return 1900;
}

This example changes the min date for a specific field on a specific form.
add_filter( 'gform_date_min_year', function ( $min_year, $form, $field ) {

return $form['id'] == 7 && $field->id == 5 ? 2014 : $min_year;
}, 10, 3 );

Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in the following methods in includes/fields/class-gf-field-date.php:

GF_Field_Date::get_field_input()
GF_Field_Date::get_year_dropdown()

gform_disable_custom_field_names_query

gform_disable_custom_field_names_query

DescriptionUsageParametersExamplePlacementSinceSource Code

Description
Allows the postmeta query which retrieves the custom field names (meta keys) to be disabled to help improve editor performance on some sites.
Usage
add_filter( 'gform_disable_custom_field_names_query', 'your_function_name', 10, 1 );

Parameters

$disable_query boolean
Indicates if the custom field names query should be disabled. Default is false.

Example
add_filter( 'gform_disable_custom_field_names_query', 'disable_query', 10, 1 );
function disable_query( $disable_query ){
return true;
}

Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in Gravity Forms version 2.3.4.1.
Source Code
This filter is located in GFFormsModel::get_custom_field_names() in forms_model.php.

gform_currency_setting_message

gform_currency_setting_message

DescriptionUsageParametersExamplesPlacementSource Code

Description
The gform_currency_setting_message action hook is used to add a message after the currency drop down within the Settings page.
Usage
add_action( 'gform_currency_setting_message', 'currency_message' );

Parameters

$message string
The default message. An empty string.

Examples
This example adds a message below the currency drop down.
add_action( 'gform_currency_setting_message', 'currency_message' );
function currency_message() {
esc_html_e( 'US Dollars is the only supported currency by this payment gateway.', 'your_text_domain_here' );
}

Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This action hook was originally located in GFSettings::gravityforms_settings_page() in settings.php. In Gravity Forms 2.5 it was moved to GFSetting::currency_message_callback().

gform_delete_lead

gform_delete_lead

DescriptionUsageParametersExamplesSource Code

Description
Note: This hook has been deprecated and gform_delete_entry should be used instead.
Fires right before an entry is deleted. Use this hook to perform actions when an entry is deleted.
Usage
add_action( 'gform_delete_lead', 'delete_entry_post' );

Parameters

$entry_id integer
The ID of the entry that is about to be deleted.

Examples
This example deletes the post associated with the deleted entry.
add_action( 'gform_delete_lead', 'delete_entry_post' );
function delete_entry_post( $entry_id ) {

//getting entry object
$entry = GFAPI::get_entry( $entry_id );

//if entry is associated with a post, delete it
if ( isset( $entry['post_id'] ) ) {
wp_delete_post( $entry['post_id'] );
}
}

Source Code
This filter is located in GFFormsModel::delete_lead() in forms_model.php.

gform_coupons_discount_amount

gform_coupons_discount_amount

DescriptionUsageJavaScript VersionParametersExamplePlacementSource CodePHP VersionParametersExamplePlacementSource CodeVersion

Description
This filter can be used to modify the coupon discount before it is applied to the form total.
Usage
The gform_coupons_discount_amount filter has both a JavaScript version and a PHP version. Both versions should be used.
The JavaScript version only modifies the coupon discount on the front-end.
gform.addFilter( 'gform_coupons_discount_amount', function( discount, couponType, couponAmount, price, totalDiscount ) {
// do stuff

return discount;
} );

The PHP version modifies the coupon discount during submission, ensuring that the pricing data used to create the entry and used with payment add-ons is updated.
add_filter( 'gform_coupons_discount_amount', function( $discount, $coupon, $price, $entry ) {
// do stuff

return $discount;
}, 10, 4 );

JavaScript Version

Parameters

discount float
The discount amount.

couponType float
The couponAmountType from the Coupons Feed Meta.

couponAmount float
The discount amount from the Coupons Feed Meta.

price float
The form total excluding discounts.

totalDiscount float
The total discount from all currently applied coupons.

Example
This example shows how you can adjust the coupon discount for logged-in users.
gform.addFilter( 'gform_coupons_discount_amount', function( discount, couponType, couponAmount, price, totalDiscount ) {
// you would need to write your own JS-version of is_user_logged_in()
if ( is_user_logged_in() ) {
discount += 5;
}
return discount;
} );

Placement
Your code snippet can be placed in a HTML field on your form or in a theme custom JavaScript file.
Source Code
This filter is located in GetDiscount() in js/coupons.js.
PHP Version

Parameters

$discount float
The discount amount.

$coupon array
Contains the coupon meta which is copied from the Coupons Feed Meta.
array(
'amount' => 100,
'name' => 'test100',
'type' => 'percentage',
'code' => 'TEST100',
'can_stack' => false,
'usage_count' => 2,
);

$price float
The form total excluding discounts.

$entry Entry Object
The current entry.

Example
This example shows how you can adjust the coupon discount for logged-in users.
add_filter( 'gform_coupons_discount_amount', 'add_logged_in_user_bonus_discount', 10, 4 );
function add_logged_in_user_bonus_discount( $discount, $coupon, $price, $entry ) {
if ( is_user_logged_in() ) {
$discount += 5;
}

return $discount;
}

Placement
Your code snippet should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GFCoupons::get_discount() in class-gf-coupons.php.
Version
The $entry parameter was added to the PHP version of the hook in Coupons version 2.6.3.

gform_datepicker_options_pre_init

gform_datepicker_options_pre_init

DescriptionUsageParametersExamples1. Weekends only2. No Weekends3. Datepicker 1 becomes minDate for datepicker 24. Datepicker 1 + 1 month becomes minDate for datepicker 25. Disable specific dates6. Restrict selectable dates to specific ranges7. Disable specific dates and a certain day of the week8. Setting local translations9. Disable past dates10. Disable month and year selection11. Disable specific months12. Force week to start on MondayPlacementSource Code

Description
This filter can be used to modify the options used to initialize a fields datepicker.
The Gravity Forms Datepicker is powered by the jQuery UI Datepicker which is bundled with WordPress. See jQuery UI API Documentation – Datepicker Widget for all the possible options you can use with this filter.
Usage

Parameters

optionsObj Javascript Object
The current datepicker object.
{
yearRange: '-100:+20',
showOn: 'focus',
dateFormat: 'mm/dd/yy',
changeMonth: true,
changeYear: true,
suppressDatePicker: false,
onClose: function () {
element.focus();
var self = this;
this.suppressDatePicker = true;
setTimeout(function () {
self.suppressDatePicker = false;
}, 200);
},
beforeShow: function (input, inst) {
return !this.suppressDatePicker;
}
}

formId integer
The ID of the current form.

fieldId integer
The ID of the current field.

Examples
1. Weekends only
gform.addFilter( 'gform_datepicker_options_pre_init', function( optionsObj, formId, fieldId ) {
if ( formId == 12 && fieldId == 1 ) {
optionsObj.firstDay = 1;
optionsObj.beforeShowDay = function(date) {
var day = date.getDay();
return [(day == 0 || day == 6)];
};
}
return optionsObj;
});

2. No Weekends
gform.addFilter( 'gform_datepicker_options_pre_init', function( optionsObj, formId, fieldId ) {
if ( formId == 12 && fieldId == 6 ) {
optionsObj.firstDay = 1;
optionsObj.beforeShowDay = jQuery.datepicker.noWeekends;
}
return optionsObj;
});

3. Datepicker 1 becomes minDate for datepicker 2
gform.addFilter( 'gform_datepicker_options_pre_init', function( optionsObj, formId, fieldId ) {
if ( formId == 12 && fieldId == 8 ) {
optionsObj.minDate = 0;
optionsObj.onClose = function (dateText, inst) {
jQuery('#input_12_9').datepicker('option', 'minDate', dateText).datepicker('setDate', dateText);
};
}
return optionsObj;
});

4. Datepicker 1 + 1 month becomes minDate for datepicker 2
gform.addFilter( 'gform_datepicker_options_pre_init', function( optionsObj, formId, fieldId ) {
if ( formId == 12 && fieldId == 11 ) {
optionsObj.minDate = 0;
optionsObj.onClose = function (dateText, inst) {
dateText = new Date(dateText);
dateMin = new Date(dateText.getFullYear(), dateText.getMonth() + 1,dateText.getDate());
jQuery('#input_12_12').datepicker('option', 'minDate', dateMin).datepicker('setDate', dateMin);
};
}
return optionsObj;
});

5. Disable specific dates
gform.addFilter( 'gform_datepicker_options_pre_init', function( optionsObj, formId, fieldId ) {
if ( formId == 12 && fieldId == 14 ) {
var disabledDays = ['06/15/2014', '07/01/2014', '07/15/2014'];
optionsObj.beforeShowDay = function(date) {
var checkdate = jQuery.datepicker.formatDate('mm/dd/yy', date);
return [disabledDays.indexOf(checkdate) == -1];
};
}
return optionsObj;
});

6. Restrict selectable dates to specific ranges
gform.addFilter( 'gform_datepicker_options_pre_init', function( optionsObj, formId, fieldId ) {
if ( formId == 12 && fieldId == 16 ) {
var ranges = [
{ start: new Date('06/15/2014'), end: new Date('06/25/2014') },
{ start: new Date('07/15/2014'), end: new Date('07/25/2014') },
{ start: new Date('08/15/2014'), end: new Date('08/25/2014') }
];
optionsObj.beforeShowDay = function(date) {
for ( var i=0; i= ranges[i].start && date <= ranges[i].end ) return [true, '']; } return [false, '']; }; optionsObj.minDate = ranges[0].start; optionsObj.maxDate = ranges[ranges.length -1].end; } return optionsObj; }); 7. Disable specific dates and a certain day of the week gform.addFilter('gform_datepicker_options_pre_init', function (optionsObj, formId, fieldId) { if (formId == 149 && fieldId == 2) { optionsObj.firstDay = 1; optionsObj.beforeShowDay = function (date) { var disabledDays = ['06/15/2015', '06/16/2015', '06/18/2015'], currentDate = jQuery.datepicker.formatDate('mm/dd/yy', date), day = date.getDay(); return [!(disabledDays.indexOf(currentDate) != -1 || day == 3)]; }; } return optionsObj; }); 8. Setting local translations The below example will set the default region to France, which will include translations. Note: This assumes that the translation file is already present and enqueued. See the Translating The Datepicker article. gform.addFilter('gform_datepicker_options_pre_init', function (optionsObj, formId, fieldId) { if (formId == 149 && fieldId == 2) { jQuery.datepicker.regional['fr'] } return optionsObj; }); 9. Disable past dates The snippet below will disable any past date and allow only to select current and future dates. gform.addFilter( 'gform_datepicker_options_pre_init', function( optionsObj, formId, fieldId ) { // Apply to field 2 only if ( fieldId == 2 ) { optionsObj.minDate = 0; } return optionsObj; }); 10. Disable month and year selection gform.addFilter( 'gform_datepicker_options_pre_init', function( optionsObj, formId, fieldId ) { if ( formId == 381 && fieldId == 2 ) { // Update form and field id in this line optionsObj.changeMonth = false; optionsObj.changeYear = false; } return optionsObj; }); 11. Disable specific months The following example will disable date selection for months January, April, and July in a datepicker field with id 1 in a form with id 1744. gform.addFilter( 'gform_datepicker_options_pre_init', function( optionsObj, formId, fieldId ) { if ( formId == 1744 && fieldId == 1 ) { // Months to disable (0 for January, 1 February, etc...) monthsDisabled = [0, 3, 6]; optionsObj.beforeShowDay = function(date) { if (jQuery.inArray(date.getMonth(), monthsDisabled) > -1) {
return [false, ''];
}
return [true, ''];
};
}
return optionsObj;
});

12. Force week to start on Monday
The following example uses the firstDay parameter to force the week to start on Monday.
gform.addFilter( 'gform_datepicker_options_pre_init', function( optionsObj, formId, fieldId ) {
// Sunday is 0, Monday is 1, etc.
optionsObj.firstDay = 1;
return optionsObj;
});

Placement
Your code snippet can be placed in a HTML field on your form or in a theme custom JavaScript file.
Source Code
This filter is located in js/datepicker.js