Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save technicalogical/83a361863c05ea2cddd771319907b2be to your computer and use it in GitHub Desktop.
Save technicalogical/83a361863c05ea2cddd771319907b2be to your computer and use it in GitHub Desktop.
Fix MWP prefixes for usermeta and options table
# Regular Colors
BLACK=`tput setaf 0`
RED=`tput setaf 1`
GREEN=`tput setaf 2`
YELLOW=`tput setaf 3`
BLUE=`tput setaf 4`
MAGENTA=`tput setaf 5`
CYAN=`tput setaf 6`
WHITE=`tput setaf 7`
BOLD=`tput bold`
RESET=`tput sgr0`
TODAY=`date +"%d%b%Y"`
currentConfig=$(wp config get table_prefix)
dbUser=$(wp config get DB_USER)
dbPass=$(wp config get DB_PASSWORD)
mySQL="mysql -u ${dbUser} -p${dbPass} --host=dhh842555562263.db.42555562.69a.hostedresource.net --port=3310 dhh842555562263"
query="UPDATE ${currentConfig}usermeta SET ${currentConfig}usermeta.meta_key = '${currentConfig}capabilities' WHERE ${currentConfig}usermeta.meta_key LIKE '%_capabilities';
UPDATE ${currentConfig}usermeta SET ${currentConfig}usermeta.meta_key = '${currentConfig}user_level' WHERE ${currentConfig}usermeta.meta_key LIKE '%_user_level';
UPDATE ${currentConfig}options SET ${currentConfig}options.option_name = '${currentConfig}user_roles' WHERE ${currentConfig}options.option_name LIKE '%_user_roles';"
backup=$(wp db export htlBackup${TODAY}.sql)
echo +++++++user_meta prefix fixer upper++++++++
echo The current table prefix in the wp-config is: ${GREEN}$currentConfig${RESET}
echo The database user is: ${GREEN}$dbUser${RESET}
echo The database password is: ${GREEN}$dbPass${RESET}
while true; do
read -p "Do you want to update the database?" yn
case $yn in
[Yy]* ) echo $backup; break; $query | ${mySQL} ; break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment