Skip to content

Commit b3f07a3

Browse files
authored
UR-4798 Fix - Fall back to basic profile fields for non-UR-form users (#1390)
* UR-4798 Fix - Fall back to basic profile fields for non-UR-form users Non-UR-form users (wp-admin/WooCommerce created, ur_form_id unresolved) had no way to actually save Profile Details - user_registration_form_data() returned an empty profile so the save loop had nothing to write. Adds ur_get_non_urm_user_profile_fields() and uses it as a fallback in update_profile_details() so these users can save Username/First Name/Email/Last Name like any other account. * UR-4798 Fix - Add pending-email notice to non-UR-form profile template Adds the same pending-email-change notice + Cancel link that UR-form fields already get (functions-ur-template.php), so non-UR-form users see and can cancel a pending email change too - previously the notice only appeared via the AJAX success handler, never on a plain page load / non-ajax submit. Placed the notice as the direct next sibling of the <input>, matching where the AJAX success handler looks (input.next('div.email-updated')) so an AJAX save correctly replaces a server-rendered notice instead of leaving a stale duplicate next to the fresh one. Verified via Playwright end-to-end on a fresh non-UR-form test user: ajax save, non-ajax save, reload persistence, and Cancel link all behave correctly with no duplicate notices.
1 parent 4d172ed commit b3f07a3

3 files changed

Lines changed: 84 additions & 1 deletion

File tree

includes/class-ur-ajax.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,11 @@ public static function update_profile_details() {
276276

277277
$profile = user_registration_form_data( $user_id, $form_id );
278278

279+
// No resolvable UR form (e.g. wp-admin/WooCommerce created user) - fall back to basic fields.
280+
if ( empty( $profile ) ) {
281+
$profile = ur_get_non_urm_user_profile_fields( $user_id );
282+
}
283+
279284
if ( empty( $profile ) ) {
280285
wp_send_json_error(
281286
array(

includes/functions-ur-core.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11205,6 +11205,51 @@ function urm_process_profile_fields( $profile, $single_field, $form_data, $form_
1120511205
}
1120611206
}
1120711207

11208+
if ( ! function_exists( 'ur_get_non_urm_user_profile_fields' ) ) {
11209+
/**
11210+
* Fallback profile fields for users with no resolvable UR registration form.
11211+
*
11212+
* @param int $user_id User ID.
11213+
*
11214+
* @return array
11215+
*/
11216+
function ur_get_non_urm_user_profile_fields( $user_id ) {
11217+
if ( ! get_userdata( $user_id ) ) {
11218+
return array();
11219+
}
11220+
11221+
return apply_filters(
11222+
'user_registration_non_urm_user_profile_fields',
11223+
array(
11224+
'user_registration_user_login' => array(
11225+
'label' => __( 'Username', 'user-registration' ),
11226+
'type' => 'text',
11227+
'field_key' => 'user_login',
11228+
'required' => true,
11229+
),
11230+
'user_registration_first_name' => array(
11231+
'label' => __( 'First Name', 'user-registration' ),
11232+
'type' => 'text',
11233+
'field_key' => 'first_name',
11234+
'required' => false,
11235+
),
11236+
'user_registration_user_email' => array(
11237+
'label' => __( 'User Email', 'user-registration' ),
11238+
'type' => 'email',
11239+
'field_key' => 'user_email',
11240+
'required' => true,
11241+
),
11242+
'user_registration_last_name' => array(
11243+
'label' => __( 'Last Name', 'user-registration' ),
11244+
'type' => 'text',
11245+
'field_key' => 'last_name',
11246+
'required' => false,
11247+
),
11248+
),
11249+
$user_id
11250+
);
11251+
}
11252+
}
1120811253

1120911254
if ( ! function_exists( 'urm_update_user_profile_data' ) ) {
1121011255
/**

templates/myaccount/form-edit-profile-non-urm-user.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,40 @@
171171
</div>
172172
<div class="ur-form-grid ur-grid-2" style="width:48%;">
173173
<div class="ur-field-item field-user_email" data-field-id="user_email" data-ref-id="user_registration_user_email">
174-
<div class="form-row validate-required" id="user_registration_user_email_field" data-priority=""><label for="user_registration_user_email" class="ur-label"><?php _e( 'User Email', 'user-registration' ); ?> <abbr class="required" title="required">*</abbr></label> <span class="input-wrapper"> <input data-rules="" data-id="user_registration_user_email" type="email" class="input-text without_icon input-email ur-edit-profile-field " name="user_registration_user_email" id="user_registration_user_email" placeholder="" value="<?php echo $user->user_email; ?>" required="required" data-default="zapoda@mailinator.com"> </span> </div>
174+
<?php
175+
// Same pending-email notice non-ajax UR-form fields get (see functions-ur-template.php).
176+
// Rendered right after the input - matches where the ajax success handler
177+
// looks (input.next('div.email-updated')) so it gets replaced, not duplicated.
178+
$pending_email = get_user_meta( $user_id, 'user_registration_pending_email', true );
179+
$expiration = get_user_meta( $user_id, 'user_registration_pending_email_expiration', true );
180+
$pending_email_notice = '';
181+
182+
if ( ! empty( $pending_email ) && time() <= $expiration ) {
183+
$cancel_url = esc_url(
184+
add_query_arg(
185+
array(
186+
'cancel_email_change' => $user_id,
187+
'_wpnonce' => wp_create_nonce( 'cancel_email_change_nonce' ),
188+
),
189+
ur_get_my_account_url() . get_option( 'user_registration_myaccount_edit_profile_endpoint', 'edit-profile' )
190+
)
191+
);
192+
$pending_email_notice = sprintf(
193+
'<div class="email-updated inline"><p>%s</p></div>',
194+
wp_kses_post(
195+
sprintf(
196+
/* translators: 1: Pending email 2: Cancel link */
197+
__( 'There is a pending change of your email to <code>%1$s</code>. <a href="%2$s">Cancel</a>', 'user-registration' ),
198+
esc_html( $pending_email ),
199+
$cancel_url
200+
)
201+
)
202+
);
203+
} else {
204+
UR_Form_Handler::delete_pending_email_change( $user_id );
205+
}
206+
?>
207+
<div class="form-row validate-required" id="user_registration_user_email_field" data-priority=""><label for="user_registration_user_email" class="ur-label"><?php _e( 'User Email', 'user-registration' ); ?> <abbr class="required" title="required">*</abbr></label> <span class="input-wrapper"> <input data-rules="" data-id="user_registration_user_email" type="email" class="input-text without_icon input-email ur-edit-profile-field " name="user_registration_user_email" id="user_registration_user_email" placeholder="" value="<?php echo $user->user_email; ?>" required="required" data-default="zapoda@mailinator.com"> <?php echo $pending_email_notice; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- already wp_kses_post()'d above. ?></span> </div>
175208
</div>
176209
<div class="ur-field-item field-last_name" data-field-id="last_name" data-ref-id="user_registration_last_name">
177210
<div class="form-row" id="user_registration_last_name_field" data-priority=""><label for="user_registration_last_name" class="ur-label"><?php _e( 'Last Name', 'user-registration' ); ?></label> <span class="input-wrapper"> <input data-rules="" data-id="user_registration_last_name" type="text" class="input-text without_icon input-text ur-edit-profile-field " name="user_registration_last_name" id="user_registration_last_name" placeholder="" value="<?php echo esc_attr( $user->last_name ); ?>" data-default=""> </span> </div>

0 commit comments

Comments
 (0)