gcapi_http_response
Description
Filter HTTP response data after receiving Allows modification of response data after the HTTP response is received. This is a low-level filter that applies to all HTTP responses received through the plugin.
Usage
Filter applied to all HTTP responses
add_filter( 'gcapi_http_response', 'my_custom_function' );
Parameters
$response_data
array
Response data that can be modified
success
bool
Whether the response was successful (2xx status code)
status_code
int
HTTP status code (0 if exception occurred)
body
string
Response body as string
error_message
string|null
Error message if exception occurred
context
array
Contextual information about the response
request
Webhook_Request|null
Original webhook request object
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
$response
Webhook_Response
The webhook response instance
Examples
Log all API responses for debugging
This example shows how to log all responses for debugging purposes.
add_filter('gcapi_http_response', function($response_data) {
if (defined('WP_DEBUG_LOG') && WP_DEBUG_LOG) {
error_log('API Response: ' . wp_json_encode([
'status' => $response_data['status_code'],
'url' => $response_data['context']['request']->get_url(),
'body_length' => strlen($response_data['body'])
]));
}
return $response_data;
});
Transform response data for specific APIs
For APIs that return data in non-standard formats, you can transform the response.
add_filter('gcapi_http_response', function($response_data) {
$request = $response_data['context']['request'];
if ($request && strpos($request->get_url(), 'legacy-api.example.com') !== false) {
// Transform legacy XML response to JSON
if (strpos($response_data['body'], '<?xml') === 0) {
$xml = simplexml_load_string($response_data['body']);
$response_data['body'] = wp_json_encode($xml);
}
}
return $response_data;
});
Since
1.0.0
Hook added.