Skip to content

Instantly share code, notes, and snippets.

@laacz
Created April 3, 2014 11:47
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laacz/9952926 to your computer and use it in GitHub Desktop.
Save laacz/9952926 to your computer and use it in GitHub Desktop.
Finds Wordpress installations with outdated cores and/or plugins. If it throws php warnings (wp-cli does so), just redirect do `wp-update-check.sh 2>/dev/null`.
#!/usr/bin/env bash
#
# Script will find all wordpress installs and check if they're out of date
#
# Using wp-cli - http://wp-cli.org/
# Paths to search for wordpresses. Separated by space.
PATHS="/var/www /data/www"
# Paths to ignore (should not be checked). Separated by space.
IGNOREPATHS="/var/www/dev-site /var/www/other-site/backup"
WPCLI=/usr/local/bin/wp-cli
LATESTVERSION=$(curl -s http://api.wordpress.org/core/version-check/1.5/ | head -n 4 | tail -n 1)
WORDPRESSES=$(find $PATHS -type d -name "wp-includes" -print)
# Loop through results
for WPATH in $WORDPRESSES; do
# Strip wp-includes from path
WPATH=$(dirname $WPATH)
# If folder is excluded, continue
if [ "${IGNOREPATHS/$WPATH}" != "$IGNOREPATHS" ]; then
continue;
fi
# Find out version
VERSION=$($WPCLI --allow-root --path=$WPATH core version)
# Compare versions. Do not care about downgrades.
if [ "$LATESTVERSION" != "$VERSION" ]; then
echo "$WPATH Versions differ. Update required $VERSION->$LATESTVERSION"
echo "Fix: $WPCLI --allow-root --path=$WPATH core update"
echo
fi
# List outdated plugins
RESULT=$($WPCLI --allow-root --path=$WPATH plugin status | grep "^[[:space:]]U") && echo "$WPATH Some plugins are outdated:" && echo $RESULT && echo "Fix: $WPCLI --allow-root --path=$WPATH plugin update --all" && echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment