Skip to content

Instantly share code, notes, and snippets.

@eksiscloud
Created October 23, 2019 19:26
Show Gist options
  • Save eksiscloud/49a42959d6d5194004772211e6a3c396 to your computer and use it in GitHub Desktop.
Save eksiscloud/49a42959d6d5194004772211e6a3c396 to your computer and use it in GitHub Desktop.
Wordpress: Backup active widgets and locations
#!/usr/bin/env bash
#
# Backup your widgets before you give a try to new theme
#
# https://guides.wp-bullet.com/using-wp-cli-backup-restore-wordpress-widgets/
#
# create array of all widgets in the wp_options table
WIDGETSARRAY=($(wp db query "SELECT option_name FROM $(wp db prefix --allow-root)options WHERE option_name LIKE 'widget\_%'" --skip-column-names --allow-root))
# loop through widgets
for WIDGET in ${WIDGETSARRAY[@]}
do
wp option get ${WIDGET} --format=json --allow-root > /tmp/widgets/${WIDGET}.txt
done
@eksiscloud
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment