Skip to content

Instantly share code, notes, and snippets.

@insanedefaults
Last active August 29, 2015 14:23
Show Gist options
  • Save insanedefaults/ef029c5094540b5e89cc to your computer and use it in GitHub Desktop.
Save insanedefaults/ef029c5094540b5e89cc to your computer and use it in GitHub Desktop.
Turns off a given plugin for each subsite on a WordPress multisite. This is useful if the plugin isn't activated network-wide.
$ turnoffplugin query-monitor
site.com/ :: Success: Plugin 'query-monitor' deactivated.
test.site.com/ :: not deactivating, plugin status is inactive
test2.site.com/ :: not deactivating, plugin status is inactive
$ turnoffplugin query-monitor
site.com/ :: not deactivating, plugin status is inactive
test.site.com/ :: not deactivating, plugin status is inactive
test2.site.com/ :: not deactivating, plugin status is inactive
function turnoffplugin() {
#pass the name of the plugin to this function as the first and only argument
subsites=$(wp site list --field=url)
target=$1
#target is the first argument to this function and the plugin to turn off
for subsite in $subsites; do
#check if the plugin is installed on this subsite
plugin_status=""
plugin_status=$(wp plugin list --name=$target --field=status)
if [[ ! -z $plugin_status ]]; then
#check if the plugin is active
if [[ "active" == $plugin_status ]]; then
echo "$subsite :: $(wp plugin deactivate $target --url=$subsite)"
else
echo "$subsite :: not deactivating, plugin status is $plugin_status"
fi
else
echo "$subsite :: the plugin isn't installed on this subsite"
fi
done 2>&1 | grep -Ev "PHP [NW]"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment