Make WordPress Core

Opened 3 years ago

Closed 18 months ago

#52428 closed enhancement (invalid)

Create a Filter for Blocking Outgoing HTTP Calls | Single URL

Reported by: jetxpert's profile jetxpert Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.7
Component: HTTP API Keywords:
Focuses: Cc:


Good Day!

Per subject, kindly create a new filter that will allow blocking Outgoing HTTP calls for single or defined URLs. Hopefully, prior to the release of WP 5.7.

Details here



Sorry for the repeat entries. Many sources available :)


Change History (6)

#1 @TimothyBlynJacobs
3 years ago

  • Component changed from General to HTTP API
  • Keywords close reporter-feedback added; dev-feedback needs-unit-tests needs-design removed
  • Version changed from 5.6 to 2.7

Hi @jetxpert,

Welcome to trac! This should be doable with the existing pre_http_request filter. For example:

add_filter( 'pre_http_request', function ( $result, $args, $url ) {
	if ( wp_parse_url( $url, PHP_URL_HOST ) === '' ) {
		return new WP_Error( 'http_request_not_executed', __( 'User has blocked requests through HTTP.' ) );

	return $result;
}, 10, 3 );

#2 @jetxpert
3 years ago

  • Keywords needs-testing added; 2nd-opinion close removed


Thank you so much. We'll give it a spin and report back.


(1) Can your proposed solution be converted to a "define" type filter we can enter into our wpconfig.php file?

(2) We do not want to report back a WP Error. How can we modify your snippet to reflect this?

(3) To add another (i.e, second or third) URL, how would we modify your snippet?

PS: We miss you over at iThemes Security (forum). Help appreciated. Let us know where we can donate :)

Again, thank you.


Last edited 3 years ago by jetxpert (previous) (diff)

#3 @jetxpert
3 years ago

  • Keywords needs-testing removed


Reporting back. Your snippet works like a charm. Thank you.

Can you kindly reply to our questions?

Thank you.

#4 @jetxpert
3 years ago



Questions (2) and (3) resolved.

Only need help with Question (1).

Thank you.

Version 0, edited 3 years ago by jetxpert (next)

#5 @TimothyBlynJacobs
3 years ago

  • Keywords close 2nd-opinion added; reporter-feedback removed

You could do something like this:

define( 'MY_BLOCKED_HOSTS', ',' );

add_filter( 'pre_http_request', function ( $result, $args, $url ) {
	$hosts = wp_parse_list( MY_BLOCKED_HOSTS );

	if ( in_array( wp_parse_url( $url, PHP_URL_HOST ), $hosts, true ) ) {
		return new WP_Error( 'http_request_not_executed', __( 'User has blocked requests through HTTP.' ) );

	return $result;
}, 10, 3 );

FYI: I'm adding the close keyword to indicate that this probably doesn't need changing in WordPress Core. The 2nd-opinion is for another Core contributor to take a look and see if they disagree.

#6 @desrosj
18 months ago

  • Keywords close 2nd-opinion removed
  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Going to close this one out. This is more of a support request and I agree with @TimothyBlynJacobs that there's no action to take on the WordPress Core side.

Note: See TracTickets for help on using tickets.