Make WordPress Core


Ignore:
Timestamp:
09/20/2022 04:24:56 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Users: Make wp_list_authors() and wp_list_users() filterable.

This commit adds three filters to customize the wp_list_authors() and wp_list_users() output:

  • wp_list_authors_args: Filters the query arguments for the list of all authors of the site.
  • pre_wp_list_authors_post_counts_query: Filters whether to short-circuit performing the query for author post counts. This may be useful to account for custom post types or post statuses.
  • wp_list_users_args: Filters the query arguments for the list of all users of the site.

Follow-up to [979], [3848], [5135], [5727], [31653], [52064], [53486], [53501].

Props kevinB, wonderboymusic, DrewAPicture, Mte90, audrasjb, rafiahmedd, costdev, nacin, afercia, chetan200891, hellofromTonya, TimothyBlynJacobs, chaion07, SergeyBiryukov.
Fixes #17025.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/user.php

    r54182 r54262  
    812812        );
    813813
    814         $args = wp_parse_args( $args, $defaults );
     814        $parsed_args = wp_parse_args( $args, $defaults );
    815815
    816816        $return = '';
    817817
    818         $query_args           = wp_array_slice_assoc( $args, array( 'orderby', 'order', 'number', 'exclude', 'include' ) );
     818        $query_args           = wp_array_slice_assoc( $parsed_args, array( 'orderby', 'order', 'number', 'exclude', 'include' ) );
    819819        $query_args['fields'] = 'ids';
    820         $users                = get_users( $query_args );
     820
     821        /**
     822         * Filters the query arguments for the list of all users of the site.
     823         *
     824         * @since 6.1.0
     825         *
     826         * @param array $query_args  The query arguments for get_users().
     827         * @param array $parsed_args The arguments passed to wp_list_users() combined with the defaults.
     828         */
     829        $query_args = apply_filters( 'wp_list_users_args', $query_args, $parsed_args );
     830
     831        $users = get_users( $query_args );
    821832
    822833        foreach ( $users as $user_id ) {
    823834                $user = get_userdata( $user_id );
    824835
    825                 if ( $args['exclude_admin'] && 'admin' === $user->display_name ) {
     836                if ( $parsed_args['exclude_admin'] && 'admin' === $user->display_name ) {
    826837                        continue;
    827838                }
    828839
    829                 if ( $args['show_fullname'] && '' !== $user->first_name && '' !== $user->last_name ) {
     840                if ( $parsed_args['show_fullname'] && '' !== $user->first_name && '' !== $user->last_name ) {
    830841                        $name = sprintf(
    831842                                /* translators: 1: User's first name, 2: Last name. */
    … …  
    838849                }
    839850
    840                 if ( ! $args['html'] ) {
     851                if ( ! $parsed_args['html'] ) {
    841852                        $return .= $name . ', ';
    842853
    … …  
    844855                }
    845856
    846                 if ( 'list' === $args['style'] ) {
     857                if ( 'list' === $parsed_args['style'] ) {
    847858                        $return .= '<li>';
    848859                }
    … …  
    850861                $row = $name;
    851862
    852                 if ( ! empty( $args['feed_image'] ) || ! empty( $args['feed'] ) ) {
     863                if ( ! empty( $parsed_args['feed_image'] ) || ! empty( $parsed_args['feed'] ) ) {
    853864                        $row .= ' ';
    854                         if ( empty( $args['feed_image'] ) ) {
     865                        if ( empty( $parsed_args['feed_image'] ) ) {
    855866                                $row .= '(';
    856867                        }
    857868
    858                         $row .= '<a href="' . get_author_feed_link( $user->ID, $args['feed_type'] ) . '"';
     869                        $row .= '<a href="' . get_author_feed_link( $user->ID, $parsed_args['feed_type'] ) . '"';
    859870
    860871                        $alt = '';
    861                         if ( ! empty( $args['feed'] ) ) {
    862                                 $alt  = ' alt="' . esc_attr( $args['feed'] ) . '"';
    863                                 $name = $args['feed'];
     872                        if ( ! empty( $parsed_args['feed'] ) ) {
     873                                $alt  = ' alt="' . esc_attr( $parsed_args['feed'] ) . '"';
     874                                $name = $parsed_args['feed'];
    864875                        }
    865876
    866877                        $row .= '>';
    867878
    868                         if ( ! empty( $args['feed_image'] ) ) {
    869                                 $row .= '<img src="' . esc_url( $args['feed_image'] ) . '" style="border: none;"' . $alt . ' />';
     879                        if ( ! empty( $parsed_args['feed_image'] ) ) {
     880                                $row .= '<img src="' . esc_url( $parsed_args['feed_image'] ) . '" style="border: none;"' . $alt . ' />';
    870881                        } else {
    871882                                $row .= $name;
    … …  
    874885                        $row .= '</a>';
    875886
    876                         if ( empty( $args['feed_image'] ) ) {
     887                        if ( empty( $parsed_args['feed_image'] ) ) {
    877888                                $row .= ')';
    878889                        }
    … …  
    880891
    881892                $return .= $row;
    882                 $return .= ( 'list' === $args['style'] ) ? '</li>' : ', ';
     893                $return .= ( 'list' === $parsed_args['style'] ) ? '</li>' : ', ';
    883894        }
    884895
    885896        $return = rtrim( $return, ', ' );
    886897
    887         if ( ! $args['echo'] ) {
     898        if ( ! $parsed_args['echo'] ) {
    888899                return $return;
    889900        }
Note: See TracChangeset for help on using the changeset viewer.