";
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 ) {
$row .= "$checkbox | ";
} else {
$row .= "";
switch ( $column_name ) {
case 'username':
$row .= "$avatar $edit";
break;
case 'name':
if ( $user_object->first_name && $user_object->last_name ) {
$row .= sprintf(
/* translators: 1: User's first name, 2: Last name. */
_x( '%1$s %2$s', 'Display name based on first name and last name' ),
$user_object->first_name,
$user_object->last_name
);
} elseif ( $user_object->first_name ) {
$row .= $user_object->first_name;
} elseif ( $user_object->last_name ) {
$row .= $user_object->last_name;
} else {
$row .= sprintf(
'—%s',
/* translators: Hidden accessibility text. */
_x( 'Unknown', 'name' )
);
}
break;
case 'email':
$row .= "$email";
break;
case 'role':
$row .= esc_html( $roles_list );
break;
case 'posts':
if ( $numposts > 0 ) {
$row .= sprintf(
'%s%s',
"edit.php?author={$user_object->ID}",
$numposts,
sprintf(
/* translators: Hidden accessibility text. %s: Number of posts. */
_n( '%s post by this author', '%s posts by this author', $numposts ),
number_format_i18n( $numposts )
)
);
} else {
$row .= 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.
*/
$row .= apply_filters( 'manage_users_custom_column', '', $column_name, $user_object->ID );
}
if ( $primary === $column_name ) {
$row .= $this->row_actions( $actions );
}
$row .= ' | ';
}
}
$row .= '
';
return $row;
}
/**
* 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 translated user role names for a given user object.
*
* @since 4.4.0
*
* @param WP_User $user_object The WP_User object.
* @return string[] An array of user role names keyed by role.
*/
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 translated role names for a user.
*
* @since 4.4.0
*
* @param string[] $role_list An array of translated user role names keyed by role.
* @param WP_User $user_object A WP_User object.
*/
return apply_filters( 'get_role_list', $role_list, $user_object );
}
}