Debugging WordPress on localhost

WordPress After I published WordPress Needs WP_LOCAL for localhost, Piet Bos and Danny van Kooten advised me to try the Airplane Mode plugin by Andrew Norcross of Tampa, Florida.

Airplane Mode uses the pre_http_request filter to block external requests. Nice job!

I installed Airplane Mode and wrote a shell script to disable all plugins. More on the script below.

My only external requests are coming from JavaScript.

Blocking External Requests from WordPress

I received additional suggestions after I wrote my script.

I would like to thank everyone who explained how to block external requests on localhost.

Paul Thompson suggesting adding WP_HTTP_BLOCK_EXTERNAL to config. I never used this, but it seems perfect:

Block external URL requests by defining WP_HTTP_BLOCK_EXTERNAL as true and this will only allow localhost and your blog to make requests. The constant WP_ACCESSIBLE_HOSTS will allow additional hosts to go through for requests.

Noam Eppel sent his Multi-Environment WordPress wp-config.php. His contribution:

This wp-config.php file can be used in multiple environments (local, staging, production). It works by detecting the server hostname and defining different constants depending on which hostname is used.

I do something similar with wp-load.php, but his solution does not require editing core.

Jon Brown sent a link to Rarst’s Disable plugins when doing local dev. This is a PHP class to selectively load plugins.

Konstantin Kovshenin suggested filtering pre_http_request, like Airplane Mode.

Importing a Production Database to localhost

I wrote a bash script to import a production database, and avoid the plugin update error.

import_wordpress_db_to_localhost is shown below.

Script disables plugins, sets blog to “private” and adds “LOCAL:” to a site’s name. It is easy to use this script for multiple sites.

Try: alias import_blog='import_wordpress_db_for_local_use.sh DB SQL login password'

No connection errors today, using AirPlane Mode and my import script.

I learned how to block Gravatar and external font loaders, too.