Filter hook 'pre_http_request'

in WP Core File wp-includes/class-wp-http.php at line 277

View Source

pre_http_request

Filter Hook
Description
Filters the preemptive return value of an HTTP request. Returning a non-false value from the filter will short-circuit the HTTP request and return early with that value. A filter should return one of: - 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 behavior.

Hook Information

File Location wp-includes/class-wp-http.php View on GitHub
Hook Type Filter
Line Number 277

Hook Parameters

Type Name Description
false|array|WP_Error $response A preemptive return value of an HTTP request. Default false.
array $parsed_args HTTP request arguments.
string $url The request URL.

Usage Examples

Basic Usage
<?php
// Hook into pre_http_request
add_filter('pre_http_request', 'my_custom_filter', 10, 3);

function my_custom_filter($response, $parsed_args, $url) {
    // Your custom filtering logic here
    return $response;
}

Source Code Context

wp-includes/class-wp-http.php:277 - How this hook is used in WordPress core
<?php
 272  		 *
 273  		 * @param false|array|WP_Error $response    A preemptive return value of an HTTP request. Default false.
 274  		 * @param array                $parsed_args HTTP request arguments.
 275  		 * @param string               $url         The request URL.
 276  		 */
 277  		$pre = apply_filters( 'pre_http_request', false, $parsed_args, $url );
 278  
 279  		if ( false !== $pre ) {
 280  			return $pre;
 281  		}
 282  

PHP Documentation

<?php
/**
		 * Filters the preemptive return value of an HTTP request.
		 *
		 * Returning a non-false value from the filter will short-circuit the HTTP request and return
		 * early with that value. A filter should return one of:
		 *
		 *  - 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 behavior.
		 *
		 * @since 2.9.0
		 *
		 * @param false|array|WP_Error $response    A preemptive return value of an HTTP request. Default false.
		 * @param array                $parsed_args HTTP request arguments.
		 * @param string               $url         The request URL.
		 */
Quick Info
  • Hook Type: Filter
  • Parameters: 3
  • File: wp-includes/class-wp-http.php
Related Hooks

Related hooks will be displayed here in future updates.