Quantcast
Channel: snippets – Konstantin Kovshenin
Viewing all articles
Browse latest Browse all 32

How to: Disable HTTP Calls in WordPress

$
0
0

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.

Click here to comment

More from Konstantin Kovshenin


Viewing all articles
Browse latest Browse all 32

Latest Images

Trending Articles



Latest Images