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 firstname.lastname@example.org admin_user=changeme 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 twentytwenty --force --activate wp theme delete $( wp theme list --field=name ) wp plugin delete --all rm -rf wp-content/mu-plugins/ mkdir wp-content/mu-plugins/ rm -rf wp-content/uploads/ mkdir 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.
wget https://kinsta.com/kinsta-tools/kinsta-mu-plugins.zip unzip kinsta-mu-plugins.zip -d wp-content/mu-plugins/ rm kinsta-mu-plugins.zip