Skip to content

Instantly share code, notes, and snippets.

@gedex
Created September 23, 2018 16:31
Show Gist options
  • Save gedex/4bedfc08127985f608f990b14de851ce to your computer and use it in GitHub Desktop.
Save gedex/4bedfc08127985f608f990b14de851ce to your computer and use it in GitHub Desktop.
#!/bin/bash
error() {
echo "$1"
exit 1
}
get_transient_names() {
local prefix="_transient_$1*"
local transients="$(wp option list --transients --search="$prefix" --field=option_name)"
for transient in ${transients}; do
if [[ "$transient" = $prefix* ]]; then
echo "${transient:11}"
fi
done
}
delete_transient() {
local transient="$1"
echo "wp delete transient ${transient}"
wp transient delete $transient
}
main() {
local prefixes=(
"wccom_vendor_reports_batches_"
"wccom_vendor_reports_batch_data_"
"wccom_vendor_data_"
)
for prefix in ${prefixes[@]}; do
echo "Get transients prefixed with ${prefix}..."
local transients=$(get_transient_names $prefix)
if [[ -z "${transients}" ]]; then
echo "No transient found."
fi
for transient in ${transients}; do
delete_transient $transient
done
done
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment