Make WordPress Core

Ticket #33967: 33967.6.patch

File 33967.6.patch, 5.3 KB (added by Mista-Flo, 8 years ago)

Add a notice if there is no user on the blog

  • wp-admin/includes/class-wp-ms-sites-list-table.php

    diff --git wp-admin/includes/class-wp-ms-sites-list-table.php wp-admin/includes/class-wp-ms-sites-list-table.php
    index 9ce3ffe..060f53e 100644
    class WP_MS_Sites_List_Table extends WP_List_Table { 
    388388         * Handles the users column output.
    389389         *
    390390         * @since 4.3.0
     391         * @since 4.7.0 Display First user of the site, and number of users in the site
    391392         * @access public
    392393         *
    393394         * @param array $blog Current site.
    394395         */
    395396        public function column_users( $blog ) {
     397                global $mode;
     398
     399                $blog_users = get_users( array(
     400                        'blog_id' => $blog['blog_id'],
     401                        'orderby' => 'registered',
     402                ) );
     403
     404                if ( empty( $blog_users ) ) {
     405                        printf( __( 'There is no user in this site' ) );
     406                        return;
     407                }
     408
    396409                $user_count = wp_cache_get( $blog['blog_id'] . '_user_count', 'blog-details' );
    397410                if ( ! $user_count ) {
    398                         $blog_users = get_users( array( 'blog_id' => $blog['blog_id'], 'fields' => 'ID' ) );
    399411                        $user_count = count( $blog_users );
    400                         unset( $blog_users );
    401412                        wp_cache_set( $blog['blog_id'] . '_user_count', $user_count, 'blog-details', 12 * HOUR_IN_SECONDS );
    402413                }
    403414
    404415                printf(
    405416                        '<a href="%s">%s</a>',
    406                         esc_url( network_admin_url( 'site-users.php?id=' . $blog['blog_id'] ) ),
    407                         number_format_i18n( $user_count )
     417                        esc_url( network_admin_url( 'user-edit.php?user_id=' . $blog_users[0]->ID ) ),
     418                        $blog_users[0]->user_login
    408419                );
     420
     421                if ( $user_count > 1 ) {
     422                        if ( 'excerpt' === $mode) {
     423                                foreach ( $blog_users as $key => $user ) {
     424                                        // Don't display again the first user
     425                                        if ( 0 === $key ) {
     426                                                continue;
     427                                        }
     428
     429                                        printf(
     430                                                '</br><a href="%s">%s</a>',
     431                                                esc_url( network_admin_url( 'user-edit.php?user_id=' . $user->ID ) ),
     432                                                $user->user_login
     433                                        );
     434
     435                                        // Only display 10 first users
     436                                        if ( $user_count > 10 && 9 === $key ) {
     437                                                printf( '</br><a href="%s">%s</a>',
     438                                                        esc_url( network_admin_url( 'site-users.php?id=' . $blog['blog_id'] ) ),
     439                                                        sprintf(
     440                                                                _x( '+ %s more users', 'Number of users of a site of a network (in admin page : wp-admin/network/sites.php)' ),
     441                                                                number_format_i18n( $user_count -10 )
     442                                                        )
     443                                                );
     444                                                break;
     445                                        }
     446                                }
     447                        } else {
     448                                printf( '</br><a href="%s">%s</a>',
     449                                        esc_url( network_admin_url( 'site-users.php?id=' . $blog['blog_id'] ) ),
     450                                        sprintf(
     451                                                _x( '+ %s more users', 'Number of users of a site of a network (in admin page : wp-admin/network/sites.php)' ),
     452                                                number_format_i18n( $user_count -1 )
     453                                        )
     454                                );
     455                        }
     456                }
     457
     458                unset( $blog_users );
    409459        }
    410460
    411461        /**