Last active
June 24, 2019 00:54
-
-
Save technicalogical/a1f97eba5381b672b47b60a7fc95be4b to your computer and use it in GitHub Desktop.
HTL MWP fixer script
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
# 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_%H-%M"` | |
currentConfig=$(wp config get table_prefix) | |
dbName=`wp config get DB_NAME` | |
dbUser=`wp config get DB_USER` | |
dbPass=`wp config get DB_PASSWORD` | |
dbHost=`wp config get DB_HOST | cut -d ':' -f 1` | |
dbPort=`wp config get DB_HOST | cut -d ':' -f 2` | |
mySQL="mysql -u ${dbUser} -p${dbPass} --host=${dbHost} --port=${dbPort} ${dbName}" | |
metaQuery="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; } | |
offPlugins () { wp plugin deactivate --all; } | |
onPlugins () { wp plugin activate --all; } | |
addAdmin () { wp user create htl-user [email protected] --role=administrator; } | |
delAdmin () { wp user delete htl-user; } | |
getSiteUrl () { wp option get siteurl; } | |
clearCache () { wp godaddy cache flush && wp cache flush; } | |
showConfig () { wp config get; } | |
prefixFix () { | |
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; echo ${metaQuery} | ${mySQL} ; break;; | |
[Nn]* ) exit;; | |
* ) echo "Please answer yes or no.";; | |
esac | |
done } | |
echo ${CYAN}++++++++++++++++++++++++++++++++++++++++++++++++++${RESET} | |
echo ${CYAN}+++++++++++++++ HTL MWP Fix Script +++++++++++++++${RESET} | |
echo ${CYAN}++++++++++++++++++++++++++++++++++++++++++++++++++${RESET} | |
PS3='Please enter your choice: ' | |
options=("Backup Database" "Turn On Plugins" "Turn Off Plugins" "Fix _usermeta Data" "Create Admin User" "Delete HTL Admin" "Clear Cache" "Show Config" "Quit") | |
select opt in "${options[@]}" | |
do | |
case $opt in | |
"Backup Database") | |
backup | |
;; | |
"Turn Off Plugins") | |
offPlugins | |
;; | |
"Turn On Plugins") | |
onPlugins | |
;; | |
"Fix _usermeta Data") | |
prefixFix | |
;; | |
"Create Admin User") | |
addAdmin | |
;; | |
"Delete HTL Admin") | |
delAdmin | |
;; | |
"Clear Cache") | |
clearCache | |
;; | |
"Show Config") | |
showConfig | |
;; | |
"Quit") | |
break | |
;; | |
*) echo "invalid option $REPLY";; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment