Doug's Blog

WP Phone Home

I’ve been working on a project running WordPress off of a Raspberry Pi. It’s a pain to carry another monitor, hdmi cord, etc around with me and once the Pi is plugged in it doesn’t need much. I can do what I need to do with just SSH access. Only trouble is some networks that I plug it into are a lot more difficult than others to ascertain what IP address the Pi has acquired. This simple plugin will check IP as defined by the server config and also ifconfig and will email these to the admin address for the installed WordPress site. There’s no settings screen, it’s really not needed. If you want it to check more, or less frequently, change the WP_PHONE_HOME_INTERVAL constant to a different number. Otherwise this simple plugin will “phone home” anytime that the server running it changes IP addresses.

Also you should create a cron job on the server itself to execute wp-cron.php at some interval in order to ensure that your cron jobs are run inside WordPress. Since in theory no one can visit any webpages that would trigger the cron job if the IP address is unknown.

Code: https://github.com/nullvariable/wp-phone-home

Also handy to configure your wp-config to handle the changing IP address, like:

define('WP_HOME', 'http://'.$_SERVER['SERVER_ADDR']);
define('WP_SITEURL', 'http://'.$_SERVER['SERVER_ADDR']);

I’d love to hear if you were able to put this to use or use it as a starting point for your own project.