This one took me all day. But I got it. I wanted to have a script that could look through all WordPress sites and find if there are outdated themes or plugins. All I need to do is slap it into a cron job and I am good to go!
Here is the BASH code to do it.
UPDATESNEEDED="" for installpath in $(find /var/www -name wp-config.php) do cd $(dirname $installpath) THEMENEEDED=$(php -r 'require_once("./wp-load.php"); delete_site_transient("update_themes"); wp_update_themes(); $new = get_site_transient("update_themes"); echo count($new->response);') if [ ! $THEMENEEDED = 0 ]; then UPDATESNEEDED="$UPDATESNEEDED \n Site $installpath needs $THEMENEEDED theme(s) updated" fi PLUGSNEEDED=$(php -r 'require_once("./wp-load.php"); delete_site_transient("update_plugins"); wp_update_plugins(); $new = get_site_transient("update_plugins"); echo count($new->response);') if [ ! $PLUGSNEEDED = 0 ]; then UPDATESNEEDED="$UPDATESNEEDED \n Site $installpath needs $PLUGSNEEDED plugin(s) updated" fi done if [ -n "$UPDATESNEEDED" ]; then echo -e "$UPDATESNEEDED" | mail -s "Updates are needed" [email protected] fi
I have been needing this script for a while.
What a great find! Nice job!
Thanks very much for writing this and posting it, Jeffrey.
For anybody else who stumbles onto this page, it should be noted that you will want to change line 3 for a cpanel server to the following to reflect the proper server path for user account directories –
> for installpath in $(find /home -name wp-config.php)
Jeffrey – It looks like it ran successfullly for me, but it did complain a bit while executing – any insight on the cause of the errors shown below?
Thanks again!
Mike
./wordpress-check: line 13: [: too many arguments
./wordpress-check: line 21: [: too many arguments
./wordpress-check: line 13: [: too many arguments
./wordpress-check: line 21: [: too many arguments
./wordpress-check: line 13: [: too many arguments
./wordpress-check: line 21: [: too many arguments
./wordpress-check: line 13: [: too many arguments
./wordpress-check: line 21: [: too many arguments
./wordpress-check: line 13: [: too many arguments
./wordpress-check: line 21: [: too many arguments
./wordpress-check: line 13: [: too many arguments
./wordpress-check: line 21: [: too many arguments
./wordpress-check: line 13: [: too many arguments
./wordpress-check: line 21: [: too many arguments
./wordpress-check: line 13: [: too many arguments
./wordpress-check: line 21: [: too many arguments
./wordpress-check: line 13: [: too many arguments
./wordpress-check: line 21: [: too many arguments
./wordpress-check: line 13: [: too many arguments
./wordpress-check: line 21: [: too many arguments
./wordpress-check: line 13: [: too many arguments
./wordpress-check: line 21: [: too many arguments
Not sure what the error is, let me know what line 13 and 21 in your script are. Those line number may not correlate with my line numbers.