brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: WP_HTTP_BLOCK_EXTERNAL stops WordPress from calling out to the internet

WordPress
~/tips/tip-wordpress-http-block-external

define( 'WP_HTTP_BLOCK_EXTERNAL', true );

Blocks outgoing HTTP requests from WordPress except to hosts you put on an allowlist.

A WordPress site talks to a lot of servers you never see: update checks, plugin licence servers, font CDNs, analytics, the odd plugin that phones home. Most of that is fine. But on a staging copy, an intranet site, or a site you just want to keep on a short leash, I like having a switch that says “no outgoing requests unless I allow it”.

That switch lives in wp-config.php. Set WP_HTTP_BLOCK_EXTERNAL to true and WordPress only lets requests through to localhost and your own site. With WP_ACCESSIBLE_HOSTS you name the hosts that may still be reached, as a comma separated list with wildcard support:

define( 'WP_HTTP_BLOCK_EXTERNAL', true );
define( 'WP_ACCESSIBLE_HOSTS', '*.wordpress.org' );

Put both lines above the /* That's all, stop editing! */ comment. The wildcard *.wordpress.org covers the subdomains of wordpress.org, including api.wordpress.org, which is the one WordPress needs for update checks. The official example uses 'api.wordpress.org,*.github.com' if you’d rather be stricter and add hosts one by one.

A neat side effect: when a plugin breaks after you turn this on, you’ve learned that it was calling home. That alone tells you something about the plugins on your site.

Two caveats. The block covers requests that go through the WordPress HTTP API, which is what core and well-behaved plugins use. A plugin that opens its own connection with raw cURL or sockets isn’t stopped by it, so treat this as a strong default and not a firewall. And if you forget to allow api.wordpress.org, core and plugin updates quietly stop checking in. My advice is to add the hosts you know you need, then visit Dashboard → Updates and confirm it still finds updates.

Further reading: Block external URL requests (wp-config.php, Advanced Administration), WP_Http::block_request()

More WordPress tips wp user application-password create anna backup-script --porcelain define( 'MEDIA_TRASH', true ); wp cli check-update wp theme delete --all wp media image-size All WordPress tips (85) All topics

Link