diff -r be944660c56a -r 3d72ae0968f4 wp/wp-includes/ms-functions.php --- a/wp/wp-includes/ms-functions.php Wed Sep 21 18:19:35 2022 +0200 +++ b/wp/wp-includes/ms-functions.php Tue Sep 27 16:37:53 2022 +0200 @@ -29,7 +29,7 @@ } /** - * Get one of a user's active blogs + * Gets one of a user's active blogs. * * Returns the user's primary blog, if they have one and * it is active. If it's inactive, function returns another @@ -101,22 +101,7 @@ } /** - * The number of active users in your installation. - * - * The count is cached and updated twice daily. This is not a live count. - * - * @since MU (3.0.0) - * @since 4.8.0 The `$network_id` parameter has been added. - * - * @param int|null $network_id ID of the network. Default is the current network. - * @return int Number of active users on the network. - */ -function get_user_count( $network_id = null ) { - return get_network_option( $network_id, 'user_count' ); -} - -/** - * The number of active sites on your installation. + * Gets the number of active sites on the installation. * * The count is cached and updated twice daily. This is not a live count. * @@ -225,7 +210,7 @@ } /** - * Remove a user from a blog. + * Removes a user from a blog. * * Use the {@see 'remove_user_from_blog'} action to fire an event when * users are removed from a blog. @@ -280,7 +265,6 @@ update_user_meta( $user_id, 'source_domain', $new_domain ); } - // wp_revoke_user( $user_id ); $user = get_userdata( $user_id ); if ( ! $user ) { restore_current_blog(); @@ -317,7 +301,7 @@ } /** - * Get the permalink for a post on another blog. + * Gets the permalink for a post on another blog. * * @since MU (3.0.0) 1.0 * @@ -334,7 +318,7 @@ } /** - * Get a blog's numeric ID from its URL. + * Gets a blog's numeric ID from its URL. * * On a subdirectory installation like example.com/blog1/, * $domain will be the root 'example.com' and $path the @@ -441,7 +425,7 @@ } /** - * Sanitize and validate data required for a user sign-up. + * Sanitizes and validates data required for a user sign-up. * * Verifies the validity and uniqueness of user names and user email addresses, * and checks email addresses against allowed and disallowed domains provided by @@ -506,7 +490,7 @@ if ( ! is_email( $user_email ) ) { $errors->add( 'user_email', __( 'Please enter a valid email address.' ) ); } elseif ( is_email_address_unsafe( $user_email ) ) { - $errors->add( 'user_email', __( 'You cannot use that email address to signup. We are having problems with them blocking some of our email. Please use another email provider.' ) ); + $errors->add( 'user_email', __( 'You cannot use that email address to signup. There are problems with them blocking some emails from WordPress. Please use another email provider.' ) ); } if ( strlen( $user_name ) < 4 ) { @@ -538,7 +522,14 @@ // Check if the email address has been used already. if ( email_exists( $user_email ) ) { - $errors->add( 'user_email', __( 'Sorry, that email address is already used!' ) ); + $errors->add( + 'user_email', + sprintf( + /* translators: %s: Link to the login page. */ + __( 'Error: This email address is already registered. Log in with this address or choose another one.' ), + wp_login_url() + ) + ); } // Has someone already signed up for this username? @@ -675,7 +666,7 @@ $errors->add( 'blogname', sprintf( _n( 'Site name must be at least %s character.', 'Site name must be at least %s characters.', $minimum_site_name_length ), number_format_i18n( $minimum_site_name_length ) ) ); } - // Do not allow users to create a blog that conflicts with a page on the main blog. + // Do not allow users to create a site that conflicts with a page on the main blog. if ( ! is_subdomain_install() && $wpdb->get_var( $wpdb->prepare( 'SELECT post_name FROM ' . $wpdb->get_blog_prefix( $current_network->site_id ) . "posts WHERE post_type = 'page' AND post_name = %s", $blogname ) ) ) { $errors->add( 'blogname', __( 'Sorry, you may not use that site name.' ) ); } @@ -715,6 +706,10 @@ $errors->add( 'blogname', __( 'Sorry, that site already exists!' ) ); } + /* + * Do not allow users to create a site that matches an existing user's login name, + * unless it's the user's own username. + */ if ( username_exists( $blogname ) ) { if ( ! is_object( $user ) || ( is_object( $user ) && ( $user->user_login != $blogname ) ) ) { $errors->add( 'blogname', __( 'Sorry, that site is reserved!' ) ); @@ -769,7 +764,7 @@ } /** - * Record site signup information for future activation. + * Records site signup information for future activation. * * @since MU (3.0.0) * @@ -835,7 +830,7 @@ } /** - * Record user signup information for future activation. + * Records user signup information for future activation. * * This function is used when user registration is open but * new site registration is not. @@ -898,7 +893,7 @@ } /** - * Send a confirmation request email to a user when they sign up for a new site. The new site will not become active + * Sends a confirmation request email to a user when they sign up for a new site. The new site will not become active * until the confirmation link is clicked. * * This is the notification function used when site registration @@ -981,7 +976,7 @@ apply_filters( 'wpmu_signup_blog_notification_email', /* translators: New site notification email. 1: Activation URL, 2: New site URL. */ - __( "To activate your blog, please click the following link:\n\n%1\$s\n\nAfter you activate, you will receive *another email* with your login.\n\nAfter you activate, you can visit your site here:\n\n%2\$s" ), + __( "To activate your site, please click the following link:\n\n%1\$s\n\nAfter you activate, you will receive *another email* with your login.\n\nAfter you activate, you can visit your site here:\n\n%2\$s" ), $domain, $path, $title, @@ -1036,7 +1031,7 @@ } /** - * Send a confirmation request email to a user when they sign up for a new user account (without signing up for a site + * Sends a confirmation request email to a user when they sign up for a new user account (without signing up for a site * at the same time). The user account will not become active until the confirmation link is clicked. * * This is the notification function used when no new site has @@ -1145,7 +1140,7 @@ } /** - * Activate a signup. + * Activates a signup. * * Hook to {@see 'wpmu_activate_user'} or {@see 'wpmu_activate_blog'} for events * that should happen only when users or sites are self-created (since @@ -1264,7 +1259,7 @@ * * @param int $blog_id Blog ID. * @param int $user_id User ID. - * @param int $password User password. + * @param string $password User password. * @param string $signup_title Site title. * @param array $meta Signup meta data. By default, contains the requested privacy setting and lang_id. */ @@ -1280,7 +1275,7 @@ } /** - * Deletes am associated signup entry when a user is deleted from the database. + * Deletes an associated signup entry when a user is deleted from the database. * * @since 5.5.0 * @@ -1295,12 +1290,12 @@ } /** - * Create a user. + * Creates a user. * * This function runs when a user self-registers as well as when * a Super Admin creates a new user. Hook to {@see 'wpmu_new_user'} for events * that should affect all new users, but only on Multisite (otherwise - * use {@see'user_register'}). + * use {@see 'user_register'}). * * @since MU (3.0.0) * @@ -1334,7 +1329,7 @@ } /** - * Create a site. + * Creates a site. * * This function runs when a user self-registers a new site as well * as when a Super Admin creates a new site. Hook to {@see 'wpmu_new_blog'} @@ -1462,8 +1457,8 @@ * @since MU (3.0.0) * @since 5.4.0 The `$blog_id` parameter was added. * - * @param string $msg Email body. - * @param int $blog_id The new site's ID. + * @param string $msg Email body. + * @param int|string $blog_id The new site's ID as an integer or numeric string. */ $msg = apply_filters( 'newblog_notify_siteadmin', $msg, $blog_id ); @@ -1810,7 +1805,7 @@ } /** - * Notify a user that their account activation has been successful. + * Notifies a user that their account activation has been successful. * * Filter {@see 'wpmu_welcome_user_notification'} to disable or bypass. * @@ -1902,7 +1897,7 @@ } /** - * Get the current network. + * Gets the current network. * * Returns an object containing the 'id', 'domain', 'path', and 'site_name' * properties of the network being viewed. @@ -1921,7 +1916,7 @@ } /** - * Get a user's most recent post. + * Gets a user's most recent post. * * Walks through each of a user's blogs to find the post with * the most recent post_date_gmt. @@ -1973,7 +1968,7 @@ // /** - * Check an array of MIME types against a list of allowed types. + * Checks an array of MIME types against a list of allowed types. * * WordPress ships with a set of allowed upload filetypes, * which is defined in wp-includes/functions.php in @@ -2000,7 +1995,7 @@ } /** - * Update a blog's post count. + * Updates a blog's post count. * * WordPress MS stores a blog's post count as an option so as * to avoid extraneous COUNTs when a blog's details are fetched @@ -2146,7 +2141,7 @@ } /** - * Ensure that the current site's domain is listed in the allowed redirect host list. + * Ensures that the current site's domain is listed in the allowed redirect host list. * * @see wp_validate_redirect() * @since MU (3.0.0) @@ -2163,7 +2158,7 @@ } /** - * Check whether an upload is too big. + * Checks whether an upload is too big. * * @since MU (3.0.0) * @@ -2186,7 +2181,7 @@ } /** - * Add a nonce field to the signup page. + * Adds a nonce field to the signup page. * * @since MU (3.0.0) */ @@ -2197,7 +2192,7 @@ } /** - * Process the signup nonce created in signup_nonce_fields(). + * Processes the signup nonce created in signup_nonce_fields(). * * @since MU (3.0.0) * @@ -2217,7 +2212,7 @@ } /** - * Correct 404 redirects when NOBLOGREDIRECT is defined. + * Corrects 404 redirects when NOBLOGREDIRECT is defined. * * @since MU (3.0.0) */ @@ -2246,7 +2241,7 @@ } /** - * Add a new user to a blog by visiting /newbloguser/{key}/. + * Adds a new user to a blog by visiting /newbloguser/{key}/. * * This will only work when the user's details are saved as an option * keyed as 'new_user_{key}', where '{key}' is a hash generated for the user to be @@ -2294,7 +2289,7 @@ } /** - * Add a user to a blog based on details from maybe_add_existing_user_to_blog(). + * Adds a user to a blog based on details from maybe_add_existing_user_to_blog(). * * @since MU (3.0.0) * @@ -2356,7 +2351,7 @@ } /** - * Correct From host on outgoing mail to match the site domain + * Corrects From host on outgoing mail to match the site domain * * @since MU (3.0.0) * @@ -2367,7 +2362,7 @@ } /** - * Check to see whether a user is marked as a spammer, based on user login. + * Determines whether a user is marked as a spammer, based on user login. * * @since MU (3.0.0) * @@ -2388,7 +2383,7 @@ } /** - * Update this blog's 'public' setting in the global blogs table. + * Updates this blog's 'public' setting in the global blogs table. * * Public blogs have a setting of 1, private blogs are 0. * @@ -2402,7 +2397,7 @@ } /** - * Check whether users can self-register, based on Network settings. + * Determines whether users can self-register, based on Network settings. * * @since MU (3.0.0) * @@ -2414,7 +2409,7 @@ } /** - * Ensure that the welcome message is not empty. Currently unused. + * Ensures that the welcome message is not empty. Currently unused. * * @since MU (3.0.0) * @@ -2446,7 +2441,7 @@ } /** - * Whether to force SSL on content. + * Determines whether to force SSL on content. * * @since 2.8.5 * @@ -2488,7 +2483,7 @@ } /** - * Schedule update of the network-wide counts for the current network. + * Schedules update of the network-wide counts for the current network. * * @since 3.1.0 */ @@ -2503,7 +2498,7 @@ } /** - * Update the network-wide counts for the current network. + * Updates the network-wide counts for the current network. * * @since 3.1.0 * @since 4.8.0 The `$network_id` parameter has been added. @@ -2516,7 +2511,7 @@ } /** - * Update the count of sites for the current network. + * Updates the count of sites for the current network. * * If enabled through the {@see 'enable_live_network_counts'} filter, update the sites count * on a network when a site is created or its status is updated. @@ -2547,7 +2542,7 @@ } /** - * Update the network-wide users count. + * Updates the network-wide users count. * * If enabled through the {@see 'enable_live_network_counts'} filter, update the users count * on a network when a user is created or its status is updated. @@ -2569,7 +2564,7 @@ } /** - * Update the network-wide site count. + * Updates the network-wide site count. * * @since 3.7.0 * @since 4.8.0 The `$network_id` parameter has been added. @@ -2597,20 +2592,16 @@ } /** - * Update the network-wide user count. + * Updates the network-wide user count. * * @since 3.7.0 * @since 4.8.0 The `$network_id` parameter has been added. - * - * @global wpdb $wpdb WordPress database abstraction object. + * @since 6.0.0 This function is now a wrapper for wp_update_user_counts(). * * @param int|null $network_id ID of the network. Default is the current network. */ function wp_update_network_user_counts( $network_id = null ) { - global $wpdb; - - $count = $wpdb->get_var( "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'" ); - update_network_option( $network_id, 'user_count', $count ); + wp_update_user_counts( $network_id ); } /** @@ -2724,7 +2715,7 @@ } /** - * Whether or not we have a large network. + * Determines whether or not we have a large network. * * The default criteria for a large network is either more than 10,000 users or more than 10,000 sites. * Plugins can alter this criteria using the {@see 'wp_is_large_network'} filter. @@ -2744,6 +2735,9 @@ if ( 'users' === $using ) { $count = get_user_count( $network_id ); + + $is_large_network = wp_is_large_user_count( $network_id ); + /** * Filters whether the network is considered large. * @@ -2755,7 +2749,7 @@ * @param int $count The count of items for the component. * @param int $network_id The ID of the network being checked. */ - return apply_filters( 'wp_is_large_network', $count > 10000, 'users', $count, $network_id ); + return apply_filters( 'wp_is_large_network', $is_large_network, 'users', $count, $network_id ); } $count = get_blog_count( $network_id ); @@ -2798,7 +2792,7 @@ } /** - * Send a confirmation request email when a change of network admin email address is attempted. + * Sends a confirmation request email when a change of network admin email address is attempted. * * The new network admin address will not become active until confirmed. * @@ -2886,7 +2880,7 @@ } /** - * Send an email to the old network admin email address when the network admin email address changes. + * Sends an email to the old network admin email address when the network admin email address changes. * * @since 4.9.0 *