diff --git a/wp-includes/author-template.php b/wp-includes/author-template.php index b4ad2906e2..b4c344dcbc 100644 --- a/wp-includes/author-template.php +++ b/wp-includes/author-template.php @@ -450,32 +450,63 @@ function wp_list_authors( $args = '' ) { 'include' => '', ); - $args = wp_parse_args( $args, $defaults ); + $parsed_args = wp_parse_args( $args, $defaults ); $return = ''; - $query_args = wp_array_slice_assoc( $args, array( 'orderby', 'order', 'number', 'exclude', 'include' ) ); + $query_args = wp_array_slice_assoc( $parsed_args, array( 'orderby', 'order', 'number', 'exclude', 'include' ) ); $query_args['fields'] = 'ids'; - $authors = get_users( $query_args ); - $author_count = array(); - foreach ( (array) $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' ) as $row ) { - $author_count[ $row->post_author ] = $row->count; + /** + * 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 ); + $post_counts = array(); + + /** + * 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 = $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 as $row ) { + $post_counts[ $row->post_author ] = $row->count; + } } - foreach ( $authors as $author_id ) { - $posts = isset( $author_count[ $author_id ] ) ? $author_count[ $author_id ] : 0; - if ( ! $posts && $args['hide_empty'] ) { + foreach ( $authors as $author_id ) { + $posts = isset( $post_counts[ $author_id ] ) ? $post_counts[ $author_id ] : 0; + + if ( ! $posts && $parsed_args['hide_empty'] ) { continue; } $author = get_userdata( $author_id ); - if ( $args['exclude_admin'] && 'admin' === $author->display_name ) { + if ( $parsed_args['exclude_admin'] && 'admin' === $author->display_name ) { continue; } - if ( $args['show_fullname'] && $author->first_name && $author->last_name ) { + if ( $parsed_args['show_fullname'] && $author->first_name && $author->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' ), @@ -486,13 +517,13 @@ function wp_list_authors( $args = '' ) { $name = $author->display_name; } - if ( ! $args['html'] ) { + if ( ! $parsed_args['html'] ) { $return .= $name . ', '; continue; // No need to go further to process HTML. } - if ( 'list' === $args['style'] ) { + if ( 'list' === $parsed_args['style'] ) { $return .= '
  • '; } @@ -504,46 +535,46 @@ function wp_list_authors( $args = '' ) { $name ); - if ( ! empty( $args['feed_image'] ) || ! empty( $args['feed'] ) ) { + if ( ! empty( $parsed_args['feed_image'] ) || ! empty( $parsed_args['feed'] ) ) { $link .= ' '; - if ( empty( $args['feed_image'] ) ) { + if ( empty( $parsed_args['feed_image'] ) ) { $link .= '('; } - $link .= 'ID, $parsed_args['feed_type'] ) . '"'; $alt = ''; - if ( ! empty( $args['feed'] ) ) { - $alt = ' alt="' . esc_attr( $args['feed'] ) . '"'; - $name = $args['feed']; + if ( ! empty( $parsed_args['feed'] ) ) { + $alt = ' alt="' . esc_attr( $parsed_args['feed'] ) . '"'; + $name = $parsed_args['feed']; } $link .= '>'; - if ( ! empty( $args['feed_image'] ) ) { - $link .= ''; + if ( ! empty( $parsed_args['feed_image'] ) ) { + $link .= ''; } else { $link .= $name; } $link .= ''; - if ( empty( $args['feed_image'] ) ) { + if ( empty( $parsed_args['feed_image'] ) ) { $link .= ')'; } } - if ( $args['optioncount'] ) { + if ( $parsed_args['optioncount'] ) { $link .= ' (' . $posts . ')'; } $return .= $link; - $return .= ( 'list' === $args['style'] ) ? '
  • ' : ', '; + $return .= ( 'list' === $parsed_args['style'] ) ? '' : ', '; } $return = rtrim( $return, ', ' ); - if ( $args['echo'] ) { + if ( $parsed_args['echo'] ) { echo $return; } else { return $return; diff --git a/wp-includes/user.php b/wp-includes/user.php index 8f5ab52e5a..0368e21753 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -811,22 +811,33 @@ function wp_list_users( $args = array() ) { 'include' => '', ); - $args = wp_parse_args( $args, $defaults ); + $parsed_args = wp_parse_args( $args, $defaults ); $return = ''; - $query_args = wp_array_slice_assoc( $args, array( 'orderby', 'order', 'number', 'exclude', 'include' ) ); + $query_args = wp_array_slice_assoc( $parsed_args, array( 'orderby', 'order', 'number', 'exclude', 'include' ) ); $query_args['fields'] = 'ids'; - $users = get_users( $query_args ); + + /** + * 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 ( $args['exclude_admin'] && 'admin' === $user->display_name ) { + if ( $parsed_args['exclude_admin'] && 'admin' === $user->display_name ) { continue; } - if ( $args['show_fullname'] && '' !== $user->first_name && '' !== $user->last_name ) { + 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' ), @@ -837,54 +848,54 @@ function wp_list_users( $args = array() ) { $name = $user->display_name; } - if ( ! $args['html'] ) { + if ( ! $parsed_args['html'] ) { $return .= $name . ', '; continue; // No need to go further to process HTML. } - if ( 'list' === $args['style'] ) { + if ( 'list' === $parsed_args['style'] ) { $return .= '
  • '; } $row = $name; - if ( ! empty( $args['feed_image'] ) || ! empty( $args['feed'] ) ) { + if ( ! empty( $parsed_args['feed_image'] ) || ! empty( $parsed_args['feed'] ) ) { $row .= ' '; - if ( empty( $args['feed_image'] ) ) { + if ( empty( $parsed_args['feed_image'] ) ) { $row .= '('; } - $row .= 'ID, $parsed_args['feed_type'] ) . '"'; $alt = ''; - if ( ! empty( $args['feed'] ) ) { - $alt = ' alt="' . esc_attr( $args['feed'] ) . '"'; - $name = $args['feed']; + if ( ! empty( $parsed_args['feed'] ) ) { + $alt = ' alt="' . esc_attr( $parsed_args['feed'] ) . '"'; + $name = $parsed_args['feed']; } $row .= '>'; - if ( ! empty( $args['feed_image'] ) ) { - $row .= ''; + if ( ! empty( $parsed_args['feed_image'] ) ) { + $row .= ''; } else { $row .= $name; } $row .= ''; - if ( empty( $args['feed_image'] ) ) { + if ( empty( $parsed_args['feed_image'] ) ) { $row .= ')'; } } $return .= $row; - $return .= ( 'list' === $args['style'] ) ? '
  • ' : ', '; + $return .= ( 'list' === $parsed_args['style'] ) ? '' : ', '; } $return = rtrim( $return, ', ' ); - if ( ! $args['echo'] ) { + if ( ! $parsed_args['echo'] ) { return $return; } echo $return; diff --git a/wp-includes/version.php b/wp-includes/version.php index e691336acd..9a913b63f4 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.1-alpha-54261'; +$wp_version = '6.1-alpha-54262'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.