From 461dde94f0af88e8a7e5f6a227d31d973617d4f9 Mon Sep 17 00:00:00 2001 From: Jason Raveling Date: Mon, 26 Jan 2026 10:49:21 -0600 Subject: [PATCH 1/2] fix(permissions): makes file executable --- user-create.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 user-create.sh diff --git a/user-create.sh b/user-create.sh old mode 100644 new mode 100755 From 2d941a7f45bd6b6a6c22310af23384fe7079927d Mon Sep 17 00:00:00 2001 From: Jason Raveling Date: Mon, 26 Jan 2026 14:40:27 -0600 Subject: [PATCH 2/2] feat(user rename): add user rename script --- user-create.sh | 2 +- user-rename.sh | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100755 user-rename.sh diff --git a/user-create.sh b/user-create.sh index cd6fc60..ae2cde8 100755 --- a/user-create.sh +++ b/user-create.sh @@ -74,7 +74,7 @@ while IFS="," read -r username email role superadmin; do else - # Output any errors from WPCLI. + # Output any errors from WPCLI for the user creation. >&2 fi diff --git a/user-rename.sh b/user-rename.sh new file mode 100755 index 0000000..b64b5ec --- /dev/null +++ b/user-rename.sh @@ -0,0 +1,65 @@ +#!/bin/env bash + +# Renames user(s) to any given string. +# +# Use caution! The new name can be a non-standard WP username, with any characters. + +source 'source/includes.sh'; + +# Prompt the user for the path to a CSV with username and email. +read -r -p 'Path to CSV file with users [./user-rename.csv]: ' csv_path; + +# Set default value if empty string provided. +[[ -z "$csv_path" ]] && csv_path='./user-rename.csv'; + +# Ensure the file actually exists. +if [[ ! -f "$csv_path" ]]; then + + echo "The file you provided does not exist: ${csv_path}"; + exit 1; + +fi + +###################################################### +# Read the CSV and update the user(s) +###################################################### + +# Init the user counter. +user_count=0; + +# Loop over the entire CSV file. +while IFS="," read -r old_username new_username; do + + echo "Changing username: ${old_username}"; + + # Ensure the user exists by getting the user ID. + if user_id=$(wp_skip_all user get "${old_username}" --field=ID >&1 ); then + + # Set the SQL query for updating the current user's username and nicename. + user_update_query="UPDATE wp_users SET user_login = '${new_username}', user_nicename = '${new_username}' WHERE ID = '${user_id}'"; + + # Update the username and check the status of the change. + if $(wp_skip_all db query "$user_update_query" >&1 ); then + + # Update the count for each successful user creation. + ((user_count++)); + + echo "Changed to: ${new_username}"; + + else + + # Output any errors from WPCLI from the query. + >&2 + + fi + + else + + # Output any WPCLI error related to checking if the user exists. + >&2; + + fi + +done < "$csv_path" + +echo "Users updated: ${user_count}";