A common customer request I get is to reset a WordPress staging site back to its default state. I’ve done this manually quite a few times and decided I should just script it. The following bash script will drop all database tables, install a fresh copy of WordPress and remove all themes, plugins and uploads. The only thing that needs configured is the
admin_user in order for the WordPress backend to be accessible.
# Reset WordPress to default
url=$( wp option get home )
title=$( wp option get blogname )
wp db reset --yes
wp core download --force
wp core install --url=$url --title="$title" --admin_user=$admin_user --admin_email=$admin_email
wp theme install twentytwentyone --force --activate
wp theme delete $( wp theme list --field=name )
wp plugin delete --all
rm -rf wp-content/mu-plugins/
rm -rf wp-content/uploads/
This works great on Kinsta. Additionally for Kinsta I recommend installing their caching plugin. This can easily be scripted as shown here.
unzip kinsta-mu-plugins.zip -d wp-content/mu-plugins/