oshevans
Forum Replies Created
-
Thanks @missveronicatv
If anyone has a better / more integrated solution than the one below, let me know.
Here’s what I’ve got, based on the original code from this post, and info from @missveronica:
/* UM PROFILE FORM - edit user_login and user_email from single username field */ add_filter("um_user_profile_restricted_edit_fields","um_111921_allow_username_edit"); function um_111921_allow_username_edit( $restricted_fields ){ return array(); } add_action("um_submit_form_profile","um_111921_username_validation", 1 ); function um_111921_username_validation( $post_form ){ if( isset( $post_form['username'] ) && ! empty( $post_form['username'] ) ){ $user = wp_get_current_user(); if( username_exists( $post_form['user_login'] ) && $post_form['username'] !== $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; if( isset( $to_update['username'] ) && ! empty( $to_update['username'] ) ){ $user = wp_get_current_user(); $sql = $wpdb->prepare("UPDATE {$wpdb->users} SET user_login = %s, user_email = %s WHERE ID = %d", $to_update['username'], $to_update['username'], $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); } }
username
?is used both for?user_login
?and?user_email
when you have the “Username or Email” UM predefined field at your Login page.OK, maybe that works for login, but when I register or edit a profile “username” is not a WP meta field, so it doesn’t do anything to the underlying account.
I will need to hook that value into the _login data.
Thanks!
Unfortunately, that field has a different Meta Key (“Username”), so I can’t use it. I don’t really know what that meta key is used for in WP either – shouldn’t it be”user_login” anyway?
Also, I’m unable to use a custom field with “user_login”, as it gives an error when creating the form: “Your meta key is a predefined reserved key and cannot be used”.
Is there a way to override the Username validation (there is no option to specify a custom validation).
- This reply was modified 7 months, 3 weeks ago by oshevans.
Here’s an interim solution that doesn’t involve editing core:
add_filter( ‘um_view_field’, ‘my_view_field’, 10, 3 );
function my_view_field( $output, $data, $type ) {
if ($type === “checkbox”) {
$values = explode(“, “, $output);
for($i = 0; $i < count($values); ++$i) {
$values[$i] = __( $values[$i], ‘ultimate-member’ );
}
$output = implode(‘, ‘, $values);
} else {
$output = __( $output, ‘ultimate-member’ );
}
return $output;
}Found the issue:
includes/core/class-fields.php – ln 4197
changed $res to __( $res,’ultimate-member’ )
Now it translates the db value before presenting it (as per the edit field).
This needs to be reported, so once I’ve finished my deadline for tomorrow, I’ll report it.
Hi @champsupertramp,
Still having these issues.
I’ve temporarily changed wpml to use domains for different langs, but will need to revert to qstring at some point.
Looks like I’m gonna have to find an alternative solution that is more compatible with wpml.
Anyone have any suggestions?
Cheers.
Hi @champsupertramp,
OK, I’ve updated the UM plugin with the code from the repo, but nothing has changed.
I’m still getting the messed up URL.I also noticed that if I access the correct URL directly, it gives me a re-direct loop error… not sure if that is related, or a separate issue.
{domain}/index.php/profile/?lang=enMany thanks.
Thank for the info and link @champsupertramp.
The info mentions that they “…recommend using the plugin WPML”, and only if we “…use the plugin Polylang … you should install a special version of the plugin Ultimate Member”
So you are suggesting that we should use this special version regardless of us already using the recommended WPML plugin?
Just wanted to clarify.
Thanks again.
WPML Multilingual CMS – Version 4.4.12
Ultimate Member – Version 2.2.4