From 26e30b84c6e90891bdee892558d780671dd594bd Mon Sep 17 00:00:00 2001
From: Kalpesh <kalpesh@xecurify.com>
Date: Thu, 9 Feb 2023 01:50:15 +0530
Subject: [PATCH] Empty nicename check fix after sanitize_user to avoid
 creating user with empty nicename

---
 src/wp-includes/user.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/wp-includes/user.php b/src/wp-includes/user.php
index 018c960c031b..892f33cea43f 100644
--- a/src/wp-includes/user.php
+++ b/src/wp-includes/user.php
@@ -1855,7 +1855,7 @@ function wp_insert_user( $userdata ) {
 	 * If a nicename is provided, remove unsafe user characters before using it.
 	 * Otherwise build a nicename from the user_login.
 	 */
-	if ( ! empty( $userdata['user_nicename'] ) ) {
+	if ( ! empty( sanitize_user( $userdata['user_nicename'], true ) ) ) {
 		$user_nicename = sanitize_user( $userdata['user_nicename'], true );
 		if ( mb_strlen( $user_nicename ) > 50 ) {
 			return new WP_Error( 'user_nicename_too_long', __( 'Nicename may not be longer than 50 characters.' ) );
