prepare( "SELECT post_author, COUNT(post_author) as contributions FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'revision' AND post_status = 'inherit' AND post_name NOT LIKE ( %s ) GROUP BY post_author ORDER BY contributions DESC LIMIT %d", $post_id, '%' . $post_id . '-autosave%', $limit ); $revisions_counts_result = $wpdb->get_results( $query ); $authors_by_contribution_count = array(); foreach ( (array) $revisions_counts_result as $revisions_count ) { $contributions_count = intval( $revisions_count->contributions ); $authors_by_contribution_count[ $revisions_count->post_author ] = $contributions_count; } // Add the current post to the contributions count. if ( isset( $authors_by_contribution_count[ $post_author ] ) ) { $authors_by_contribution_count[ $post_author ]++; } else { $authors_by_contribution_count[ $post_author ] = 1; } return $authors_by_contribution_count; } function get_contributors_block(): string { $post_author = get_post()->post_author; $contributors = get_contributors( $post_author ); if ( count( $contributors ) === 0 ) { return null; } $contributor_list_items = array_map( function ( int $contributor_id, int $count ): string { $userdata = get_userdata( $contributor_id ); $avatar = get_avatar( $contributor_id, 72, '', '', [ 'height' => 36, 'width' => 36 ] ); $link = esc_url( get_author_posts_url( $contributor_id ) ); $link_title = esc_attr( sprintf( /* translators: %1$s is replaced with the user's display name; %2$s is the user's nicename */ __( 'Posts by %1$s ( @%2$s )', 'p2020' ), $userdata->display_name, $userdata->user_nicename ) ); $name = esc_html( $userdata->display_name ); $revisions = esc_html( /* translators: %s is replaced with the number of revisions */ sprintf( _n( '%s revision', '%s revisions', $count, 'p2020' ), $count ) ); return <<
$avatar
$name
$revisions
LISTITEM; }, array_keys( $contributors ), $contributors ); $contributor_list_items_imploded = implode( '', $contributor_list_items ); $heading_text = esc_html__( 'Contributors', 'p2020' ); return <<

$heading_text

    $contributor_list_items_imploded
CONTRIBUTORS; }