gform_webhooks_request_method

gform_webhooks_request_method

DescriptionUsageParametersExamplePlacementSource Code

Description
This filter allows the webhook HTTP request method to be modified.
Usage
The following would apply to all forms:
add_filter( 'gform_webhooks_request_method', 'your_function_name', 10, 4 )

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

Parameters

$request_method string
HTTP request method.

$feed Feed Object
The current feed object.

$entry Entry Object
The current entry object.

$form Form Object
The current form object.

Example
add_filter( 'gform_webhooks_request_method', 'set_method', 10, 4 );
function set_method( $request_method, $feed, $entry, $form ){
return 'GET';
}

Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GF_Webhooks::process_feed() in gravityformswebhooks/class-gf-webhooks.php.

gform_webhooks_request_headers

gform_webhooks_request_headers

DescriptionUsageParametersExamples1. Set the From header2. Set the authorization header #13. Set the authorization header #24. Set the authorization header #3PlacementSource Code

Description
The 「gform_webhooks_request_headers」 filter allows the webhook HTTP request headers to be modified.
Usage
The following would apply to all forms:
add_filter( 'gform_webhooks_request_headers' 'your_function_name', 10, 4 );

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

Parameters

$request_headers array
HTTP request headers.

$feed Feed Object
The feed object.

$entry Entry Object
The current entry.

$form Form Object
The form object.

Examples
1. Set the From header
add_filter( 'gform_webhooks_request_headers', 'set_headers', 10, 4 );
function set_headers( $request_headers, $feed, $entry, $form ){
$request_headers['From'] = '[email protected]';
return $request_headers;
}

2. Set the authorization header #1
This example shows how you can generate and add a bearer token to the authorization header. In this case the token is being generated by a third-party service (goabroadhq.com) and then cached locally until it expires.
add_filter( 'gform_webhooks_request_headers', function ( $request_headers ) {
$token = GFCache::get( 'goabroadhq_token' );

if ( ! $token ) {
$post_url = 'https://hq-api.goabroadhq.com/token';
$body = array(
'client_id' => 'something',
'client_secret' => 'something',
'grant_type' => 'client_credentials',
);
$headers = array( 'Content-Type' => 'application/x-url-form-encoded' );

$response = wp_remote_post( $post_url, array( 'body' => $body, 'headers' => $headers ) );
gf_webhooks()->log_debug( 'gform_webhooks_request_headers: response => ' . print_r( $response, true ) );

if ( ! is_wp_error( $response ) && wp_remote_retrieve_response_code( $response ) == 200 ) {
$response_body_json = wp_remote_retrieve_body( $response );
$response_body_array = json_decode( $response_body_json, true );

if ( isset( $response_body_array['access_token'] ) ) {
$token = $response_body_array['access_token'];
GFCache::set( 'goabroadhq_token', $token, true, $response_body_array['expires_in'] - 30 );
}
}
}

if ( $token ) {
gf_webhooks()->log_debug( 'gform_webhooks_request_headers: token added.' );
$request_headers['Authorization'] = 'Bearer ' . $token;
}

return $request_headers;
} );

3. Set the authorization header #2
This example shows how you can generate and add a bearer token to the authorization header. In this case the token is being generated by the JWT PHP Library for use with the Zoom API.
add_filter( 'gform_webhooks_request_headers', function ( $request_headers ) {
// Requires JWT PHP Library https://github.com/firebase/php-jwt
if ( class_exists( 'JWT' ) ) {
// Zoom API credentials from https://developer.zoom.us/me/
$key = '';
$secret = '';
$token = array(
"iss" => $key,
// The benefit of JWT is expiry tokens, we'll set this one to expire in 1 minute
"exp" => time() + 60
);

$request_headers['Authorization'] = 'Bearer ' . JWT::encode( $token, $secret );
gf_webhooks()->log_debug( 'gform_webhooks_request_headers: token added.' );
}

return $request_headers;
} );

4. Set the authorization header #3
This example shows how you can add the Basic Authorization header to authenticate a request.
add_filter( 'gform_webhooks_request_headers', function ( $request_headers ) {
$request_headers['Authorization'] = 'Basic ' . base64_encode( USERNAME . ':' . PASSWORD );

return $request_headers;
}, 10, 2 );

Note: The above example is based on USERNAME and PASSWORD being constants defined elsewhere (i.e. the wp-config.php file), if not, you can include the values within the quotes e.g. 『USERNAME:PASSWORD』.
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GF_Webhooks::process_feed() in gravityformswebhooks/class-gf-webhooks.php.

gform_webhooks_request_data

gform_webhooks_request_data

DescriptionUsageParametersExamples1. Add a new field2. Modify the field keys3. Modify the field values for the Events Calendar plugin4. Remove empty valuesPlacementSource Code

Description
This filter allows the webhook HTTP request data to be modified.
Usage
The following would apply to all forms:
add_filter( 'gform_webhooks_request_data', 'your_function_name', 10, 4 )

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

Parameters

$request_data array
HTTP request data.

$feed Feed Object
The current feed object.

$entry Entry Object
The current entry object.

$form Form Object
The current form object.

Examples
1. Add a new field
add_filter( 'gform_webhooks_request_data', 'modify_data', 10, 4 );
function modify_data( $request_data, $feed, $entry, $form ){
$request_data[1] = 'Tester McTesty';
return $request_data;
}

2. Modify the field keys
This example shows how the field/input IDs, which are used as the keys to the data when the 「all fields」 choice is selected for the request body setting, can be replaced. In this case the period used in the input IDs is being replaced with an underscore so the webhook to Automate.io will succeed.
add_filter( 'gform_webhooks_request_data', function ( $request_data, $feed ) {
if ( rgars( $feed, 'meta/requestBodyType' ) === 'all_fields'
&& strpos( rgars( $feed, 'meta/requestURL' ), 'automate.io' ) !== false
) {
foreach ( $request_data as $key => $value ) {
if ( is_numeric( $key ) ) {
$request_data[ 'field ' . str_replace( '.', '_', $key ) ] = $value;
unset( $request_data[ $key ] );
}
}
}

return $request_data;
}, 10, 2 );

3. Modify the field values for the Events Calendar plugin
This example shows how some field values, which will be strings when mapped to form field values, can be changed to booleans as required by the Events Calendar plugin.
add_filter( 'gform_webhooks_request_data', function ( $request_data, $feed ) {
$request_url = rgars( $feed, 'meta/requestURL' );
if ( strpos( $request_url, 'tribe/events/' ) !== false ) {
$requires_bool_values = array(
'all_day',
'show_map',
'show_map_link',
'hide_from_listings',
'sticky',
'featured',
);

foreach ( $request_data as $key => $value ) {
if ( in_array( $key, $requires_bool_values ) ) {
$request_data[ $key ] = (bool) $value;
}
}
}

return $request_data;
}, 10, 2 );

4. Remove empty values
This example shows how empty fields can be removed from the request data when the 「all fields」 choice is selected for the request body setting.
add_filter( 'gform_webhooks_request_data', function ( $request_data, $feed ) {
if ( rgars( $feed, 'meta/requestBodyType' ) === 'all_fields' ) {
foreach ( $request_data as $key => $value ) {
if ( empty( $value ) ) {
unset( $request_data[ $key ] );
}
}
}

return $request_data;
}, 10, 2 );

Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GF_Webhooks::get_request_data() in gravityformswebhooks/class-gf-webhooks.php.

gform_webhooks_request_args

gform_webhooks_request_args

DescriptionUsageParametersExamples1. Set the 「From」 Header2. Set the WP REST API Cookie Authentication Arguments3. Set the WP REST API Basic Authorization HeaderPlacementSource Code

Description
The 「gform_webhooks_request_args」 filter allows the webhook HTTP request arguments to be modified.
Usage
1add_filter( 'gform_webhooks_request_args' 'your_function_name', 10, 4 );

Parameters

$request_args array
HTTP request arguments.

$feed Feed Object
The feed object.

$entry Entry Object
The current entry.

$form Form Object
The form object.

Examples
1. Set the 「From」 Header
12345add_filter( 'gform_webhooks_request_args', 'set_args', 10, 4 );function set_args( $request_args, $feed, $entry, $form ){    $request_args['headers']['From'] = '[email protected]';    return $request_args;}
2. Set the WP REST API Cookie Authentication Arguments
This example shows how you can add the 「cookies」 argument and the 「X-WP-Nonce」 header to authenticate a request to the local WordPress REST API for the currently logged-in user.
123456789add_filter( 'gform_webhooks_request_args', function ( $request_args, $feed ) {    $request_url = rgars( $feed, 'meta/requestURL' );    if ( strpos( $request_url, '{rest_api_url}' ) === 0 || strpos( $request_url, rest_url() ) === 0 ) {        $request_args['cookies']               = $_COOKIE;        $request_args['headers']['X-WP-Nonce'] = wp_create_nonce( 'wp_rest' );    }     return $request_args;}, 10, 2 );
3. Set the WP REST API Basic Authorization Header
This example shows how you can add the Basic Authorization header to authenticate a request to the local WordPress REST API.
Note: Cookie authentication is the only method the WordPress REST API supports natively. Using alternative methods such as the Basic Authorization header will require the use of additional plugins, see the WordPress REST API documentation for some suggestions.
12345678add_filter( 'gform_webhooks_request_args', function ( $request_args, $feed ) {    $request_url = rgars( $feed, 'meta/requestURL' );    if ( strpos( $request_url, '{rest_api_url}' ) === 0 || strpos( $request_url, rest_url() ) === 0 ) {        $request_args['headers']['Authorization'] = 'Basic ' . base64_encode( USERNAME_HERE . ':' . PASSWORD_HERE );    }     return $request_args;}, 10, 2 );
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GF_Webhooks::process_feed() in gravityformswebhooks/class-gf-webhooks.php.

gform_webhooks_post_request

gform_webhooks_post_request

DescriptionUsageParametersExamplesExample 1Example 2PlacementSource Code

Description
The 「gform_webhooks_post_request」 action fires after a Webhooks request has been executed and allows further actions to be performed.
Usage
The following would apply to all forms:
1add_action( 'gform_webhooks_post_request' 'your_function_name', 10, 4 );
To target a specific form, append the form id to the hook name. (format: gform_webhooks_post_request_FORMID)
1add_action( 'gform_webhooks_post_request_78' 'your_function_name', 10, 4 );
To target a specific form』s feed, append the form id and feed id to the hook name. (format: gform_webhooks_post_request_FORMID_FEEDID)
1add_action( 'gform_webhooks_post_request_78_12' 'your_function_name', 10, 4 );

Parameters

$response WP_Error or array
The response from the request execution. The response will be the WP_Error object if the execution fails, otherwise an array.

$feed Feed Object
The feed object.

$entry Entry Object
The current entry.

$form Form Object
The form object.

Examples
Example 1
1234add_action( 'gform_webhooks_post_request', 'post_request', 10, 4 );function post_request( $response, $feed, $entry, $form ){  //do something grand here}
Example 2
12345add_action( 'gform_webhooks_post_request', function ( $response, $feed, $entry, $form ) {    if ( is_wp_error( $response ) ) {        // Do something here if the request failed.    }}, 10, 4 );
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GF_Webhooks::process_feed() in gravityformswebhooks/class-gf-webhooks.php.

gform_webapi_key_user_capabilities

gform_webapi_key_user_capabilities

DescriptionUsageParametersExamples1. Add CapabilityPlacementSinceSource Code

Description
The gform_webapi_key_user_capabilities filter allows the list of capabilities which are used to determine if a user is included in the User drop down menu when creating a new REST API Key to be overridden.
Usage
The filter would be used like so:
add_filter( 'gform_webapi_key_user_capabilities', 'your_function_name' );

Parameters

$capabilities array
A list of Gravity Forms capabilities used by REST API endpoints.

Examples
1. Add Capability
This example adds a new capability to the list.
add_filter( 'gform_webapi_key_user_capabilities', function ( $capabilities ) {
$capabilities[] = 'create_users';

return $capabilities;
} );

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.4.23.2.
Source Code
This filter is located in GFWebAPI::user_can_access_api() in includes/webapi/webapi.php.

gform_webapi_get_users_settings_page

gform_webapi_get_users_settings_page

DescriptionUsageParametersExamplesPlacementSource Code

Description
Use this filter to control the list of users available to be selected in the 「Impersonate account」 setting. Note that this doesn』t control access to the API, it just controls the list of users available on the settings page.
Usage
add_filter( 'gform_webapi_get_users_settings_page', 'api_get_users_args' );

Parameters

$args array

array( 'number' => 3000 )
The array of options to use when filtering the users. See the WP_User_Query::prepare_query() reference on the WordPress codex for further details.

Examples
This example lists only the users from the role 「administrator」.
add_filter( 'gform_webapi_get_users_settings_page', 'api_get_users_args' );
function api_get_users_args( $args ) {
$args['role'] = 'administrator';
return $args;
}

Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GFWebAPI::plugin_settings_fields() in includes/webapi.php

gform_webapi_ENDPOINT

gform_webapi_ENDPOINT

DescriptionUsageParametersExamplesSource Code

Description
Triggered when a particular Gravity Forms Web API endpoint is accessed.
Usage
1add_action( 'gform_webapi_get_forms', 'my_function', 10, 4 );

Parameters

$id string
The ID of the element obtained. For example, the form ID if accessing a form.

$id2 string
Only defined if a secondary ID is defined in the request; such as getting a specific field, within a specific entry.

$format string
The format that the data is returned it. By default, returns json.

$args array
Arguments that were used within the request such as the offset, page size, and schema.

Examples
1234function my_function() {    //Do something here}add_action( 'gform_webapi_get_forms', 'my_function', 10, 4 );
Source Code
This action hook is located in webapi.php

gform_webapi_authentication_required_ENDPOINT

gform_webapi_authentication_required_ENDPOINT

DescriptionUsageParametersExampleForce authentication for the POST forms/[ID]/submissions endpoint.PlacementSource Code

Description
The 「gform_webapi_authentication_required_」 plus ENDPOINT filter in Gravity Forms allows the overriding of authentication for all the endpoints of the Web API.
Usage
1add_filter( 'gform_webapi_authentication_required_' . $endpoint, 'your_function_name' );

Parameters

$authentication_required bool
Whether authentication is required for this endpoint.

Example
Force authentication for the POST forms/[ID]/submissions endpoint.
The following example forces the Gravity Forms Web API to authenticate the user before allowing the form to be POSTed.
1add_filter( 'gform_webapi_authentication_required_post_forms_submissions', '__return_true' );
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GFWebAPI::handle_page_request() in includes/webapi/webapi.php

gform_web_api_retrieve_form_totals

gform_web_api_retrieve_form_totals

DescriptionUsageParametersExamples1. Simple Usage2. Advanced UsagePlacementSinceSource Code

Description
The gform_web_api_retrieve_form_totals filter allows the entries property (entry totals) to be omitted from the GET /forms (REST API v1) response. This is useful for increasing performance of the endpoint when totals aren』t required.
Usage
The filter would be used like so:
add_filter( 'gform_web_api_retrieve_form_totals', 'your_function_name', 10, 2 );

You can also specify this per form by adding the form id after the filter name.
add_filter( 'gform_web_api_retrieve_form_totals_6', 'your_function_name', 10, 2 );

Parameters

$include_totals boolean
Whether to include totals; defaults to true.

$form object
The current form properties (id, title, date_created, is_active).

Examples
1. Simple Usage
add_filter( 'gform_web_api_retrieve_form_totals', '__return_false' );

2. Advanced Usage
add_filter( 'gform_web_api_retrieve_form_totals', function ( $include_totals, $form ) {
return ! in_array( $form->id, array( 1, 3, 5 ) );
}, 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.4.24.1.
Source Code
This filter is located in GFWebAPI::get_forms() in includes/webapi/webapi.php.