Created
October 23, 2019 19:30
-
-
Save eksiscloud/1469b3c36218e33d83c3cb79f45ff9af to your computer and use it in GitHub Desktop.
Wordpress: Restore active widgets and locations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Restore your widgets after tried new theme | |
# | |
# https://guides.wp-bullet.com/using-wp-cli-backup-restore-wordpress-widgets/ | |
# | |
# loop through widget backups | |
for WIDGETBACKUP in /tmp/widgets/*.txt | |
do | |
# extract filename | |
WIDGETFILE=$(basename ${WIDGETBACKUP}) | |
# get filename only without extension | |
WIDGET="${WIDGETFILE%%.*}" | |
# output which widget is being updated | |
#echo "$WIDGET" | |
# show widget backup contents | |
#cat ${WIDGETBACKUP} | |
WIDGETTEST=$(wp option get ${WIDGET} --allow-root) | |
if [[ ! -z "$WIDGETTEST" ]]; then | |
wp option update ${WIDGET} --format=json --allow-root < ${WIDGETBACKUP} | |
else | |
wp option add ${WIDGET} --format=json --allow-root < ${WIDGETBACKUP} | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Remember backup first:
https://gist.github.com/eksiscloud/49a42959d6d5194004772211e6a3c396