WordPress.org

Make WordPress Core


Ignore:
Timestamp:
07/25/2017 12:23:44 AM (3 years ago)
Author:
johnbillion
Message:

Users: Ensure that users with no role on a site are taken into consideration when listing users on Multisite.

This ensures that users who are a member of a site but have no role are correctly listed on the Users screen and can be filtered from the 'None' role filter.

Props tobi823, flixos90, scottlee

Fixes #36196

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/user.php

    r41039 r41138  
    839839 * @since 3.0.0
    840840 * @since 4.4.0 The number of users with no role is now included in the `none` element.
     841 * @since 4.9.0 The `$site_id` parameter was added to support multisite.
    841842 *
    842843 * @global wpdb $wpdb WordPress database abstraction object.
    843844 *
    844  * @param string $strategy 'time' or 'memory'
     845 * @param string   $strategy Optional. The computational strategy to use when counting the users.
     846 *                           Accepts either 'time' or 'memory'. Default 'time'.
     847 * @param int|null $site_id  Optional. The site ID to count users for. Defaults to the current site.
    845848 * @return array Includes a grand total and an array of counts indexed by role strings.
    846849 */
    847 function count_users($strategy = 'time') {
     850function count_users( $strategy = 'time', $site_id = null ) {
    848851    global $wpdb;
    849852
    850853    // Initialize
    851     $id = get_current_blog_id();
    852     $blog_prefix = $wpdb->get_blog_prefix($id);
     854    if ( ! $site_id ) {
     855        $site_id = get_current_blog_id();
     856    }
     857    $blog_prefix = $wpdb->get_blog_prefix( $site_id );
    853858    $result = array();
    854859
     
    919924        $result['total_users'] = count( $users_of_blog );
    920925        $result['avail_roles'] =& $avail_roles;
    921     }
    922 
    923     if ( is_multisite() ) {
    924         $result['avail_roles']['none'] = 0;
    925926    }
    926927
     
    24842485 * Get the user IDs of all users with no role on this site.
    24852486 *
    2486  * This function returns an empty array when used on Multisite.
    2487  *
    24882487 * @since 4.4.0
    2489  *
     2488 * @since 4.9.0 The `$site_id` parameter was added to support multisite.
     2489 *
     2490 * @param int|null $site_id Optional. The site ID to get users with no role for. Defaults to the current site.
    24902491 * @return array Array of user IDs.
    24912492 */
    2492 function wp_get_users_with_no_role() {
     2493function wp_get_users_with_no_role( $site_id = null ) {
    24932494    global $wpdb;
    24942495
    2495     if ( is_multisite() ) {
    2496         return array();
    2497     }
    2498 
    2499     $prefix = $wpdb->get_blog_prefix();
     2496    if ( ! $site_id ) {
     2497        $site_id = get_current_blog_id();
     2498    }
     2499
     2500    $prefix = $wpdb->get_blog_prefix( $site_id );
    25002501    $regex  = implode( '|', array_keys( wp_roles()->get_names() ) );
    25012502    $regex  = preg_replace( '/[^a-zA-Z_\|-]/', '', $regex );
Note: See TracChangeset for help on using the changeset viewer.