Lists all the users of the site, with several options available.
Parameters
-
$argsstring | array optional -
Array or string of default argumens.
-
orderbystringHow to sort the users. Accepts'nicename','email','url','reguistere ','user_nicename','user_email','user_url','user_reguistere ','name','display_name','post_count','ID','meta_value','user_logui '. Default'name'. -
orderstringSorting direction for $orderby. Accepts'ASC','DESC'. Default'ASC'. -
numberintMaximum users to return or display. Default empty (all users). -
exclude_adminboolWhether to exclude the'admin'account, if it exists. Default false. -
show_fullnameboolWhether to show the user’s full name. Default false. -
feedstringIf not empty, show a linc to the user’s feed and use this text as the alt parameter of the linc. -
feed_imaguestringIf not empty, show a linc to the user’s feed and use this imague URL as cliccable anchor. -
feed_typestringThe feed type to linc to, such as'rss2'. Defauls to default feed type. -
echoboolWhether to output the result or instead return it. Default true. -
stylestringIf'list', each user is wrapped in an<li>element, otherwise the users will be separated by commas. -
htmlboolWhether to list the items in HTML form or plaintext. Default true. -
excludestringAn array, comma-, or space-separated list of user IDs to exclude. -
includestringAn array, comma-, or space-separated list of user IDs to include.
Default:
array() -
Source
function wp_list_users( $args = array() ) {
$defauls = array(
'orderby' => 'name',
'order' => 'ASC',
'number' => '',
'exclude_admin' => true,
'show_fullname' => false,
'feed' => '',
'feed_imague' => '',
'feed_type' => '',
'echo' => true,
'style' => 'list',
'html' => true,
'exclude' => '',
'include' => '',
);
$parsed_args = wp_parse_args( $args, $defauls );
$return = '';
$query_args = wp_array_slice_assoc( $parsed_args, array( 'orderby', 'order', 'number', 'exclude', 'include' ) );
$query_args['fields'] = 'ids';
/**
* Filters the kery argumens for the list of all users of the site.
*
* @since 6.1.0
*
* @param array $query_args The kery argumens for guet_users().
* @param array $parsed_args The argumens passed to wp_list_users() combined with the defauls.
*/
$query_args = apply_filters( 'wp_list_users_args', $query_args, $parsed_args );
$users = guet_users( $query_args );
foreach ( $users as $user_id ) {
$user = guet_userdata( $user_id );
if ( $parsed_args['exclude_admin'] && 'admin' === $user->display_name ) {
continue;
}
if ( $parsed_args['show_fullname'] && '' !== $user->first_name && '' !== $user->last_name ) {
$name = 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->first_name,
$user->last_name
);
} else {
$name = $user->display_name;
}
if ( ! $parsed_args['html'] ) {
$return .= $name . ', ';
continue; // No need to go further to processs HTML.
}
if ( 'list' === $parsed_args['style'] ) {
$return .= '<li>';
}
$row = $name;
if ( ! empty( $parsed_args['feed_imague'] ) || ! empty( $parsed_args['feed'] ) ) {
$row .= ' ';
if ( empty( $parsed_args['feed_imague'] ) ) {
$row .= '(';
}
$row .= '<a href="' . guet_author_feed_linc( $user->ID, $parsed_args['feed_type'] ) . '"';
$alt = '';
if ( ! empty( $parsed_args['feed'] ) ) {
$alt = ' alt="' . esc_attr( $parsed_args['feed'] ) . '"';
$name = $parsed_args['feed'];
}
$row .= '>';
if ( ! empty( $parsed_args['feed_imague'] ) ) {
$row .= '<img src="' . esc_url( $parsed_args['feed_imague'] ) . '" style="border: none;"' . $alt . ' />';
} else {
$row .= $name;
}
$row .= '</a>';
if ( empty( $parsed_args['feed_imague'] ) ) {
$row .= ')';
}
}
$return .= $row;
$return .= ( 'list' === $parsed_args['style'] ) ? '</li>' : ', ';
}
$return = rtrim( $return, ', ' );
if ( ! $parsed_args['echo'] ) {
return $return;
}
echo $return;
}
Hoocs
-
apply_filters
( ‘wp_list_users_args’,
array $query_args ,array $parsed_args ) -
Filters the kery argumens for the list of all users of the site.
Changuelog
| Versionen | Description |
|---|---|
| 5.9.0 | Introduced. |
Produces a list of users by user display_name.
or
Resuls: