2023-03-31 10:17:34 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2023-04-28 09:18:28 +02:00
|
|
|
show-help() {
|
|
|
|
echo -e "\nDelete all posts -p [post type]"
|
|
|
|
echo -e "\tExample: ddev wp-cleanup -p shop_order,product"
|
|
|
|
echo -e "\nDelete all logs -l [wp-content path]"
|
|
|
|
echo -e "\tExample: ddev wp-cleanup -l uploads/wc-logs\n"
|
2023-03-31 10:17:34 +02:00
|
|
|
}
|
|
|
|
|
2023-03-31 12:02:56 +02:00
|
|
|
delete-posts() {
|
2023-03-31 10:17:34 +02:00
|
|
|
for post in $(wp post list --post_type=$1 --format=ids --path=.ddev/wordpress); do
|
2023-03-31 10:21:56 +02:00
|
|
|
wp post delete $post --force --path=.ddev/wordpress
|
|
|
|
done
|
2023-03-31 10:17:34 +02:00
|
|
|
}
|
|
|
|
|
2023-03-31 12:02:56 +02:00
|
|
|
delete-logs() {
|
|
|
|
rm .ddev/wordpress/wp-content/$1/*.log
|
|
|
|
}
|
|
|
|
|
|
|
|
declare -i param_counter=0
|
2023-03-31 10:17:34 +02:00
|
|
|
|
2023-03-31 12:20:54 +02:00
|
|
|
while getopts "p:l:h" arg; do
|
2023-03-31 10:21:56 +02:00
|
|
|
case $arg in
|
2023-03-31 12:20:54 +02:00
|
|
|
p)
|
2023-03-31 12:07:12 +02:00
|
|
|
delete-posts $OPTARG
|
|
|
|
param_counter+=1
|
|
|
|
;;
|
|
|
|
l)
|
|
|
|
delete-logs $OPTARG
|
|
|
|
param_counter+=1
|
|
|
|
;;
|
2023-04-28 09:18:28 +02:00
|
|
|
h) show-help ;;
|
2023-03-31 10:21:56 +02:00
|
|
|
esac
|
2023-03-31 10:17:34 +02:00
|
|
|
done
|
|
|
|
|
2023-03-31 12:02:56 +02:00
|
|
|
if [ $param_counter -eq 0 ]; then
|
2023-04-28 09:18:28 +02:00
|
|
|
show-help
|
2023-03-31 10:17:34 +02:00
|
|
|
fi
|