Skip to content

Instantly share code, notes, and snippets.

@jbuchbinder
Last active August 26, 2016 16:57
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jbuchbinder/7419000 to your computer and use it in GitHub Desktop.
WP deprecated function check
#!/bin/bash
#
# Wordpress Deprecated function checker
#
# Version: 0.2
#
# Author: Michiel Roos <michiel@donationbasedhosting.org>
# Jeff Buchbinder (https://github.com/jbuchbinder)
#
# www.php.net/manual/en/migration53.deprecated.php
#
# Original code: http://www.typofree.org/article/archive/2011/may/title/check-your-php-code-for-deprecated-ini-directives-and-functions/
#
# Jeff's notes:
#
# *) This version should return a non-zero bash "errorlevel" if deprecated
# functions are found, which should allow easy integration into CI systems.
# *) This was adapted from a deprecated function checker to allow Wordpress
# specific pre-upgrade checks.
tag=$1
if [ "$tag" == "" ]; then
echo "Wordpress version must be specified."
exit 1
fi
whereami="$( cd "$(dirname "$0")"; pwd )"
function dfunctions() {
tag=$1
# Derived from the list at http://codex.wordpress.org/Category:Deprecated_Functions
# (Use Coral Cache to cut down on Wordpress TRAC load.)
deprecated_sources=(
http://core.trac.wordpress.org.nyud.net/browser/tags/${tag}/src/wp-includes/deprecated.php?format=txt
http://core.trac.wordpress.org.nyud.net/browser/tags/${tag}/src/wp-admin/includes/deprecated.php?format=txt
http://core.trac.wordpress.org.nyud.net/browser/tags/${tag}/src/wp-includes/pluggable-deprecated.ph?format=txt
http://core.trac.wordpress.org.nyud.net/browser/tags/${tag}/src/wp-includes/ms-deprecated.php?format=txt
http://core.trac.wordpress.org.nyud.net/browser/tags/${tag}/src/wp-admin/includes/ms-deprecated.php?format=txt
)
for s in ${deprecated_sources}; do
wget -q -O /dev/stdout "$s" | grep '^function ' | cut -d' ' -f2 | cut -d'(' -f 1
done
}
deprecatedFunctions=(
$( dfunctions ${tag} )
)
len=${#deprecatedFunctions[*]}
i=0
echo "Checking for deprectated functions ______________________________________"
echo ""
found=0
while [ $i -lt $len ]; do
echo " // checking for '${deprecatedFunctions[$i]}()'"
grep -rn --color --include=*.php "^[^#\/]*[^a-zA-Z_]${deprecatedFunctions[$i]}[[:space:]]*(" *;
if [ $? -ne 0 ]; then
found=1
fi
echo ""
let i++
done
exit $found
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment