|

WP-CLI for Updates

Note that this is at an extremely introductory level. If you’re looking for more advanced help, there are many other resources elsewhere, including the one linked at the end.

I’ve recently most most of my sites from cPanel/WHM to Cyberpanel. I will post some notes on transferring sites. There are many excellent resources, but also quite a number of potential pitfalls.

If you are using Cyberpanel without any add-ons, one issue is updating multiple WordPress sites. With the appropriate add-on, this can be done from Cyberpanel, but I found that this doesn’t always suit my needs, simple as they are! Note that I strongly recommend the all addons option for Cyberpanel. It’s only $7.99 per month, last I checked, and it adds some handy tools, while still leaving the overall cost well below cPanel.

Now to the point. I do only managed WordPress sites, almost all for authors with my company Energion Publications. One key requirement I have is that all be regularly updated. This is for security reasons. To make sure this happens, I need to be able to check/update all the WordPress sites on a server. For my small number of sites, this is not that difficult.

I wrote a short bash script that I can run. I use a source file with user names and paths. The reason for the source file is that there are both sites that are not WordPress on my server, and also WordPress sites for which I may be holding certain updates.

Here’s the code:

#!/usr/bin/bash
echo "Update WP sites: " `date`

while read line
do
   echo $line
   pieces=($line)
   sudo -u ${pieces[1]} wp core update --path=${pieces[0]}
   sudo -u ${pieces[1]} wp plugin update --all --path=${pieces[0]}
   sudo -u ${pieces[1]} wp theme update --all --path=${pieces[0]}
done < wpsites.txt

You will, of course, need to update the first line to match your system. Here’s the control file:

/home/path-to-your-site-html siteuser

You can add however many lines.

A more advanced system could scan for sites, users, and WordPress installations, but that’s one of the things Cyberpanel does for you, as well as various more advanced scripts.

This script can be run by hand or added as a cron job. If you do that, you will doubtless want to redirect output to a suitable file.

Some instructions. These come from GoDaddy, but they have key commands.

In case you were wondering, the code in the featured image is not bash!!

Similar Posts

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.