Title: pre_http_request
Published: April 25, 2014
Last modified: February 24, 2026

---

# apply_filters( ‘pre_http_request’, false|array|WP_Error $response, array $parsed_args, string $url )

## In this article

 * [Description](https://developer.wordpress.org/reference/hooks/pre_http_request/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/hooks/pre_http_request/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/hooks/pre_http_request/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/pre_http_request/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/pre_http_request/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/hooks/pre_http_request/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/hooks/pre_http_request/?output_format=md#wp--skip-link--target)

Filters the preemptive return value of an HTTP request.

## 󠀁[Description](https://developer.wordpress.org/reference/hooks/pre_http_request/?output_format=md#description)󠁿

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](https://developer.wordpress.org/reference/classes/wp_error/) instance
 * Boolean false to avoid short-circuiting the response

Returning any other value may result in unexpected behavior.

## 󠀁[Parameters](https://developer.wordpress.org/reference/hooks/pre_http_request/?output_format=md#parameters)󠁿

 `$response`false|array|[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)

A preemptive return value of an HTTP request. Default false.

`$parsed_args`array

HTTP request arguments.

`$url`string

The request URL.

## 󠀁[Source](https://developer.wordpress.org/reference/hooks/pre_http_request/?output_format=md#source)󠁿

    ```php
    $pre = apply_filters( 'pre_http_request', false, $parsed_args, $url );
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-http.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/class-wp-http.php#L277)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/class-wp-http.php#L277-L277)

## 󠀁[Related](https://developer.wordpress.org/reference/hooks/pre_http_request/?output_format=md#related)󠁿

| Used by | Description | 
| [WP_Http::request()](https://developer.wordpress.org/reference/classes/wp_http/request/)`wp-includes/class-wp-http.php` |

Send an HTTP request to a URI.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/hooks/pre_http_request/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.9.0](https://developer.wordpress.org/reference/since/2.9.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/hooks/pre_http_request/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/hooks/pre_http_request/?output_format=md#comment-content-5775)
 2.   [expresstechsoftware](https://profiles.wordpress.org/expresstechsoftware/)  [  4 years ago  ](https://developer.wordpress.org/reference/hooks/pre_http_request/#comment-5775)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpre_http_request%2F%23comment-5775)
    Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpre_http_request%2F%23comment-5775)
 4.     ```php
        add_filter( 'pre_http_request', 'pass_or_reject_request', 10, 3 );
    
        function pass_or_reject_request( $preempt, $parsed_args, $url ){
        	// filter...
        	if( strpos($url, 'http(s)://any_domain.com') !==false ){
        		return new WP_Error( 'http_request_block', __( "This request is not allowed", "textdomain" ) );
        	}
        	return $preempt;
        }
        ```
    
 5.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpre_http_request%2F%3Freplytocom%3D5775%23feedback-editor-5775)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpre_http_request%2F)
before being able to contribute a note or feedback.