Ultimate member Username edit
-
Hi All,
Our client asked us if we can unlock the “edit your username” field when a visitor updates their profile.
I have selected the options user can edit this field etc but it’s still locked only for the username field.Can you help me with that?
Thank you in advance.Thanos.
-
Unfortunately, this requires customization on your end. You can try the following code snippets to enable the username in the Profile Form:
add_filter("um_user_profile_restricted_edit_fields","um_111921_allow_username_edit"); function um_111921_allow_username_edit( $restricted_fields ){ unset( $restricted_fields[2] ); return $restricted_fields; } add_action("um_submit_form_profile","um_111921_username_validation", 1 ); function um_111921_username_validation( $post_form ){ if( isset( $post_form['user_login'] ) && ! empty( $post_form['user_login'] ) ){ $user = wp_get_current_user(); if( username_exists( $post_form['user_login'] ) && $post_form['user_login'] !== $user->user_login ){ UM()->form()->add_error( 'user_login', __( 'Your username is already taken', 'ultimate-member' ) ); } } } add_action("um_user_after_updating_profile","um_111921_update_username", 9999999, 3 ); function um_111921_update_username( $to_update, $user_id, $args ){ global $wpdb; $user = wp_get_current_user(); $sql = $wpdb->prepare("UPDATE {$wpdb->users} SET user_login = %s WHERE ID = %d", $to_update['user_login'], $user_id ); $wpdb->query($sql); // Log-in again. wp_set_auth_cookie($user->ID); wp_set_current_user($user->ID); do_action('wp_login', $user->user_login, $user); }When you update the username, the account will be logged-out as per WP core design. You can add the code to your theme/child-theme’s functions.php file or use the Code Snippet plugin to run the code.
Regards,
Hi Champ,
Thank you very much for your comment.
I have now added this code to my functions.php file but unfortunately, it didn’t work.
Kind regards,
ThanosDid you add the username field to your Profile Form via UM Form Builder?
Regards,
Hi Champ,
Yes, I can see it there but it’s still locked.
Please see the screenshot attached.
https://paste.pics/354520d06dc8fbe612ac83e1030baefa
https://paste.pics/434d6f83ae58a25715df7e85e7de5d08Regards,
It’s not a Profile Form in your screenshot, it’s an Account form. The code above is for the Profile Form. You can view the profile form in /user/ page or /profile/ page. You can check the Profile page set in WP Admin > Ultimate Member > Settings > General > Pages > User page.
Regards,
Hi @champsupertramp ,
Thank you for your comment.
It looks like the /user page is just the profile and then if I click “my account” the username field is still locked.
https://paste.pics/8a1ec3d894281491f4cc3b5aa5a4dfe8
Regards,
Please try enabling the user to edit the profile. Please go to WP Admin > Ultimate Member > User Roles > Edit the user role > see “General Permissions” section > check the option “Can edit their profile?”. Once the user is allowed to edit a profile, you should see the “Edit Profile” in the actions: https://drive.google.com/file/d/13dVugT-O2tJmHZiWQwx06iFRYXxtvpSz/view?usp=sharing
Regards,
Hi @champsupertramp ,
Thank you, I can now see the edit profile option but I cannot change the username.
Any idea why?https://paste.pics/3c88360ca419968285ac6e43b4c05286
Regards,
Please go to WP Admin > Ultimate Member > Forms > Edit the default Profile > click on the ” + ” to show the fields. Click on the “Username” field. Once the field is added, click on the “Update” to save the changes to the form.
Please see the screenshot: https://drive.google.com/file/d/13fgnVPKtBwu2AiHz3H_2mnWufnVnLF4m/view?usp=sharing
Regards,
Hi @champsupertramp ,
The username field is now visible on the page but not editable.
https://paste.pics/99f1cd764b5acd89b88170ccf66530bb
Regards,
Please edit the profile to see the editable fields: https://drive.google.com/file/d/13dVugT-O2tJmHZiWQwx06iFRYXxtvpSz/view
Regards,
Hi @champsupertramp ,
Here is the before I click edit profile:
https://paste.pics/8116500dd2b36290a289c014134af37a
and here is the after. (I have selected that the user can edit this field but nothing changed.)
https://paste.pics/ab390b0211f6ccbd36dc26cf84188c5e
Regards,
Did you keep the code above to your theme/child-theme’s functions.php file?
Regards,
Could you please try updating this code:
add_filter("um_user_profile_restricted_edit_fields","um_111921_allow_username_edit"); function um_111921_allow_username_edit( $restricted_fields ){ unset( $restricted_fields[2] ); return $restricted_fields; }To:
add_filter("um_user_profile_restricted_edit_fields","um_111921_allow_username_edit"); function um_111921_allow_username_edit( $restricted_fields ){ return array(); }Let me know if you’re still having issues.
Regards,
The topic ‘Ultimate member Username edit’ is closed to new replies.