Skip to content

Instantly share code, notes, and snippets.

@ramiabraham
Last active August 23, 2016 20:41
Show Gist options
  • Save ramiabraham/faca4e3c26703397b2cc513be358bab1 to your computer and use it in GitHub Desktop.
Save ramiabraham/faca4e3c26703397b2cc513be358bab1 to your computer and use it in GitHub Desktop.
Get AffiliateWP version
#!/bin/bash
# Plugin version checker.
#
# Requirements:
# - WP-CLI
__get_affwp_v() {
wp plugin list --name='affiliate-wp' --version --format=json --allow-root
}
__json_value() {
awk -F"[,:}]" '{for(i=1;i<=NF;i++){if($i~/version\042/){print $(i+1)}}}' | tr -d '"' | sed -n 1p
}
if type "wp" > /dev/null; then
echo "WP-CLI located..."
else
echo "WP-CLI is required." && exit
fi
__get_bc() {
if type "bc" > /dev/null; then
echo 'bc command located'
else
echo "Installing bc command..." &&
apt-get install bc && echo "Success!"
fi
}
__affwp_v() {
__get_bc &&
__get_affwp_v | __json_value
}
__affwp_v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment