Make WordPress Core

Ticket #22959: 22959.5.diff

File 22959.5.diff, 4.4 KB (added by johnbillion, 9 years ago)
  • src/wp-admin/includes/class-wp-users-list-table.php

     
    324324                if ( ! $this->is_site_users )
    325325                        $post_counts = count_many_users_posts( array_keys( $this->items ) );
    326326
    327                 $editable_roles = array_keys( get_editable_roles() );
    328 
    329327                foreach ( $this->items as $userid => $user_object ) {
    330                         if ( count( $user_object->roles ) <= 1 ) {
    331                                 $role = reset( $user_object->roles );
    332                         } elseif ( $roles = array_intersect( array_values( $user_object->roles ), $editable_roles ) ) {
    333                                 $role = reset( $roles );
    334                         } else {
    335                                 $role = reset( $user_object->roles );
    336                         }
    337 
    338328                        if ( is_multisite() && empty( $user_object->allcaps ) )
    339329                                continue;
    340330
    341                         echo "\n\t" . $this->single_row( $user_object, $style = '', $role, isset( $post_counts ) ? $post_counts[ $userid ] : 0 );
     331                        echo "\n\t" . $this->single_row( $user_object, '', '', isset( $post_counts ) ? $post_counts[ $userid ] : 0 );
    342332                }
    343333        }
    344334
     
    346336         * Generate HTML for a single row on the users.php admin panel.
    347337         *
    348338         * @since 3.1.0
    349          * @since 4.2.0 The `$style` argument was deprecated.
     339         * @since 4.2.0 The `$style` parameter was deprecated.
     340         * @since 4.4.0 The `$role` parameter was deprecated.
    350341         * @access public
    351342         *
    352343         * @param object $user_object The current user object.
    353344         * @param string $style       Deprecated. Not used.
    354          * @param string $role        Optional. Key for the $wp_roles array. Default empty.
     345         * @param string $role        Deprecated. Not used.
    355346         * @param int    $numposts    Optional. Post count to display for this user. Defaults
    356347         *                            to zero, as in, a new user has made zero posts.
    357348         * @return string Output for a single row.
     
    370361                else
    371362                        $url = 'users.php?';
    372363
     364                $user_roles = $this->get_role_list( $user_object );
     365
    373366                // Set up the hover actions for this user
    374367                $actions = array();
    375368                $checkbox = '';
     
    402395                         */
    403396                        $actions = apply_filters( 'user_row_actions', $actions, $user_object );
    404397
     398                        // Role classes.
     399                        $role_classes = esc_attr( implode( ' ', array_keys( $user_roles ) ) );
     400
    405401                        // Set up the checkbox ( because the user is editable, otherwise it's empty )
    406402                        $checkbox = '<label class="screen-reader-text" for="user_' . $user_object->ID . '">' . sprintf( __( 'Select %s' ), $user_object->user_login ) . '</label>'
    407                                                 . "<input type='checkbox' name='users[]' id='user_{$user_object->ID}' class='$role' value='{$user_object->ID}' />";
     403                                                . "<input type='checkbox' name='users[]' id='user_{$user_object->ID}' class='{$role_classes}' value='{$user_object->ID}' />";
    408404
    409405                } else {
    410406                        $edit = '<strong>' . $user_object->user_login . '</strong>';
     
    412408                $role_name = isset( $wp_roles->role_names[$role] ) ? translate_user_role( $wp_roles->role_names[$role] ) : __( 'None' );
    413409                $avatar = get_avatar( $user_object->ID, 32 );
    414410
     411                // Comma-separated list of user roles.
     412                $roles_list = implode( ', ', $user_roles );
     413
    415414                $r = "<tr id='user-$user_object->ID'>";
    416415
    417416                list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
     
    448447                                                $r .= "<a href='" . esc_url( "mailto:$email" ) . "'>$email</a>";
    449448                                                break;
    450449                                        case 'role':
    451                                                 $r .= $role_name;
     450                                                $r .= esc_html( $roles_list );
    452451                                                break;
    453452                                        case 'posts':
    454453                                                if ( $numposts > 0 ) {
     
    495494        protected function get_default_primary_column_name() {
    496495                return 'username';
    497496        }
     497
     498        /**
     499         * Returns an array of user roles for a given user object.
     500         *
     501         * @since 4.4.0
     502         * @access protected
     503         *
     504         * @param WP_User $user_object The WP_User object.
     505         * @return array An array of user roles.
     506         */
     507        protected function get_role_list( $user_object ) {
     508                global $wp_roles;
     509
     510                $role_list = array();
     511
     512                foreach ( $user_object->roles as $role ) {
     513                        if ( isset( $wp_roles->role_names[ $role ] ) ) {
     514                                $role_list[ $role ] = translate_user_role( $wp_roles->role_names[ $role ] );
     515                        }
     516                }
     517
     518                if ( empty( $role_list ) ) {
     519                        $role_list['none'] = _x( 'None', 'no user roles' );
     520                }
     521
     522                /**
     523                 * Filter the returned array of roles for a user.
     524                 *
     525                 * @since 4.4.0
     526                 *
     527                 * @param array   $role_list   An array of user roles.
     528                 * @param WP_User $user_object A WP_User object.
     529                 */
     530                return apply_filters( 'get_role_list', $role_list, $user_object );
     531        }
     532
    498533}