This script finds all your wordpress sites under a specific parent directory and then loops through them and prompts you to accept or reject an upgrade for plugins, themes and wordpress core.
# find all WordPress installs
WP_SITES=`find /path/to/your/sites/root -regex '.*web/wp-config\.php'`
# path to wp-cli
WP=/usr/local/bin/wp
for i in $WP_SITES
do
# get the full path to the wp install
WP_DIR=$(dirname $i)
# get the owner so we run the upgrade as the correct user
OWNER=`stat -c %U $WP_DIR`
echo "Owner $OWNER"
# so we can echo the installation we are upgrading
SITE_URL=`$WP --path=$WP_DIR option get siteurl`
# list the plugins and available upgrades
$WP --path=$WP_DIR plugin list
echo -n "Do you want to update all plugins for $SITE_URL: [N/y] "
read R
case $R in
Y|y)
echo "Running update all plugins for $SITE_URL"
sudo -u $OWNER $WP --path=$WP_DIR plugin update --all
;;
*)
echo "Skipping update all for $SITE_URL"
;;
esac
# next do themes
$WP --path=$WP_DIR theme list
echo -n "Do you want to update all themes for $SITE_URL: [N/y] "
read R
case $R in
Y|y)
echo "Running update of all themes for $SITE_URL"
sudo -u $OWNER $WP --path=$WP_DIR theme update --all
;;
*)
echo "Skipping update of all themes for $SITE_URL"
;;
esac
# finally wordpress core update
$WP --path=$WP_DIR core check-update
echo -n "Do you want to update wp core for $SITE_URL: [N/y] "
read R
case $R in
Y|y)
echo "Running wp core update for $SITE_URL"
sudo -u $OWNER $WP --path=$WP_DIR core update
;;
*)
echo "Skipping update of core for $SITE_URL"
;;
esac
done
0 Comments