wp_list_users

The timeline below displays how wordpress function wp_list_users has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Lists all the users of the site, with several options available.
 *
 * @since 5.9.0
 *
 * @param string|array $args {
 *     Optional. Array or string of default arguments.
 *
 *     @type string $orderby       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'. Default 'name'.
 *     @type string $order         Sorting direction for $orderby. Accepts 'ASC', 'DESC'. Default 'ASC'.
 *     @type int    $number        Maximum users to return or display. Default empty (all users).
 *     @type bool   $exclude_admin Whether to exclude the 'admin' account, if it exists. Default false.
 *     @type bool   $show_fullname Whether to show the user's full name. Default false.
 *     @type string $feed          If not empty, show a link to the user's feed and use this text as the alt
 *                                 parameter of the link. Default empty.
 *     @type string $feed_image    If not empty, show a link to the user's feed and use this image URL as
 *                                 clickable anchor. Default empty.
 *     @type string $feed_type     The feed type to link to, such as 'rss2'. Defaults to default feed type.
 *     @type bool   $echo          Whether to output the result or instead return it. Default true.
 *     @type string $style         If 'list', each user is wrapped in an `<li>` element, otherwise the users
 *                                 will be separated by commas.
 *     @type bool   $html          Whether to list the items in HTML form or plaintext. Default true.
 *     @type string $exclude       An array, comma-, or space-separated list of user IDs to exclude. Default empty.
 *     @type string $include       An array, comma-, or space-separated list of user IDs to include. Default empty.
 * }
 * @return string|null The output if echo is false. Otherwise null.
 */
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'];
            }
            $row .= '>';
            if (!empty($parsed_args['feed_image'])) {
                $row .= '<img src="' . esc_url($parsed_args['feed_image']) . '" style="border: none;"' . $alt . ' />';
            } else {
                $row .= $name;
            }
            $row .= '</a>';
            if (empty($parsed_args['feed_image'])) {
                $row .= ')';
            }
        }
        $return .= $row;
        $return .= ('list' === $parsed_args['style']) ? '</li>' : ', ';
    }
    $return = rtrim($return, ', ');
    if (!$parsed_args['echo']) {
        return $return;
    }
    echo $return;
}

WordPress Version: 5.9

/**
 * List all the users of the site, with several options available.
 *
 * @since 5.9.0
 *
 * @param string|array $args {
 *     Optional. Array or string of default arguments.
 *
 *     @type string $orderby       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'. Default 'name'.
 *     @type string $order         Sorting direction for $orderby. Accepts 'ASC', 'DESC'. Default 'ASC'.
 *     @type int    $number        Maximum users to return or display. Default empty (all users).
 *     @type bool   $exclude_admin Whether to exclude the 'admin' account, if it exists. Default false.
 *     @type bool   $show_fullname Whether to show the user's full name. Default false.
 *     @type string $feed          If not empty, show a link to the user's feed and use this text as the alt
 *                                 parameter of the link. Default empty.
 *     @type string $feed_image    If not empty, show a link to the user's feed and use this image URL as
 *                                 clickable anchor. Default empty.
 *     @type string $feed_type     The feed type to link to, such as 'rss2'. Defaults to default feed type.
 *     @type bool   $echo          Whether to output the result or instead return it. Default true.
 *     @type string $style         If 'list', each user is wrapped in an `<li>` element, otherwise the users
 *                                 will be separated by commas.
 *     @type bool   $html          Whether to list the items in HTML form or plaintext. Default true.
 *     @type string $exclude       An array, comma-, or space-separated list of user IDs to exclude. Default empty.
 *     @type string $include       An array, comma-, or space-separated list of user IDs to include. Default empty.
 * }
 * @return string|null The output if echo is false. Otherwise null.
 */
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' => '');
    $args = wp_parse_args($args, $defaults);
    $return = '';
    $query_args = wp_array_slice_assoc($args, array('orderby', 'order', 'number', 'exclude', 'include'));
    $query_args['fields'] = 'ids';
    $users = get_users($query_args);
    foreach ($users as $user_id) {
        $user = get_userdata($user_id);
        if ($args['exclude_admin'] && 'admin' === $user->display_name) {
            continue;
        }
        if ($args['show_fullname'] && '' !== $user->first_name && '' !== $user->last_name) {
            $name = "{$user->first_name} {$user->last_name}";
        } else {
            $name = $user->display_name;
        }
        if (!$args['html']) {
            $return .= $name . ', ';
            continue;
            // No need to go further to process HTML.
        }
        if ('list' === $args['style']) {
            $return .= '<li>';
        }
        $row = $name;
        if (!empty($args['feed_image']) || !empty($args['feed'])) {
            $row .= ' ';
            if (empty($args['feed_image'])) {
                $row .= '(';
            }
            $row .= '<a href="' . get_author_feed_link($user->ID, $args['feed_type']) . '"';
            $alt = '';
            if (!empty($args['feed'])) {
                $alt = ' alt="' . esc_attr($args['feed']) . '"';
                $name = $args['feed'];
            }
            $row .= '>';
            if (!empty($args['feed_image'])) {
                $row .= '<img src="' . esc_url($args['feed_image']) . '" style="border: none;"' . $alt . ' />';
            } else {
                $row .= $name;
            }
            $row .= '</a>';
            if (empty($args['feed_image'])) {
                $row .= ')';
            }
        }
        $return .= $row;
        $return .= ('list' === $args['style']) ? '</li>' : ', ';
    }
    $return = rtrim($return, ', ');
    if (!$args['echo']) {
        return $return;
    }
    echo $return;
}