";
list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
foreach ( $columns as $column_name => $column_display_name ) {
$classes = "$column_name column-$column_name";
if ( $primary === $column_name ) {
$classes .= ' has-row-actions column-primary';
}
if ( 'posts' === $column_name ) {
$classes .= ' num'; // Special case for that column.
}
if ( in_array( $column_name, $hidden, true ) ) {
$classes .= ' hidden';
}
$data = 'data-colname="' . esc_attr( wp_strip_all_tags( $column_display_name ) ) . '"';
$attributes = "class='$classes' $data";
if ( 'cb' === $column_name ) {
$r .= "$checkbox | ";
} else {
$r .= "";
switch ( $column_name ) {
case 'username':
$r .= "$avatar $edit";
break;
case 'name':
if ( $user_object->first_name && $user_object->last_name ) {
$r .= "$user_object->first_name $user_object->last_name";
} elseif ( $user_object->first_name ) {
$r .= $user_object->first_name;
} elseif ( $user_object->last_name ) {
$r .= $user_object->last_name;
} else {
$r .= sprintf(
'—%s',
_x( 'Unknown', 'name' )
);
}
break;
case 'email':
$r .= "$email";
break;
case 'role':
$r .= esc_html( $roles_list );
break;
case 'posts':
if ( $numposts > 0 ) {
$r .= sprintf(
'%s%s',
"edit.php?author={$user_object->ID}",
$numposts,
sprintf(
/* translators: %s: Number of posts. */
_n( '%s post by this author', '%s posts by this author', $numposts ),
number_format_i18n( $numposts )
)
);
} else {
$r .= 0;
}
break;
default:
/**
* Filters the display output of custom columns in the Users list table.
*
* @since 2.8.0
*
* @param string $output Custom column output. Default empty.
* @param string $column_name Column name.
* @param int $user_id ID of the currently-listed user.
*/
$r .= apply_filters( 'manage_users_custom_column', '', $column_name, $user_object->ID );
}
if ( $primary === $column_name ) {
$r .= $this->row_actions( $actions );
}
$r .= ' | ';
}
}
$r .= '
';
return $r;
}
/**
* Gets the name of the default primary column.
*
* @since 4.3.0
*
* @return string Name of the default primary column, in this case, 'username'.
*/
protected function get_default_primary_column_name() {
return 'username';
}
/**
* Returns an array of user roles for a given user object.
*
* @since 4.4.0
*
* @param WP_User $user_object The WP_User object.
* @return string[] An array of user roles.
*/
protected function get_role_list( $user_object ) {
$wp_roles = wp_roles();
$role_list = array();
foreach ( $user_object->roles as $role ) {
if ( isset( $wp_roles->role_names[ $role ] ) ) {
$role_list[ $role ] = translate_user_role( $wp_roles->role_names[ $role ] );
}
}
if ( empty( $role_list ) ) {
$role_list['none'] = _x( 'None', 'no user roles' );
}
/**
* Filters the returned array of roles for a user.
*
* @since 4.4.0
*
* @param string[] $role_list An array of user roles.
* @param WP_User $user_object A WP_User object.
*/
return apply_filters( 'get_role_list', $role_list, $user_object );
}
}