wp_list_users( string|array $args = array() ): string|null
- Since
- 5.9.0
- Source
wp-includes/user.php:913
Compatibility
- WordPress
- since 5.9.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$argsstring|arrayoptional- Array or string of default arguments.Default:
array()$orderbystringdefault: 'name'How to sort the users. Accepts 'nicename', 'email', 'url', 'registered', 'user_nicename', 'user_email', 'user_url', 'user_registered', 'name', 'display_name', 'post_count', 'ID', 'meta_value', 'user_login'.$orderstringdefault: 'ASC'Sorting direction for $orderby. Accepts 'ASC', 'DESC'.$numberintdefault: empty (all users)Maximum users to return or display.$exclude_adminbooldefault: trueWhether to exclude the 'admin' account, if it exists.$show_fullnamebooldefault: falseWhether to show the user's full name.$feedstringdefault: emptyIf not empty, show a link to the user's feed and use this text as the alt parameter of the link.$feed_imagestringdefault: emptyIf not empty, show a link to the user's feed and use this image URL as clickable anchor.$feed_typestringThe feed type to link to, such as 'rss2'. Defaults to default feed type.$echobooldefault: trueWhether to output the result or instead return it.$stylestringIf 'list', each user is wrapped in an<li>element, otherwise the users will be separated by commas.$htmlbooldefault: trueWhether to list the items in HTML form or plaintext.$excludestringdefault: emptyAn array, comma-, or space-separated list of user IDs to exclude.$includestringdefault: emptyAn array, comma-, or space-separated list of user IDs to include.
Return value
string|null- The output if echo is false. Otherwise null.
Performance profile
How much work a call to wp_list_users() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Scales with input
- Instructions
- 35–37
- Plugin surface
- 1 hook
- Called by
- 0
Reaches the database via get_users().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 140.
Third-party callbacks on 'wp_list_users_args' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()called directly - querycontent query
get_users()called directly - optionoption read or write
get_option()one call below wp_list_users()
Further down the call graph this can also reach cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_list_users() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 35–37 | wp_parse_args(), wp_array_slice_assoc(), apply_filters(), get_users(), rtrim() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 140 instructions, 35–37 executed per call, 17 branches. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 1
One hook fires while wp_list_users() runs, in this order:
- apply_filters( wp_list_users_args )filterline 945 (+32 into the body)
Filters the query arguments for the list of all users of the site.
Uses · 9
- wp_parse_args()Merges user defined arguments into defaults array.
- wp_array_slice_assoc()Extracts a slice of an array, given a list of keys.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- get_users()Retrieves list of users matching criteria.
- get_userdata()Retrieves user info by user ID.
- _x()Retrieves translated string with gettext context.
- get_author_feed_link()Retrieves the feed link for a given author.
- esc_attr()Escaping for HTML attributes.
- esc_url()Checks and cleans a URL.
Source code
function wp_list_users( $args = array() ) { $defaults = array( 'orderby' => 'name', 'order' => 'ASC', 'number' => '', 'exclude_admin' => true, 'show_fullname' => false, 'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true, 'style' => 'list', 'html' => true, 'exclude' => '', 'include' => '', ); $parsed_args = wp_parse_args( $args, $defaults ); $return = ''; $query_args = wp_array_slice_assoc( $parsed_args, array( 'orderby', 'order', 'number', 'exclude', 'include' ) ); $query_args['fields'] = 'ids'; /** * Filters the query arguments for the list of all users of the site. * * @since 6.1.0 * * @param array $query_args The query arguments for get_users(). * @param array $parsed_args The arguments passed to wp_list_users() combined with the defaults. */ $query_args = apply_filters( 'wp_list_users_args', $query_args, $parsed_args ); $users = get_users( $query_args ); foreach ( $users as $user_id ) { $user = get_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 process HTML. } if ( 'list' === $parsed_args['style'] ) { $return .= '<li>'; } $row = $name; if ( ! empty( $parsed_args['feed_image'] ) || ! empty( $parsed_args['feed'] ) ) { $row .= ' '; if ( empty( $parsed_args['feed_image'] ) ) { $row .= '('; } $row .= '<a href="' . get_author_feed_link( $user->ID, $parsed_args['feed_type'] ) . '"'; $alt = ''; if ( ! empty( $parsed_args['feed'] ) ) { $alt = ' alt="' . esc_attr( $parsed_args['feed'] ) . '"'; $name = $parsed_args['feed']; }Changelog
Introduced in 5.9.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 tag, from
src/wp-includes/user.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.