-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-rename-plugin
executable file
·63 lines (50 loc) · 1.25 KB
/
wp-rename-plugin
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
59
60
61
62
63
#!/usr/bin/env sh
SELF=${0##*/}
if [[ $# != 2 ]]
then
cat << EOF
usage: ${SELF} <old directory> <new directory>
EOF
exit
fi
OLD_FOLDER_NAME=${1}
NEW_FOLDER_NAME=${2}
WP=$(which wp)
MV=$(which mv)
if [[ ${WP} == '' ]]
then
echo
echo WP CLI \(https://wp-cli.org\) is not installed. Aborting...
echo
exit 3
fi
if [[ ! -d "${OLD_FOLDER_NAME}" ]]
then
echo
echo The folder \"${OLD_FOLDER_NAME}\" does not exist. Aborting...
echo
exit 1
fi
if [[ -d "${NEW_FOLDER_NAME}" ]]
then
echo
echo The destination folder \"${NEW_FOLDER_NAME}\" exists. Aborting...
echo
exit 2
fi
table_prefix=$(${WP} config get table_prefix)
echo Backing up database...
echo ${WP} db export
${WP} db export
echo
echo Renaming folder...
echo ${MV} ${OLD_FOLDER_NAME} ${NEW_FOLDER_NAME}
${MV} ${OLD_FOLDER_NAME} ${NEW_FOLDER_NAME}
echo
# https://wordpress.stackexchange.com/questions/267245/how-to-update-an-array-option-using-wp-cli
echo Updating ${table_prefix}options...
echo ${WP} option get active_plugins --format=json \| sed \"s/${OLD_FOLDER_NAME}/${NEW_FOLDER_NAME}/\" \| ${WP} option set active_plugins --format=json
${WP} option get active_plugins --format=json | sed "s/${OLD_FOLDER_NAME}/${NEW_FOLDER_NAME}/" | ${WP} option set active_plugins --format=json
echo
echo ...done.
echo