v-change-wordpress-admin-passwords: ability to run v-run-wp-cli on choosen PHP version

This commit is contained in:
Peca 2025-07-11 10:34:38 +02:00
commit acc87125f0

View file

@ -25,9 +25,9 @@ WP_PATH="/home/$USER/web/$DOMAIN/public_html"
# WP-CLI wrapper
if [ ! -z "$PHP" ]; then
WP_RUN=(PHP=$PHP /usr/local/vesta/bin/v-run-wp-cli $DOMAIN --skip-plugins --skip-themes)
WP_RUN="PHP=$PHP /usr/local/vesta/bin/v-run-wp-cli $DOMAIN --skip-plugins --skip-themes"
else
WP_RUN=(/usr/local/vesta/bin/v-run-wp-cli $DOMAIN --skip-plugins --skip-themes)
WP_RUN="/usr/local/vesta/bin/v-run-wp-cli $DOMAIN --skip-plugins --skip-themes"
fi
return_code=$?
@ -54,9 +54,9 @@ if [ -f /home/$USER/web/$DOMAIN/wp-admin-password-change.txt ]; then
rm /home/$USER/web/$DOMAIN/wp-admin-password-change.txt
fi
ADMIN_LIST_CSV=$("${WP_RUN[@]}" user list --role=administrator \
--fields=ID,user_login,user_email \
--format=csv --skip-plugins --skip-themes 2>/dev/null | tail -n +2)
RUN="$WP_RUN user list --role=administrator --fields=ID,user_login,user_email --format=csv --skip-plugins --skip-themes 2>/dev/null | tail -n +2"
ADMIN_LIST_CSV=$(eval "$RUN")
[ -z "$ADMIN_LIST_CSV" ] && { echo "No administrator accounts found."; exit 0; }
printf "%-6s %-20s %s\n" "ID" "Username" "Email"
@ -98,7 +98,8 @@ while IFS=',' read -r ID LOGIN EMAIL; do
echo "Invalid username. Please choose one of: ${OTHER_USERS[*]}"
done
# delete by username, reassign by username
"${WP_RUN[@]}" user delete "$LOGIN" --reassign="$REASSIGN" --yes --skip-plugins --skip-themes
RUN="$WP_RUN user delete $LOGIN --reassign=$REASSIGN --yes --skip-plugins --skip-themes"
eval "$RUN"
if [ $? -eq 0 ]; then
echo "$TARGET deleted (content reassigned to $REASSIGN)."
else
@ -112,7 +113,8 @@ while IFS=',' read -r ID LOGIN EMAIL; do
;;
[Cc]* )
NEW_PASS=$(gen_pass)
"${WP_RUN[@]}" user update "$LOGIN" --user_pass="$NEW_PASS" --skip-plugins --skip-themes
RUN="$WP_RUN user update $LOGIN --user_pass=$NEW_PASS --skip-plugins --skip-themes"
eval "$RUN"
if [ $? -eq 0 ]; then
echo "Password for username '$TARGET' changed to: $NEW_PASS"
echo "Password for username '$TARGET' changed to: $NEW_PASS" >> /home/$USER/web/$DOMAIN/wp-admin-password-change.txt
@ -145,9 +147,12 @@ echo "-------------------------------------"
echo
echo "Flushing cache and refreshing salts..."
"${WP_RUN[@]}" cache flush
"${WP_RUN[@]}" config shuffle-salts WP_CACHE_KEY_SALT --force
"${WP_RUN[@]}" config shuffle-salts
RUN="$WP_RUN cache flush"
eval "$RUN"
RUN="$WP_RUN config shuffle-salts WP_CACHE_KEY_SALT --force"
eval "$RUN"
RUN="$WP_RUN config shuffle-salts"
eval "$RUN"
echo "Cache flushed and salts refreshed."