wp_list_authors( string|array $args = '' ): void|string
- Since
- 1.2.0
- Source
wp-includes/author-template.php:454
Compatibility
- WordPress
- since 1.2.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:
''$orderbystringdefault: 'name'How to sort the authors. 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 authors)Maximum authors to return or display.$optioncountbooldefault: falseShow the count in parenthesis next to the author's name.$exclude_adminbooldefault: trueWhether to exclude the 'admin' account, if it exists.$show_fullnamebooldefault: falseWhether to show the author's full name.$hide_emptybooldefault: trueWhether to hide any authors with no posts.$feedstringdefault: emptyIf not empty, show a link to the author's feed and use this text as the alt parameter of the link.$feed_imagestringdefault: emptyIf not empty, show a link to the author's feed and use this image URL as clickable anchor.$feed_typestringdefault: is the value of get_default_feed()The feed type to link to. Possible values include 'rss2', 'atom'.$echobooldefault: trueWhether to output the result or instead return it.$stylestringIf 'list', each author is wrapped in an<li>element, otherwise the authors will be separated by commas.$htmlbooldefault: trueWhether to list the items in HTML form or plaintext.$excludeint[]|stringdefault: emptyArray or comma/space-separated list of author IDs to exclude.$includeint[]|stringdefault: emptyArray or comma/space-separated list of author IDs to include.
Return value
void|string- Void if 'echo' argument is true, list of authors if 'echo' is false.
Performance profile
How much work a call to wp_list_authors() 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
- 44–63
- Plugin surface
- 2 hooks
- Called by
- 1
Reaches the database via ->get_results().
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 198.
Third-party callbacks on 'wp_list_authors_args', 'pre_wp_list_authors_post_counts_query' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly - querycontent query
get_users()called directly - sqldatabase query
->get_results()called directly - optionoption read or write
get_option()one call below wp_list_authors()
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 · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_list_authors() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
is_array($post_counts) | 44–46 | wp_parse_args(), wp_array_slice_assoc(), apply_filters(), get_users(), apply_filters(), rtrim() |
!is_array($post_counts) && $post_counts_query | 61–63 | wp_parse_args(), wp_array_slice_assoc(), apply_filters(), get_users(), apply_filters(), get_private_posts_cap_sql(), ->get_results(), rtrim() |
This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 198 instructions, 44–63 executed per call, 24 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 · 2
2 hooks fire while wp_list_authors() runs, in this order:
- apply_filters( wp_list_authors_args )filterline 490 (+36 into the body)
Filters the query arguments for the list of all authors of the site.
- apply_filters( pre_wp_list_authors_post_counts_query )filterline 502 (+48 into the body)
Filters whether to short-circuit performing the query for author post counts.
Uses · 11
- 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_private_posts_cap_sql()Retrieves the private post SQL based on capability.
- get_userdata()Retrieves user info by user ID.
- _x()Retrieves translated string with gettext context.
- esc_url()Checks and cleans a URL.
- get_author_posts_url()Retrieves the URL to the author page for the user with the ID provided.
- get_author_feed_link()Retrieves the feed link for a given author.
- esc_attr()Escaping for HTML attributes.
Used by · 1
- list_authors()Lists authors.
Source code
function wp_list_authors( $args = '' ) { global $wpdb; $defaults = array( 'orderby' => 'name', 'order' => 'ASC', 'number' => '', 'optioncount' => false, 'exclude_admin' => true, 'show_fullname' => false, 'hide_empty' => true, '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 authors 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_authors() combined with the defaults. */ $query_args = apply_filters( 'wp_list_authors_args', $query_args, $parsed_args ); $authors = get_users( $query_args ); /** * Filters whether to short-circuit performing the query for author post counts. * * @since 6.1.0 * * @param int[]|false $post_counts Array of post counts, keyed by author ID. * @param array $parsed_args The arguments passed to wp_list_authors() combined with the defaults. */ $post_counts = apply_filters( 'pre_wp_list_authors_post_counts_query', false, $parsed_args ); if ( ! is_array( $post_counts ) ) { $post_counts = array(); $post_counts_query = $wpdb->get_results( "SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE " . get_private_posts_cap_sql( 'post' ) . ' GROUP BY post_author' ); foreach ( (array) $post_counts_query as $row ) { $post_counts[ $row->post_author ] = $row->count; } } foreach ( $authors as $author_id ) { $posts = $post_counts[ $author_id ] ?? 0; if ( ! $posts && $parsed_args['hide_empty'] ) { continue; } $author = get_userdata( $author_id ); if ( $parsed_args['exclude_admin'] && 'admin' === $author->display_name ) { continue; } if ( $parsed_args['show_fullname'] && $author->first_name && $author->last_name ) { $name = sprintf( /* translators: 1: User's first name, 2: Last name. */Changelog
Introduced in 1.2.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/author-template.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.