Partial Database Restores From a Backup

So maybe you accidentally deleted 600,000 customer records and associated usermeta from a WordPress site. Or maybe I did. Regardless, it’s a problem and they now need to be restored.

Thankfully, there’s a backup (boy howdy, you better hope so). Our site is hosted with WP Engine, so we restored a snapshot from before the accidental deletion to a new environment.

We hadn’t deleted all the user records, just a subset. But the easiest way to restore them from the backup was to export the all the users and usermeta within a specific range- but then only restore the ones that were missing. We did this using WP CLI. Continue reading

GitHub Actions for Laravel Tests

I just set up GitHub Actions for running tests with Laravel and was impressed with how simple it was.

This video shows how I got it set up with the Laravel React Bootstrap project.

1. Click “Actions”
2. Select the default Laravel workflow
3. Create a branch or commit the new workflow

If you have any secret keys that are required for the test environment, those can also be injected easily. I show how to do it in the video, but here’s the full GitHub documentation for it.

Restrict Access to a WordPress Site Based on IP

I recently developed an internal website for our company that wanted to be accessible to employees only. Instead of having a server level password, or individual WordPress logins, we decided to just limit access to by IP address. This way everyone on the office network could access easily, but outside the network they would get an access denied message.

We use WP Engine for hosting, but IP whitelisting or blocking should work with any host.

.htaccess Option

One quick method to set this up is by editing the .htaccess file directly (this should be in the base folder of your WordPress directory) and add the 3 lines at the top of this codeblock:

https://gist.github.com/devinsays/d0781b0b7909c2d16e1b8141c950edea

You’ll want to change the IP address in the example (98.6.000.111) to the IP you want to whitelist. You can also whitelist multiple IP addresses by just adding more below that line.

Plugin Option

An easier option (in my opinion) is to use the Restricted Site Access plugin, maintained by the folks at 10up. This plugin provides you with a dashboard to set up the IP restrictions, and also allows you to set a custom restriction messages or redirects.