pre_http_request

Filters whether to preempt an HTTP request's return value.

Description

apply_filters( 'pre_http_request', (bool) $false, (array) $r, (string) $url ); 

Returning a non-false value from the filter will short-circuit the HTTP request and return early with that value. A filter should return either:

- An array containing headers,, body , response, cookies, and filename elements - A WP_Error instance - boolean false (to avoid short-circuiting the response)

Returning any other value may result in unexpected behaviour.

Parameters (3)

0. $false (bool) => false
Whether to preempt an HTTP request's return value. Default false.
1. $r (array)
HTTP request arguments.
2. $url (string)
The request URL.

Usage

To run the hook, copy the example below.
  1. $false = apply_filters( 'pre_http_request', $false, $r, $url ); 
  2.  
  3. if ( !empty( $false ) ) { 
  4.  
  5. // everything has led up to this point... 
  6.  
  7.  
The following example is for adding a hook callback.
  1. // define the pre_http_request callback 
  2. function filter_pre_http_request( $false, $r, $url ) { 
  3. // make filter magic happen here... 
  4. return $false
  5. }; 
  6.  
  7. // add the filter 
  8. add_filter( 'pre_http_request', 'filter_pre_http_request', 10, 3 ); 
To remove a hook callback, use the example below.
  1. // remove the filter 
  2. remove_filter( 'pre_http_request', 'filter_pre_http_request', 10, 3 ); 

Defined (1)

The filter is defined in the following location(s).

/wp-includes/class-http.php  
  1. $pre = apply_filters( 'pre_http_request', false, $r, $url );