Create a gist now

Instantly share code, notes, and snippets.

WordPress Multisite HTTP to HTTPS migration
!/bin/bash
# WordPress Multisite HTTP to HTTPS migration
# Use wp-cli to assist HTTP to HTTPS migration for a WP Multisite installation.
# Update site metadata for the main site as well as each site in the network.
WP_PATH=/var/www
WPCLI_PATH=/home/admin/bin/wp-cli.phar
UPDATE_FIELDS="siteurl home fileupload_url"
# Get list of all sites in network.
SITELIST=$(php $WPCLI_PATH --path=$WP_PATH --quiet site list | awk '{if (NR!=1) {print $2}}' | sed 's/\/$//g')
# Get item count.
SITELIST_COUNT=${#SITELIST[@]}
# Loop through sites and update site metadata.
if [ "$SITELIST_COUNT" -gt "0" ]; then
for SITE in $SITELIST; do
for FIELD in $UPDATE_FIELDS; do
php $WPCLI_PATH --path=$WP_PATH --url=$SITE --user=1 option update $FIELD https://$SITE
done
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment