Description
The “gform_webhooks_request_args” filter allows the webhook HTTP request arguments to be modified.
Usage
add_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
add_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.
add_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.
add_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.