Skip to content

Commit 75f4a09

Browse files
committed
Users: Prevent creating of empty usernames after sanitization.
Introduces a check in `wp_insert_user()` to ensure the username doesn't have a length of zero after sanitization removes invalid characters. Props kalpeshh, missveronicatv, rayhatron, rinkalpagdar, sergeybiryukov, thehercules. Fixes #57635. git-svn-id: https://develop.svn.wordpress.org/trunk@60288 602fd350-edb4-49c9-b593-d223f7449a82
1 parent ecd37b7 commit 75f4a09

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/wp-includes/user.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2286,7 +2286,10 @@ function wp_insert_user( $userdata ) {
22862286
*/
22872287
$user_nicename = apply_filters( 'pre_user_nicename', $user_nicename );
22882288

2289-
if ( mb_strlen( $user_nicename ) > 50 ) {
2289+
// Check if the sanitized nicename is empty.
2290+
if ( empty( $user_nicename ) ) {
2291+
return new WP_Error( 'empty_user_nicename', __( 'Cannot create a user with an empty nicename.' ) );
2292+
} elseif ( mb_strlen( $user_nicename ) > 50 ) {
22902293
return new WP_Error( 'user_nicename_too_long', __( 'Nicename may not be longer than 50 characters.' ) );
22912294
}
22922295

0 commit comments

Comments
 (0)