Half Manual Automated WordPress Site Upgrade Script

by | Sep 8, 2021 | IT Tips, Wordpress | 0 comments

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# 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

Submit a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.