gform_rest_api_capability_get_forms

gform_rest_api_capability_get_forms

DescriptionUsageParametersExamplesPlacementSinceSource Code

Description
Filters the capability required to get form details via the Rest API V2.
Usage
1add_filter( 'gform_rest_api_capability_get_forms', 'your_function_name', 10, 2 );

Parameters

$capability string
The capability required. Defaults to 『gravityforms_edit_forms』.

$request WP_REST_Request
Full data about the request.

Examples
12345add_filter( 'gform_rest_api_capability_get_forms', 'get_get_forms_capability', 10, 2 );function get_get_forms_capability( $capability, $request ) {   return 'my_custom_capability';}
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_REST_Forms_Controller::get_items_permissions_check() in includes/webapi/v2/includes/controllers/class-controller-forms.php
GF_REST_Forms_Controller::get_item_permissions_check() in includes/webapi/v2/includes/controllers/class-controller-forms.php

gform_rest_api_capability_get_feeds

gform_rest_api_capability_get_feeds

DescriptionUsageParametersExamplesPlacementSinceSource Code

Description
Filters the capability required to get feeds via the Rest API V2.
Usage
add_filter( 'gform_rest_api_capability_get_feeds', 'your_function_name', 10, 2 );

Parameters

$capability string
The capability required. Defaults to 『gravityforms_edit_forms』.

$request WP_REST_Request
Full data about the request.

Examples
add_filter( 'gform_rest_api_capability_get_feeds', 'get_rest_api_capability_get_feeds', 10, 2 );

function get_rest_api_capability_get_feeds( $capability, $request )
{
return 'my_custom_capability';
}

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_REST_Feeds_Controller::get_items_permissions_check() in includes/webapi/v2/includes/controllers/class-controller-feeds.php
GF_REST_Form_Feeds_Controller::get_items_permissions_check() in includes/webapi/v2/includes/controllers/class-controller-form-feeds.php

gform_rest_api_capability_get_entries

gform_rest_api_capability_get_entries

DescriptionUsageParametersExamplePlacementSinceSource Code

Description
Filters the capability required to get entries via the Rest API V2.
Usage
1add_filter( 'gform_rest_api_capability_get_entries', 'your_function_name', 10, 2 );

Parameters

$capability string
The capability required. Defaults to 『gravityforms_view_entries』.

$request WP_REST_Request
Full data about the request.

Example
12345add_filter( 'gform_rest_api_capability_get_entries', 'get_get_entries_capability', 10, 2 );function get_get_entries_capability( $capability, $request ) {   return 'my_custom_capability'; }
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_REST_Entries_Controller::get_items_permissions_check() in includes/webapi/v2/includes/controllers/class-controller-entries.php
GF_REST_Form_Entries_Controller::get_items_permissions_check() in includes/webapi/v2/includes/controllers/class-controller-form-entries.php

gform_rest_api_capability_delete_forms

gform_rest_api_capability_delete_forms

DescriptionUsageParametersExamplePlacementSinceSource Code

Description
Filters the capability required to delete forms via the Rest API V2.
Usage
add_filter( 'gform_rest_api_capability_delete_forms', 'your_function_name', 10, 2 );

Parameters

$capability string
The capability required. Defaults to 『gravityforms_delete_forms』.

$request WP_REST_Request
Full data about the request.

Example
add_filter( 'gform_rest_api_capability_delete_forms', 'get_delete_forms_capability', 10, 2 );
function get_delete_forms_capability ( $capability, $request )
{
return 'my_custom_capability';
}

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_REST_Forms_Controller::gform_rest_api_capability_delete_forms() in includes/webapi/v2/includes/controllers/class-controller-forms.php.

gform_rest_api_capability_delete_feeds

gform_rest_api_capability_delete_feeds

DescriptionUsageParametersExamplesPlacementSinceSource Code

Description
Filters the capability required to delete feeds via the Rest API V2.
Usage
add_filter( 'gform_rest_api_capability_delete_feeds', 'your_function_name', 10, 2 );

Parameters

$capability string
The capability required. Defaults to 『gravityforms_edit_forms』.

$request WP_REST_Request
Full data about the request.

Examples
add_filter( 'gform_rest_api_capability_delete_feeds', 'get_rest_api_capability_delete_feeds', 10, 2 );

function get_rest_api_capability_delete_feeds( $capability, $request )
{
return 'my_custom_capability';
}

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_REST_Feeds_Controller::delete_item_permissions_check() in includes/webapi/v2/includes/controllers/class-controller-feeds.php.

gform_rest_api_capability_delete_entries

gform_rest_api_capability_delete_entries

DescriptionUsageParametersExamplesPlacementSinceSource Code

Description
Filters the capability required to delete entries via the Rest API V2.
Usage
add_filter( 'gform_rest_api_capability_delete_entries', 'your_function_name', 10, 2 );

Parameters

$capability string
The capability required. Defaults to 『gravityforms_delete_entries』.

$request WP_REST_Request
Full data about the request.

Examples
add_filter( 'gform_rest_api_capability_delete_entries', 'get_rest_api_capability_delete_entries', 10, 2 );
function get_rest_api_capability_delete_entries ( $capability, $request )
{
return 'my_custom_capability';
}

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_REST_Entries_Controller::delete_item_permissions_check() in includes/webapi/v2/includes/controllers/class-controller-entries.php.

gform_reset_pre_conditional_logic_field_action

gform_reset_pre_conditional_logic_field_action

DescriptionUsageParametersExamples1. Prevent all field values being resetPlacementSource CodeSince

Description
This JavaScript hook can be used to prevent the field value being reset to its default value when hidden by conditional logic on the frontend.
Please note fields which are hidden by conditional logic when the form is submitted will not be saved when the entry is saved.
Usage

Parameters

reset boolean
Determines if the field values should be reset to default when the field is hidden. Default is true.

formId integer
The ID of the current form.

targetId string
The ID selector for the field container (li) in the format #field_{formId}_{fieldId} e.g. #field_10_2

defaultValues string|array
The field default values.

isInit boolean
True when the form is initially displayed, otherwise false.

Examples
1. Prevent all field values being reset
The following example shows how you can prevent the field values being reset to default when the field is hidden by conditional logic.

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/conditional_logic.js
Since
This filter was added in Gravity Forms 2.0.7.1.

gform_required_legend

gform_required_legend

DescriptionUsageParametersExamples1. Use a custom legendPlacementSinceSource Code

Description

The gform_required_legend filter enables the legend displayed at the bottom of the form header, which explains how required fields are indicated, to be overridden.

Usage

add_filter( 'gform_required_legend', 'your_function_name', 10, 2 );

You can also specify this per form by adding the form id after the filter name.

add_filter( 'gform_required_legend_6', 'your_function_name', 10, 2 );

Parameters

$ledend stringThe required indicator legend.$form Form ObjectThe current form object.

Examples

1. Use a custom legend

add_filter( 'gform_required_legend', function( $legend, $form ) {    return 'your custom legend here';}, 10, 2 );

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 Gravity Forms v2.5.

Source Code

This filter is located in GFFormDisplay::get_form() in form_display.php.

gform_require_login_pre_download

gform_require_login_pre_download

DescriptionUsageParametersExamples1. Require login for all forms2. Require login for specific form and field3. Require login for all forms and redirect to login pagePlacementSinceSource Code

Description
By default the real location of an uploaded file is hidden. The download URL will be generated with a security token to prevent guessing or enumeration attacks to discover the location of other files. The gform_require_login_pre_download filter can be used to require the user be logged in before the download URL will allow access to the file.
Usage
The following would apply to all forms.
add_filter( 'gform_require_login_pre_download', 'your_function_name', 10, 3 );

Parameters

$require_login bool
Does the user need to be logged in to access the file? Default false.

$form_id int
The ID of the form used to upload the requested file.

$field_id int
The ID of the field used to upload the requested file.

Examples
1. Require login for all forms
add_filter( 'gform_require_login_pre_download', '__return_true' );

2. Require login for specific form and field
add_filter( 'gform_require_login_pre_download', 'require_login_for_downloads', 10, 3 );

function require_login_for_downloads( $require_login, $form_id, $field_id ){

// Update values below to match your form and field id's
if ( $form_id == '97' && $field_id == '2' ) {

$require_login = true;

}

return $require_login;
}

3. Require login for all forms and redirect to login page
add_filter( 'gform_require_login_pre_download', function( $require_login ) {
$require_login = true;
if ( ! is_user_logged_in() ) {
auth_redirect();
}

return $require_login;
} );

Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in Gravity Forms 2.2.3.16.
Source Code
This filter is located in GF_Download::validate_download() in includes/class-gf-download.php.

gform_replace_merge_tags

gform_replace_merge_tags

DescriptionUsageParametersExamples1. Replace a custom merge tag2. Replace {entry_time}3. Replace {transaction_id}4. Replace {entry_notes}5. Replace {paypal_link}6. Replace {archive_title}7. Custom Date Merge Tag8. Replace {user_id}9. Replace {username}9. Replace a custom merge tag with value from a BuddyPress profile fieldSource Code

Description
Use this filter to replace custom merge tags.
Usage
1add_filter( 'gform_replace_merge_tags', 'replace_custom_merge_tags', 10, 7 );

Parameters

$text string
The current text in which merge tags are being replaced.

$form Form Object
The current form.

$entry Entry Object
The current entry.

$url_encode boolean
Whether or not to encode any URLs found in the replaced value.

$esc_html boolean
Whether or not to encode HTML found in the replaced value.

$nl2br boolean
Whether or not to convert newlines to break tags.

$format string
Determines how the value should be formatted. Default is html.

Examples
1. Replace a custom merge tag
This example demonstrates how to replace a custom merge tag. The code first searches for the merge tag in the $text. If found, it proceeds to retrieve the value which should replace the merge tag and then returns the newly replaced string.
1234567891011121314add_filter( 'gform_replace_merge_tags', 'replace_download_link', 10, 7 );function replace_download_link( $text, $form, $entry, $url_encode, $esc_html, $nl2br, $format ) {     $custom_merge_tag = '{download_link}';     if ( strpos( $text, $custom_merge_tag ) === false ) {        return $text;    }     $download_link = gform_get_meta( $entry['id'], 'gfmergedoc_download_link' );    $text = str_replace( $custom_merge_tag, $download_link, $text );     return $text;}
2. Replace {entry_time}
This example replaces a custom merge tag with the entry date and time. If you don』t need to customize the output, you can also use the built-in {entry:date_created} merge tag that uses the default yyyy-mm-dd hh::mm::ss format.
123456789add_filter( 'gform_replace_merge_tags', function ( $text, $form, $entry, $url_encode, $esc_html, $nl2br, $format ) {    $merge_tag = '{entry_time}';     if ( strpos( $text, $merge_tag ) === false || empty( $entry ) || empty( $form ) ) {        return $text;    }     return str_replace( $merge_tag, GFCommon::format_date( rgar( $entry, 'date_created' ), false, 'Y/m/d' ), $text );}, 10, 7 );
3. Replace {transaction_id}
This example replaces a custom merge tag with the payment transaction id.
12345678910add_filter( 'gform_replace_merge_tags', function ( $text, $form, $entry, $url_encode ) {    $merge_tag = '{transaction_id}';     if ( strpos( $text, $merge_tag ) === false || empty( $form ) || empty( $entry ) ) {        return $text;    }    $transaction_id = esc_html( rgar( $entry, 'transaction_id' ) );     return str_replace( $merge_tag, $url_encode ? urlencode( $transaction_id ) : $transaction_id, $text );}, 10, 4 );
Note: Since Gravity Forms 2.1.1.11 you don』t even have to use this filter to output the transaction_id or other payment details for add-ons using the add-on framework. You can use the entry merge tag with the modifier for the property you want to output. e.g. {entry:transaction_id}
4. Replace {entry_notes}
This example replaces a custom merge tag with the entry notes.
123456789101112131415161718192021add_filter( 'gform_replace_merge_tags', 'replace_entry_notes', 10, 7 );function replace_entry_notes( $text, $form, $entry, $url_encode, $esc_html, $nl2br, $format ) {    $merge_tag = '{entry_notes}';     if ( strpos( $text, $merge_tag ) === false || empty( $entry ) || empty( $form ) ) {        return $text;    }     $entry_notes = '';    $notes       = RGFormsModel::get_lead_notes( $entry['id'] );     if ( $notes ) {        $entry_notes .= "

Additional Notes
";        foreach ( $notes as $note ) {            $date = GFCommon::format_date( $note->date_created, false );            $entry_notes .= "{$note->user_name} - {$date}
{$note->value}

";        }    }     return str_replace( $merge_tag, $entry_notes, $text );}
5. Replace {paypal_link}
This example replaces a custom merge tag with the PayPal link for the feed which was used to process an entry.
1234567891011121314151617add_filter( 'gform_replace_merge_tags', 'replace_paypal_link_merge_tag', 10, 7 );function replace_paypal_link_merge_tag( $text, $form, $entry, $url_encode, $esc_html, $nl2br, $format ) {    $merge_tag = '{paypal_link}';     if ( strpos( $text, $merge_tag ) === false || empty( $entry ) || empty( $form ) || ! function_exists( 'gf_paypal' ) ) {        return $text;    }     $feed = gf_paypal()->get_payment_feed( $entry, $form );    if ( $feed ) {        $submission_data = gf_paypal()->get_submission_data( $feed, $form, $entry );        $url             = gf_paypal()->redirect_url( $feed, $submission_data, $form, $entry );        $text            = str_replace( $merge_tag, sprintf( "Pay by PayPal", $url ), $text );    }     return $text;}
6. Replace {archive_title}
This example replaces a custom merge tag during form pre-population with the archive title where the form is located.
123456789add_filter( 'gform_replace_merge_tags', function ( $text, $form ) {    $merge_tag = '{archive_title}';     if ( strpos( $text, $merge_tag ) === false || ! empty( $form ) ) {        return $text;    }     return str_replace( $merge_tag, get_the_archive_title(), $text );}, 10, 2 );
7. Custom Date Merge Tag
This example replaces shows how you can define a custom merge tag to return the current date in your desired format.
123456789101112add_filter( 'gform_replace_merge_tags', function ( $text, $form, $entry, $url_encode, $esc_html, $nl2br, $format ) {    $merge_tag = '{custom_date}';     if ( strpos( $text, $merge_tag ) === false ) {        return $text;    }     $local_timestamp = GFCommon::get_local_timestamp( time() );    $local_date      = date_i18n( 'Y-m-d', $local_timestamp, true );     return str_replace( $merge_tag, $url_encode ? urlencode( $local_date ) : $local_date, $text );}, 10, 7 );
8. Replace {user_id}
This example replaces a custom merge tag with the id of the user which was created from the current entry.
123456789101112add_filter( 'gform_replace_merge_tags', 'replace_user_id_merge_tag', 10, 3 );function replace_user_id_merge_tag( $text, $form, $entry ) {    $merge_tag = '{user_id}';     if ( strpos( $text, $merge_tag ) === false || empty( $entry ) || empty( $form ) || ! function_exists( 'gf_user_registration' ) ) {        return $text;    }     $user_id = gf_user_registration()->get_user_by_entry_id( $entry['id'], true );     return str_replace( $merge_tag, $user_id, $text );}
9. Replace {username}
This example replaces a custom merge tag with the username of the user which was created from the current entry.
1234567891011121314add_filter( 'gform_replace_merge_tags', function ( $text, $form, $entry ) {    GFCommon::log_debug( __METHOD__ . '(): Running snippet for custom {username} merge tag.' );    $merge_tag = '{username}';      if ( strpos( $text, $merge_tag ) === false || empty( $entry ) || ! function_exists( 'gf_user_registration' ) ) {        return $text;    }      /** @var WP_User $user */    $user = gf_user_registration()->get_user_by_entry_id( $entry['id'] );    GFCommon::log_debug( __METHOD__ . "(): user_login for entry id {$entry['id']} is {$user->user_login}" );      return str_replace( $merge_tag, $user->user_login, $text );}, 10, 3 );
9. Replace a custom merge tag with value from a BuddyPress profile field
This example replaces a custom merge tag with the value obtained from a custom BuddyPress profile field of type Text labeled as BP Text in BuddyPress.
123456789101112131415// BuddyPress custom merge tagadd_filter( 'gform_replace_merge_tags', function ( $text, $form ) {    $merge_tag = '{bpfield_bptext}'; // Change this to any name you may want to use for your merge tag      if ( strpos( $text, $merge_tag ) === false || ! empty( $form ) ) {        return $text;    }      $current_user = wp_get_current_user();     // Change BP Text to the label defined for your field in BuddyPress    $bp_field_content = bp_get_profile_field_data( array( 'field'=>'BP Text', 'user_id'=>$current_user->ID ) );       return str_replace( $merge_tag, $bp_field_content, $text );}, 10, 2 );
Source Code
1apply_filters( 'gform_replace_merge_tags', $text, $form, $entry, $url_encode, $esc_html, $nl2br, $format )
This filter is located in GFCommon::replace_variables_prepopulate() in common.php.