Using Gravity Forms ‘gform_mailchimp_request_args’ PHP filter

The gform_mailchimp_request_args Gravity Forms PHP filter allows you to modify the request arguments before they are sent to Mailchimp.

Usage

add_filter('gform_mailchimp_request_args', 'your_function_name', 10, 2);

Parameters

  • $args (array): The request arguments sent to Mailchimp.
  • $path (string): The request path.

More information

See Gravity Forms Docs: gform_mailchimp_request_args

Examples

Change request method to POST

Modify the request method to be POST before sending to Mailchimp.

add_filter('gform_mailchimp_request_args', 'change_request_args', 10, 2);

function change_request_args($args, $path) {
    // Change method
    $args['method'] = 'POST';
    return $args;
}

Add custom header

Add a custom header to the request arguments before sending to Mailchimp.

add_filter('gform_mailchimp_request_args', 'add_custom_header', 10, 2);

function add_custom_header($args, $path) {
    // Add custom header
    $args['headers']['X-Custom-Header'] = 'CustomValue';
    return $args;
}

Modify request timeout

Change the request timeout value before sending to Mailchimp.

add_filter('gform_mailchimp_request_args', 'modify_request_timeout', 10, 2);

function modify_request_timeout($args, $path) {
    // Set timeout to 10 seconds
    $args['timeout'] = 10;
    return $args;
}

Change request path

Modify the request path before sending to Mailchimp.

add_filter('gform_mailchimp_request_args', 'change_request_path', 10, 2);

function change_request_path($args, $path) {
    // Change path
    $path = '/new/request/path';
    return $args;
}

Log request arguments

Log the request arguments before sending to Mailchimp.

add_filter('gform_mailchimp_request_args', 'log_request_args', 10, 2);

function log_request_args($args, $path) {
    // Log request arguments
    error_log(print_r($args, true));
    return $args;
}