7

How To: Disable/Block External HTTP Requests In WordPress


Posted by Artem Russakovskii on November 16th, 2011 in PHP, Wordpress

One thing that's been continuously annoying me when doing WordPress development on the go is when something somewhere inside WordPress decides to send requests to external urls when I don't even have Internet connection or it's slow and flaky (tethering, slow Wi-Fi, etc). This results in random lag when loading pages, especially if I haven't opened my dev WordPress instance for a long time.

Turns out there's an easy and undocumented (other than in code) solution. To block external HTTP requests right in WordPress's core itself, open up wp-config.php and add WP_HTTP_BLOCK_EXTERNAL like so:

1
define('WP_HTTP_BLOCK_EXTERNAL', true);

Whenever this variable is present, external requests will be ignored, unless you specify your own comma-separated whitelist of domains using WP_ACCESSIBLE_HOSTS like so:

1
define('WP_ACCESSIBLE_HOSTS', 'site1.com, site2.com');

You can examine relevant core code here and the relevant bug reports here and here.

Happy developing!

● ● ●
Artem Russakovskii is a San Francisco programmer and blogger. Follow Artem on Twitter (@ArtemR) or subscribe to the RSS feed.

In the meantime, if you found this article useful, feel free to buy me a cup of coffee below.