I’m a great believer in automation; as one of my interviewers said to me once: If we do it twice; we automate it.
I adopted this style throughout my work; hence I wanted to show how would I upgrade/update the WordPress core and plugins using cron to keep all my blogs and sites secure and up to date with security patches.
1- get & install
2- write a script to use
wp-cli to update WordPress [see attached code]
# prevent errors snowball effect : stop at any process which exit with non success value (non zero)
# print current version | used for logs
wp core version
# upgrade core and database
wp core update
wp core update-db
# upgrade plugins
wp plugin update --all
# upgrade themes
wp theme update --all
3- add that script to your crontap using the crontab -e command; you can use http://crontab-generator.org to generate one if you’re not familiar with the syntax
I have my cron running this script each mid month
0 0 */15 * * /user/scripts/update-wordpress.sh > /var/log/wp-update.log
my real working version is slightly different; for example I like to do a health check after an update to check if my server is down.
You may not want to auto-update if you run complex stuff; I don’t know it’s up to you to tweak it 🙂