I use LocalWP to run WordPress locally, and I made a command to reset a site while keeping the themes and some plugins so I can quickly run various tests.
#!/usr/bin/env sh
# Configuration variables
SITE_URL="test.local"
ADMIN_USER="kossmann"
ADMIN_PASSWORD="kossmann"
ADMIN_EMAIL="dev-email@dev-domain.local"
THEME="twentytwentyfour"
LANGUAGE="en_US"
# Delete plugins, but keep the ones I need: starting with dk-, auto-login and index.php
find wp-content/plugins/ -mindepth 1 -maxdepth 1 -type d ! -name 'dk-*' ! -name 'auto-login' ! -name 'index.php' -exec trash {} +;
# Delete everything in wp-content except plugins/ and themes/
find wp-content/ -mindepth 1 -maxdepth 1 -type d ! -name 'plugins' ! -name 'themes' -exec trash {} +;
# Reset database
wp db reset --yes;
# Install WordPress
wp core install --url="$SITE_URL" --title="" --admin_user="$ADMIN_USER" --admin_password="$ADMIN_PASSWORD" --admin_email="$ADMIN_EMAIL";
# Activate all plugins
wp plugin activate --all;
# Activated desired theme
wp theme activate ${THEME};
# Set language, useful for testing internationalization
wp language core install ${LANGUAGE} --activate;
local-wp-reset.shFor the script above, I used the steps from my previous guides about removing files (except certain subfolders) and using the trash command.
I’ve added this script to a GitHub repository called wp-tools, which I created to share my WordPress tools.
🤖 Clarification on the use of Artificial Intelligence in this content
- 📝 AI used for: text correction;
- 🧠 Model: ChatGPT 4.1;
- 🧐 Human Reviewed: Yes.
Leave a Reply