gcapi_http_request

  1. Description
  2. Usage
  3. Parameters
  4. Examples
    1. Modify request URL for testing environment
    2. Add custom authentication header from PHP constant
  5. Since

Description

Filter HTTP request data before sending Allows modification of request URL, method, and options before the HTTP request is sent. This is a low-level filter that applies to all HTTP requests made through the plugin.

Usage

Filter applied to all HTTP requests

add_filter( 'gcapi_http_request', 'my_custom_function' );

Parameters

$request_data array

Request data that can be modified

url string

Request URL

method string

HTTP method (GET, POST, PUT, DELETE, etc.)

options array

Guzzle request options

timeout int

Request timeout in seconds

context array

Contextual information about the request

feed array|null

Gravity Forms feed configuration

entry array|null

Gravity Forms entry data

form array|null

Gravity Forms form data

connection_profile Connection_Profile|null

Connection profile instance

$request Webhook_Request

The webhook request instance

Examples

Modify request URL for testing environment

This example shows how to redirect all API requests to a staging environment for testing purposes.

add_filter('gcapi_http_request', function($request_data) {
    if (defined('WP_DEBUG') && WP_DEBUG) {
        $request_data['url'] = str_replace('api.example.com', 'staging-api.example.com', $request_data['url']);
    }
    return $request_data;
});

Add custom authentication header from PHP constant

For requests that need additional authentication beyond connection profiles.

add_filter('gcapi_http_request', function($request_data) {
    if (defined('CUSTOM_API_TOKEN')) {
        $request_data['options']['headers']['X-Custom-Auth'] = 'Bearer ' . CUSTOM_API_TOKEN;
    }
    return $request_data;
});

Since

  • 1.0.0 Hook added.