-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser-delete.sh
More file actions
executable file
·78 lines (65 loc) · 2.75 KB
/
user-delete.sh
File metadata and controls
executable file
·78 lines (65 loc) · 2.75 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/env bash
# This interactive script deletes a given user by their ID and reattributes their content to another
# user based on the provided ID.
source 'source/includes.sh';
echo;
echo 'You are about to delete a user and attribute any content they may have to another use.';
echo;
echo 'You may exit any time with Ctrl+c';
echo;
# Prompt the user for the ID to DELETE.
while [[ -z "$user_id_delete" || "$user_id_delete" =~ re'^[0-9]+$' ]]; do
read -p 'User ID to delete: ' user_id_delete;
done;
# Prompt for the attribution user.
while [[ -z "$user_id_attribute" || "$user_id_attribute" =~ re'^[0-9]+$' ]]; do
read -p 'User ID to attribute content to: ' user_id_attribute;
done;
# Prompt for a site ID or no site ID to get all.
#
# In some cases we may just want to remove them from a single site instead of the entire network.
while [[ -z "$site_id" || "$site_id" =~ re'^[0-9]+$' ]]; do
read -p 'Site ID to delete the user from (999 for every site) : ' site_id;
done;
# Prompt for the site ID to delete the user from.
if [[ 999 = $site_id ]]; then
sites=$(wp_skip_all site list --field="url" --archived=0);
sites_name='All sites in the WP network';
else
sites=$(wp_skip_all site list --field="url" --site__in=${site_id});
sites_name="$sites";
fi
echo;
# Add human readable info for the user to be deleted.
user_name_delete=$(wp_skip_all user get ${user_id_delete} --field="display_name");
# user_login_delete=$(wp_skip_all user get ${user_id_delete} --field="user_login");
# Add human readable info for the user to get attribution of content.
user_name_attribute=$(wp_skip_all user get ${user_id_attribute} --field="display_name");
# user_login_attribute=$(wp_skip_all user get ${user_id_attribute} --field="user_login");
# Confirm before moving on.
while [[ -z "$confirmed" ]]; do
echo '* WARNING! *******************************************************************************';
echo '******************************************************************************************';
echo '* You are about delete a user!';
echo '******************************************************************************************';
echo;
echo "User to delete: ${user_id_delete} (${user_name_delete})";
echo "Attribute content to: ${user_id_attribute} (${user_name_attribute})";
echo "Site ID: ${site_id} (${sites_name})";
echo;
read -p "Continue? [y/n]: " confirmed;
echo;
done;
case $confirmed in
n|N)
echo;
echo 'You have decided not to continue. No data will be changed. Bye.';
exit;
;;
esac
# Loop through every site individually. Using the --network flag in `wp user delete` will not let
# you reattribute content.
echo 'Removing the user...';
for site in $sites; do
wp_skip_all user delete $user_id_delete --reassign="${user_id_attribute}" --url="${site}" ;
done;