How to: Disable HTTP Calls in WordPress

Sometimes you’re travelling on a plane or on a boat, in the metro or on the road. Sometimes you just have a crappy Internet connection, and you’ll notice that a local WordPress install (mostly admin pages) takes several seconds to load. That could create a big problem if you’re developing a theme or plugin, and have to refresh eighty times per minute.

WordPress uses its HTTP API (the WP_Http class and wrapper functions) to look for plugin, themes and core updates, fetch RSS feeds or talk to third party API (such as a Twitter widget plugin) and with no Internet connection, calls to such functions will timeout in a few seconds, thus the long page load time. A simple solution is to simply disable all HTTP calls and luckily, WordPress allows us to do that in a single filter for our theme (functions.php) or plugin file:

add_filter( 'pre_http_request', '__return_true', 100 );

The smarter way would be to intercept the request and let it pass or block it based on the request URL, that way you’ll be able to work with local APIs. Yet another benefit of using the WordPress HTTP API and not file_get_contents or curl_exec :)

Update: As Dion Hulse mentioned on Twitter, you can also use WP_HTTP_BLOCK_EXTERNAL in your config file to achieve the same thing, but in a more “cron friendly” way. More information about this can be found somewhere around this line.

About the author

Konstantin Kovshenin

WordPress Core Contributor, ex-Automattician, public speaker and consultant, enjoying life in Moscow. I blog about tech, WordPress and DevOps.

3 comments

  • I have different installs in a network area, and no chance to get outside this network. I use a small custom plugin, more code; but useable in different versions of WP; not all have the last version – business problems ;)
    But my smallest config to deactivte the call is the constant:

    define( 'WP_HTTP_BLOCK_EXTERNAL', TRUE );
    

    best regards

    • Hi Frank, thanks for stopping by! The constant seems to work well in most recent versions, and does not break the cron magic. Thanks for sharing the plugin, might use it if I stumble upon an old installation, though that would make me sad. Cheers!