WordPress.org

Make WordPress Core

Ticket #33967: 33967.2.patch

File 33967.2.patch, 7.5 KB (added by Mista-Flo, 5 years ago)

Properly get the first user of the blog (order by registered date)

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

    From 368f0c38629930e99ca1cff4ae9e4a20c79325aa Mon Sep 17 00:00:00 2001
    From: Florian TIAR <contact@tiar-florian.fr>
    Date: Tue, 27 Sep 2016 18:38:07 +0200
    Subject: [PATCH 1/2] Add first username and link to all username of a site in
     wp admin list sites (multisite)
    
    ---
     wp-admin/includes/class-wp-ms-sites-list-table.php | 20 ++++++++++++++++----
     1 file changed, 16 insertions(+), 4 deletions(-)
    
    diff --git a/wp-admin/includes/class-wp-ms-sites-list-table.php b/wp-admin/includes/class-wp-ms-sites-list-table.php
    index 9ce3ffe..9d61008 100644
    a b 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                $blog_users = get_users( array( 'blog_id' => $blog['blog_id'] ) );
    396398                $user_count = wp_cache_get( $blog['blog_id'] . '_user_count', 'blog-details' );
    397399                if ( ! $user_count ) {
    398                         $blog_users = get_users( array( 'blog_id' => $blog['blog_id'], 'fields' => 'ID' ) );
    399400                        $user_count = count( $blog_users );
    400                         unset( $blog_users );
    401401                        wp_cache_set( $blog['blog_id'] . '_user_count', $user_count, 'blog-details', 12 * HOUR_IN_SECONDS );
    402402                }
    403403
    404404                printf(
    405405                        '<a href="%s">%s</a>',
    406                         esc_url( network_admin_url( 'site-users.php?id=' . $blog['blog_id'] ) ),
    407                         number_format_i18n( $user_count )
     406                        esc_url( network_admin_url( 'user-edit.php?user_id=' . $blog_users[0]->ID ) ),
     407                        $blog_users[0]->user_login
    408408                );
     409
     410                if ( $user_count > 1 ) {
     411                        printf( '<a href="%s">%s</a>',
     412                                esc_url( network_admin_url( 'site-users.php?id=' . $blog['blog_id'] ) ),
     413                                sprintf(
     414                                        _x( '+ %s more users', 'Number of users of a site of a network (in admin page : wp-admin/network/sites.php)' ),
     415                                        number_format_i18n( $user_count )
     416                                )
     417                        );
     418                }
     419
     420                unset( $blog_users );
    409421        }
    410422
    411423        /**
  • wp-admin/includes/class-wp-ms-sites-list-table.php

    -- 
    1.9.5.github.0
    
    
    From 471a3e75e984dd41d5c402a2075fb2e796d254da Mon Sep 17 00:00:00 2001
    From: Florian TIAR <contact@tiar-florian.fr>
    Date: Tue, 27 Sep 2016 19:09:36 +0200
    Subject: [PATCH 2/2] Fix get_users args to get the first user of blog
    
    ---
     wp-admin/includes/class-wp-ms-sites-list-table.php | 12 +++++++++---
     1 file changed, 9 insertions(+), 3 deletions(-)
    
    diff --git a/wp-admin/includes/class-wp-ms-sites-list-table.php b/wp-admin/includes/class-wp-ms-sites-list-table.php
    index 9d61008..c3a4df4 100644
    a b class WP_MS_Sites_List_Table extends WP_List_Table { 
    394394         * @param array $blog Current site.
    395395         */
    396396        public function column_users( $blog ) {
    397                 $blog_users = get_users( array( 'blog_id' => $blog['blog_id'] ) );
     397                $blog_users = get_users( array(
     398                        'blog_id' => $blog['blog_id'],
     399                        'fields'  => 'ID',
     400                        'orderby' => 'registered',
     401                ) );
     402
    398403                $user_count = wp_cache_get( $blog['blog_id'] . '_user_count', 'blog-details' );
    399404                if ( ! $user_count ) {
    400405                        $user_count = count( $blog_users );
    401406                        wp_cache_set( $blog['blog_id'] . '_user_count', $user_count, 'blog-details', 12 * HOUR_IN_SECONDS );
    402407                }
    403408
     409                $first_blog_user = get_user_by( 'id', $blog_users[0] );
    404410                printf(
    405411                        '<a href="%s">%s</a>',
    406                         esc_url( network_admin_url( 'user-edit.php?user_id=' . $blog_users[0]->ID ) ),
    407                         $blog_users[0]->user_login
     412                        esc_url( network_admin_url( 'user-edit.php?user_id=' . $first_blog_user->ID ) ),
     413                        $first_blog_user->user_login
    408414                );
    409415
    410416                if ( $user_count > 1 ) {