-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-reset-admin-user
executable file
·58 lines (42 loc) · 1.39 KB
/
wp-reset-admin-user
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env sh
BASH_LIB=bash.lib
. ${BASH_LIB}
if [[ $# != 2 ]]
then
cat << EOF
Resets the admin username (including the user_login), password, and email for the WP instance in the current directory.
usage: ${SELF} <username> <password>
EOF
exit
fi
${WP} core is-installed --path=. > /dev/null
if [[ $? == 1 ]]
then
echo
echo The current directory does not contain a WordPress installation. Aborting...
echo
exit
fi
NEW_USER=${1}
NEW_PASS=${2}
NEW_EMAIL="YOUR EMAIL HERE"
ID=1
# get database table prefix
DB_PREFIX=$(wp db prefix)
# add test to ensure the current directory contains a wp installation
sql="update ${DB_PREFIX}users set user_login='${NEW_USER}' where ID=1"
echo
echo Updating user info...
echo ${WP} user update ${ID} --user_nicename=${NEW_USER} --display_name=${NEW_USER} --nickname=${NEW_USER} --user_pass=${NEW_PASS} --user_email=${NEW_EMAIL} --skip-email
${WP} user update ${ID} --user_nicename=${NEW_USER} --display_name=${NEW_USER} --nickname=${NEW_USER} --user_pass=${NEW_PASS} --user_email=${NEW_EMAIL} --skip-email
echo
echo Updating user_login...
echo ${WP} db query \"$sql\"
${WP} db query "$sql"
echo
echo Getting user info for \"${NEW_USER}\" \(ID: ${ID}\)...
echo ${WP} user list --include=${ID} --fields=user_login,display_name,user_email
${WP} user list --include=${ID} --fields=user_login,display_name,user_email
echo
echo ...done.
echo