@@ -37,6 +37,17 @@ trim_value() {
3737 echo " $1 " | sed -E ' s/^[[:space:]]+//; s/[[:space:]]+$//'
3838}
3939
40+ is_truthy () {
41+ case " $( echo " ${1:- } " | tr ' [:upper:]' ' [:lower:]' ) " in
42+ 1|true|yes|on)
43+ return 0
44+ ;;
45+ * )
46+ return 1
47+ ;;
48+ esac
49+ }
50+
4051plugins_config_exists () {
4152 [ -n " $( trim_value " ${WORDPRESS_SETUP_CONFIG_YAML:- } " ) " ]
4253}
@@ -127,6 +138,46 @@ sync_site_urls() {
127138 replace_url_occurrences " ${prod_host} " " ${local_host} "
128139}
129140
141+ reset_local_user_passwords () {
142+ local reset_all_users=" ${WORDPRESS_LOCAL_RESET_ALL_USERS_PASSWORDS:- 0} "
143+ local target_user
144+ local shared_password=" ${WORDPRESS_LOCAL_USERS_PASSWORD:- } "
145+ local user_id
146+
147+ target_user=" $( trim_value " ${WORDPRESS_LOCAL_RESET_PASSWORD_FOR_USER:- } " ) "
148+
149+ if [ -z " $shared_password " ]; then
150+ echo " WORDPRESS_LOCAL_USERS_PASSWORD not set; skipping local user password reset."
151+ return
152+ fi
153+
154+ if is_truthy " $reset_all_users " ; then
155+ echo " Resetting password for all local WordPress users..."
156+ while IFS= read -r user_id; do
157+ user_id=" $( trim_value " $user_id " ) "
158+ if [ -z " $user_id " ]; then
159+ continue
160+ fi
161+ runuser -u www-data -- wp user update " $user_id " --user_pass=" $shared_password " > /dev/null
162+ done < <( runuser -u www-data -- wp user list --field=ID)
163+ echo " ✓ Password reset completed for all users"
164+ return
165+ fi
166+
167+ if [ -n " $target_user " ]; then
168+ echo " Resetting password for local WordPress user '$target_user '..."
169+ if runuser -u www-data -- wp user get " $target_user " --field=ID > /dev/null 2>&1 ; then
170+ runuser -u www-data -- wp user update " $target_user " --user_pass=" $shared_password " > /dev/null
171+ echo " ✓ Password reset completed for user '$target_user '"
172+ else
173+ echo " ⚠ User '$target_user ' not found; skipping password reset"
174+ fi
175+ return
176+ fi
177+
178+ echo " No local password reset target configured; set WORDPRESS_LOCAL_RESET_ALL_USERS_PASSWORDS=1 or WORDPRESS_LOCAL_RESET_PASSWORD_FOR_USER."
179+ }
180+
130181install_plugin () {
131182 local plugin_slug=" $1 "
132183
@@ -312,6 +363,7 @@ echo "Installing plugins and themes..."
312363
313364if wordpress_is_installed; then
314365 sync_site_urls
366+ reset_local_user_passwords
315367
316368 if plugins_config_exists; then
317369 install_org_plugins_from_config
0 commit comments