Skip to content

Instantly share code, notes, and snippets.

@Neshable
Created April 28, 2020 16:06
Show Gist options
  • Save Neshable/3cbb765815d0e6afc996eb8fa7a7cba8 to your computer and use it in GitHub Desktop.
Save Neshable/3cbb765815d0e6afc996eb8fa7a7cba8 to your computer and use it in GitHub Desktop.
WordPress Safe Update Through CLI
#!/bin/sh
echo "Starting safe update"
# Display the WordPress version
current_wp_core=$(wp core version --path=./wordpress)
# Update the WordPress version
wp core update
wp core update-db
# Test website if it's ok
status_code=$(curl --write-out %{http_code} --silent --output /dev/null domain.com)
if [[ "$status_code" == 200 ]] ; then
echo "Website status is $status_code . All seems to be working. Continue with updating the plugins .. "
else
echo "Site seems to be broken. Revert back to old version .."
wp core update --version="$current_wp_core" --force
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment