Error on creating unique user ID when registering anonymously
-
I’m using a registration form for a file-submission database.
To enable posting multiple times for the same username/email, I’m not using the build in user/email fields, but instead creating custom meta-keys.UM then creates a Unique email/user id, and heres where i found a small bug.
When testing for a unique username, UM counts the current number of users (line 326 in includes/core/um-actions-register.php) and ads 1.
But if you delete one existing user, you may get a username that already exists, resulting in an error creating the user.
I fixed this, by modifying line 328 – 330 in includes/core/um-actions-register.php from:
if ( ! isset( $user_login ) || strlen( $user_login ) > 30 && ! is_email( $user_login ) ) { $user_login = 'user' . $unique_userID; }
to
if ( ! isset( $user_login ) || strlen( $user_login ) > 30 && ! is_email( $user_login ) ) { $user_login = 'user' . $unique_userID; $temp_user_login = $user_login; while ( username_exists( $temp_user_login ) ) { $temp_user_login = 'user' . $unique_userID; $unique_userID++; } if ( $temp_user_login !== $user_login ) { $user_login = $temp_user_login; } }
Would be nice to have implemented in an update.
- The topic ‘Error on creating unique user ID when registering anonymously’ is closed to new replies.