Using Gravity Forms ‘gform_webhooks_request_args’ PHP filter

The gform_webhooks_request_args filter allows you to modify webhook HTTP request arguments in Gravity Forms.

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.

More information

See Gravity Forms Docs: gform_webhooks_request_args

Place the code in the functions.php file of your active theme. The filter is located in GF_Webhooks::process_feed() in gravityformswebhooks/class-gf-webhooks.php.

Examples

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;
}

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);

Set the WP REST API Basic Authorization Header

Add the Basic Authorization header to authenticate a request to the local WordPress REST API. This method requires additional plugins.

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);