Make WordPress Core

Opened 14 years ago

Closed 2 years ago

Last modified 2 years ago

#15145 closed enhancement (fixed)

Add a wp_list_users() template tag

Reported by: greenshady's profile greenshady Owned by: hellofromtonya's profile hellofromTonya
Milestone: 5.9 Priority: normal
Severity: normal Version: 3.1
Component: Users Keywords: has-patch has-unit-tests commit
Focuses: template Cc:

Description

Now that get_users() has been implemented (#14572), I propose we add a function called wp_list_users() that handles a basic list of users similar to wp_list_authors(). WordPress has long needed a function for handling this.

The arguments for the function would simply be the same arguments used for get_users(). The wp_list_users() function would basically be a function for outputting the HTML. The function should also have the ability to link to the user's archive page and output a link to the user's RSS feed.

This would make it easy for theme developers and users to be able to create a users list without a lot of PHP work.

An alternate idea might be to push a few more arguments into the wp_list_authors() function, but I don't think that's the best route to go since its primary function is to list users that have written posts.

Attachments (3)

15145.diff (4.3 KB) - added by rohan013 10 years ago.
Adds a new function wp_list_users() which is very similar to wp_list_authors except the 'optioncount' and 'hide_empty' args since they are not valid here.
15145.2.diff (4.3 KB) - added by Mte90 7 years ago.
patch refreshed
15145.3.diff (10.9 KB) - added by costdev 2 years ago.
Refresh + Unit tests added.

Download all attachments as: .zip

Change History (35)

#1 @scribu
14 years ago

  • Cc scribu added
  • Component changed from Users to Template

#2 @Utkarsh
14 years ago

  • Cc admin@… added

#3 @markjaquith
13 years ago

  • Milestone changed from Awaiting Review to Future Release

#4 @nacin
10 years ago

  • Component changed from Template to Users
  • Focuses template added
  • Keywords needs-patch added

Would need a patch.

@rohan013
10 years ago

Adds a new function wp_list_users() which is very similar to wp_list_authors except the 'optioncount' and 'hide_empty' args since they are not valid here.

#5 @rohan013
10 years ago

  • Keywords has-patch added; needs-patch removed

#6 @chriscct7
8 years ago

  • Keywords needs-refresh added

@Mte90
7 years ago

patch refreshed

#7 @Mte90
7 years ago

  • Keywords dev-feedback added; needs-refresh removed

This ticket was mentioned in Slack in #core by mte90. View the logs.


6 years ago

#9 @afercia
6 years ago

  • Keywords needs-refresh added

In 15145.2.diff naming a variable $return is potentially confusing, for better code readability I'd suggest to rename it. Also needs some minor coding standards.

This ticket was mentioned in PR #1059 on WordPress/wordpress-develop by Mte90.


3 years ago
#10

  • Keywords needs-refresh removed

Add wp_list_users function.

Trac ticket: https://core.trac.wordpress.org/ticket/15145

#11 @Mte90
3 years ago

Refreshed also this one but is still missing unit tests

#12 @SergeyBiryukov
3 years ago

  • Milestone changed from Future Release to 5.8

#13 @audrasjb
3 years ago

  • Keywords needs-refresh added; dev-feedback removed
  • Owner set to audrasjb
  • Status changed from new to reviewing

Hey,
I'm not super convinced by the style parameter. First it doesn't exist on related functions like wp_list_pages, second I don't think the function should output anything else than a list. But it would be nice to add a hook to help to filter the output, just like wp_list_pages does:

    /**
     * Filters the HTML output of the pages to list.
     *
     * @since 5.8.0
     *
     * @see wp_list_users()
     *
     * @param string    $output      HTML output of the users list.
     * @param array     $parsed_args An array of user-listing arguments. See wp_list_users()
     *                               for information on accepted arguments.
     * @param WP_User[] $users       Array of the user objects.
     */
    $html = apply_filters( 'wp_list_users', $output, $parsed_args, $users );

Also, the PR needs an @since mention :)

#14 @Mte90
3 years ago

Updated the patch with this feedback except for the style.

Maybe it is the case to move the style part to a function like get_the_term_list for users?

This ticket was mentioned in Slack in #core by mte90. View the logs.


3 years ago

#16 @audrasjb
3 years ago

@Mte90 ok the patch looks good to me, thanks for the update. By the way, there are some minor check failures on the proposed PR :)

#17 @Mte90
3 years ago

I saw that errors but they are not on the right lines and so on and I cannot rerun jobs to update the checks itself.

Mte90 commented on PR #1059:


3 years ago
#18

I can't rerun the jobs as the linting is wrong as that lines are clean and report errors on the wrong lines.

#19 @desrosj
3 years ago

  • Keywords needs-unit-tests added; needs-refresh removed
  • Milestone changed from 5.8 to 5.9

Today is feature freeze for 5.8. Since a committer has not had a chance to review this one, I'm going to punt.

I'm putting this in 5.9 instead of Future Release, though. And I'll try to return to it in the next cycle.

@Mte90 I did push an update to your branch that should fix the coding standards issues! Also, it would be great if we could add some unit tests. Looks like wp_list_authors() has some. We could probably use those as a starting point.

#20 @Mte90
3 years ago

Thanks for the help I will check for the unit tests :-)

#21 @Mte90
3 years ago

I did the unit tests months ago but I cannot check the logs now to see the errors as they are expired.

@costdev
2 years ago

Refresh + Unit tests added.

#22 @costdev
2 years ago

  • Keywords has-unit-tests added; needs-unit-tests removed

Patch 15145.3.diff refreshes the previous patch against trunk and adds unit tests for the wp_list_users() function.

The tests for wp_list_authors() and unit tests written for wp_list_users() in PR 1059 test arguments like exclude. Such arguments are handled by the call to get_users() and are not touched by wp_list_users().

This patch does not test these arguments and instead tests only the expected behaviour of wp_list_users().

#23 @audrasjb
2 years ago

The patch and tests look good to me. I tested the $echo/$html/$style param variations and it works fine on my side.

This ticket was mentioned in Slack in #core by audrasjb. View the logs.


2 years ago

#25 @hellofromTonya
2 years ago

  • Owner changed from audrasjb to hellofromTonya

Reassigning review to me in preparation for commit consideration prior to 5.9 feature freeze.

#26 follow-up: @audrasjb
2 years ago

I saw a few inconsistencies between this functions and other existing functions like wp_list_pages or wp_list_categories.

for instance, if $style !== 'list' the wp_list_categories function uses <br /> as a separator.

This ticket was mentioned in PR #1837 on WordPress/wordpress-develop by costdev.


2 years ago
#27

wp_list_users() makes it easy for extenders to create a basic list of users, similar to wp_list_authors().

Trac ticket: https://core.trac.wordpress.org/ticket/15145

#28 in reply to: ↑ 26 @hellofromTonya
2 years ago

Replying to audrasjb:

I saw a few inconsistencies between this functions and other existing functions like wp_list_pages or wp_list_categories.

for instance, if $style !== 'list' the wp_list_categories function uses <br /> as a separator.

I see differences between the existing functions themselves. Guessing each has been tailored for its specific list of things.

This new function most closely resembles wp_list_authors().

#29 @hellofromTonya
2 years ago

  • Keywords commit added

PR 1837 includes the patch and tests. It's approved. Marking for commit.

#30 @hellofromTonya
2 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 52064:

Users: Introduce wp_list_users() function.

Introduces a new function called wp_list_users(). Similar to other list functions such as wp_list_authors(), it lists all the users of the site. Options are available to configure the HTML output.

Following the same pattern of the other list functions, the list's HTML output is rendered by default. Setting the echo argument to false, returns the list's HTML output.

A new test class is included.

Props afercia, audrasjb, chriscct7, costdev, desrosj, greenshady, hellofromTonya, mte90, nacin, rohan013, sergeybiryukov.
Fixes #15145.

hellofromtonya commented on PR #1059:


2 years ago
#32

This patch was pulled into PR #1837 which was committed via changeset https://core.trac.wordpress.org/changeset/52064.

Note: See TracTickets for help on using tickets.