v-change-wordpress-admin-passwords: modified user deletion and password update commands to use user ID instead of username.

This commit is contained in:
Peca 2025-07-14 16:32:21 +02:00
commit 98600537fc
2 changed files with 19 additions and 2 deletions

View file

@ -12,6 +12,11 @@ if [ "$whoami" != "root" ]; then
exit 1 exit 1
fi fi
if [ "$#" -lt 4 ]; then
echo "Usage: v-add-wordpress-admin [DOMAIN] [USERNAME] [PASSWORD] [EMAIL]"
exit 1
fi
# Importing system environment # Importing system environment
source /etc/profile source /etc/profile

View file

@ -106,7 +106,7 @@ while IFS=',' read -r ID LOGIN EMAIL; do
echo "Invalid username. Please choose one of: ${OTHER_USERS[*]}" echo "Invalid username. Please choose one of: ${OTHER_USERS[*]}"
done done
# delete by username, reassign by username # delete by username, reassign by username
RUN="$WP_RUN user delete $LOGIN --reassign=$REASSIGN --yes --skip-plugins --skip-themes" RUN="$WP_RUN user delete $ID --reassign=$REASSIGN --yes --skip-plugins --skip-themes"
eval "$RUN" eval "$RUN"
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "$TARGET deleted (content reassigned to $REASSIGN)." echo "$TARGET deleted (content reassigned to $REASSIGN)."
@ -121,7 +121,7 @@ while IFS=',' read -r ID LOGIN EMAIL; do
;; ;;
[Cc]* ) [Cc]* )
NEW_PASS=$(gen_pass) NEW_PASS=$(gen_pass)
RUN="$WP_RUN user update $LOGIN --user_pass=$NEW_PASS --skip-plugins --skip-themes" RUN="$WP_RUN user update $ID --user_pass=$NEW_PASS --skip-plugins --skip-themes"
eval "$RUN" eval "$RUN"
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "Password for username '$TARGET' changed to: $NEW_PASS" echo "Password for username '$TARGET' changed to: $NEW_PASS"
@ -147,6 +147,18 @@ while IFS=',' read -r ID LOGIN EMAIL; do
done done
done <<< "$ADMIN_LIST_CSV" done <<< "$ADMIN_LIST_CSV"
if [ -f /home/$USER/web/$DOMAIN/wp-admin-password-change.txt ]; then
echo "-------------------------------------"
echo
read -r -p "Do you want to save the new passwords to a file /home/$USER/web/$DOMAIN/wp-admin-password-change.txt ? (y/n, default: n) " SAVE_PASSWORDS < /dev/tty
if [ -z "$SAVE_PASSWORDS" ]; then
SAVE_PASSWORDS="n"
fi
if [[ $SAVE_PASSWORDS =~ ^[Nn]$ ]]; then
rm /home/$USER/web/$DOMAIN/wp-admin-password-change.txt
fi
fi
#----------------------------------------------------------# #----------------------------------------------------------#
# flush cache and refresh all security salts # # flush cache and refresh all security salts #
#----------------------------------------------------------# #----------------------------------------------------------#