We all know how important it is to keep your WordPress plugins updated to maintain security and avoid being hacked. A WordPress plugin vulnerability database is maintained by WPScan and can be found here. It is a tedious task to update multiple WordPress installations, some tools exist like ManageWP and InfiniteWP to ease the monotony.
I like to automate things so I wrote a bash script that uses the power of WP-CLI which is a powerful command line tool for managing WordPress. I run this script as a daily cronjob. One drawback of updating WordPress quickly is you can encounter new bugs, to mitigate that scenario the bash script takes a backup of all WordPress sites and databases prior to updating so you can easily restore.
If you want to do updates for WordPress or WooCommerce without a cronjob see this post
Autoupdate WordPress Plugins with WP-CLI Cronjob
The script does the following
- Creates a list of your WordPress sites
- Back up WordPress folder and database
- Update WordPress plugins
- Set recommended WordPress file and folder permissions
You will need WP-CLI installed. A very basic installation can be done with these commands
Create a new WordPress backup script file
Here is the WP-CLI script for backing up WordPress and automatically updating the plugins
Make sure the WP-CLI script is executable.
Test the script manually before adding it as a cronjob.
Add the WP-CLI backup script to as a cronjob
Enter this line to run the WP-CLI backup script at midnight every day
That does it, every day at midnight the script will back up WordPress and update all plugins for you.
Sources and Inspiration
Sucuri Secure WordPress Backup Update
Advanced WordPress Facebook Group
Cronjob Timing
Thanks! This is going to save my bacon, as I have quite a few sites that I have to update to 4.7.2 now that WordPress 4.7.1 is vulnerable!
Thanks! This is going to save my bacon, as I have quite a few sites that I have to update to 4.7.2 now that WordPress 4.7.1 is vulnerable!