From 35c5e74706ca459e54e6b6799729a8ee8ed45a5a Mon Sep 17 00:00:00 2001 From: davidbaumwald Date: Fri, 18 Mar 2022 20:44:01 +0000 Subject: [PATCH] Users: Check maximum length of `user_nicename` after filters are applied. Similar to other checks on `user_login` and `user_url`, this change moves the maximum length check on `user_nicename` after the `pre_user_nicename` filter has been applied, to account for any changes to the value prior to saving. Props SergeyBiryukov, ravipatel, muhammadfaizanhaidar, mukesh27, csesumonpro, azouamauriac. Fixes #54987. Built from https://develop.svn.wordpress.org/trunk@52954 git-svn-id: http://core.svn.wordpress.org/trunk@52543 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/user.php | 7 ++++--- wp-includes/version.php | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/wp-includes/user.php b/wp-includes/user.php index 81944eda0e..e58091aa10 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -1977,9 +1977,6 @@ function wp_insert_user( $userdata ) { */ if ( ! empty( $userdata['user_nicename'] ) ) { $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.' ) ); - } } else { $user_nicename = mb_substr( $user_login, 0, 50 ); } @@ -1995,6 +1992,10 @@ function wp_insert_user( $userdata ) { */ $user_nicename = apply_filters( 'pre_user_nicename', $user_nicename ); + if ( mb_strlen( $user_nicename ) > 50 ) { + return new WP_Error( 'user_nicename_too_long', __( 'Nicename may not be longer than 50 characters.' ) ); + } + $user_nicename_check = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->users WHERE user_nicename = %s AND user_login != %s LIMIT 1", $user_nicename, $user_login ) ); if ( $user_nicename_check ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index ebeee9e189..97cbf6567c 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.0-alpha-52953'; +$wp_version = '6.0-alpha-52954'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.