diff --git src/wp-admin/includes/class-wp-users-list-table.php src/wp-admin/includes/class-wp-users-list-table.php
index 018654bdd2..33be7a1a93 100644
|
|
class WP_Users_List_Table extends WP_List_Table { |
387 | 387 | * Generate the list table rows. |
388 | 388 | * |
389 | 389 | * @since 3.1.0 |
| 390 | * @since 5.5.0 Include 'pending', 'future', and 'draft' posts in the count. |
390 | 391 | */ |
391 | 392 | public function display_rows() { |
392 | 393 | // Query the post counts for this page. |
393 | 394 | if ( ! $this->is_site_users ) { |
394 | | $post_counts = count_many_users_posts( array_keys( $this->items ) ); |
| 395 | $post_counts = count_many_users_posts( array_keys( $this->items ), 'post', false, true ); |
395 | 396 | } |
396 | 397 | |
397 | 398 | foreach ( $this->items as $userid => $user_object ) { |
diff --git src/wp-includes/post.php src/wp-includes/post.php
index 10eee1d25f..e3dc43fbe7 100644
|
|
function get_private_posts_cap_sql( $post_type ) { |
6371 | 6371 | * |
6372 | 6372 | * @since 3.0.0 |
6373 | 6373 | * @since 4.3.0 Introduced the ability to pass an array of post types to `$post_type`. |
| 6374 | * @since 5.5.0 Added the parameter `$include_unpublished` which will include 'pending', 'future', and 'draft' |
| 6375 | * posts in the SQL. |
6374 | 6376 | * |
6375 | 6377 | * @see get_private_posts_cap_sql() |
6376 | 6378 | * @global wpdb $wpdb WordPress database abstraction object. |
6377 | 6379 | * |
6378 | | * @param string|string[] $post_type Single post type or an array of post types. |
6379 | | * @param bool $full Optional. Returns a full WHERE statement instead of just |
6380 | | * an 'andalso' term. Default true. |
6381 | | * @param int $post_author Optional. Query posts having a single author ID. Default null. |
6382 | | * @param bool $public_only Optional. Only return public posts. Skips cap checks for |
6383 | | * $current_user. Default false. |
| 6380 | * @param string|string[] $post_type Single post type or an array of post types. |
| 6381 | * @param bool $full Optional. Returns a full WHERE statement instead of just |
| 6382 | * an 'andalso' term. Default true. |
| 6383 | * @param int $post_author Optional. Query posts having a single author ID. Default null. |
| 6384 | * @param bool $public_only Optional. Only return public posts. Skips cap checks for |
| 6385 | * $current_user. Default false. |
| 6386 | * @param bool $include_unpublished Optional. Whether to include 'pending', 'future', and 'draft' posts. |
| 6387 | * Default false. |
6384 | 6388 | * @return string SQL WHERE code that can be added to a query. |
6385 | 6389 | */ |
6386 | | function get_posts_by_author_sql( $post_type, $full = true, $post_author = null, $public_only = false ) { |
| 6390 | function get_posts_by_author_sql( $post_type, $full = true, $post_author = null, $public_only = false, $include_unpublished = false ) { |
6387 | 6391 | global $wpdb; |
6388 | 6392 | |
6389 | 6393 | if ( is_array( $post_type ) ) { |
… |
… |
function get_posts_by_author_sql( $post_type, $full = true, $post_author = null, |
6428 | 6432 | $post_status_sql .= " OR post_status = 'private'"; |
6429 | 6433 | } // Else none. |
6430 | 6434 | } // Else none. |
| 6435 | |
| 6436 | if ( $include_unpublished ) { |
| 6437 | $post_status_sql .= " OR post_status = 'future' OR post_status = 'pending' OR post_status = 'draft'"; |
| 6438 | } |
6431 | 6439 | } |
6432 | 6440 | |
6433 | 6441 | $post_type_clauses[] = "( post_type = '" . $post_type . "' AND ( $post_status_sql ) )"; |
diff --git src/wp-includes/user.php src/wp-includes/user.php
index 6c6f87eced..107436fb95 100644
|
|
function count_user_posts( $userid, $post_type = 'post', $public_only = false ) |
393 | 393 | * Number of posts written by a list of users. |
394 | 394 | * |
395 | 395 | * @since 3.0.0 |
| 396 | * @since 5.5.0 Added the parameter `$include_unpublished` which will include 'pending', 'future', and 'draft' posts. |
396 | 397 | * |
397 | 398 | * @global wpdb $wpdb WordPress database abstraction object. |
398 | 399 | * |
399 | | * @param int[] $users Array of user IDs. |
400 | | * @param string|string[] $post_type Optional. Single post type or array of post types to check. Defaults to 'post'. |
401 | | * @param bool $public_only Optional. Only return counts for public posts. Defaults to false. |
| 400 | * @param int[] $users Array of user IDs. |
| 401 | * @param string|string[] $post_type Optional. Single post type or array of post types to check. Defaults to 'post'. |
| 402 | * @param bool $public_only Optional. Only return counts for public posts. Defaults to false. |
| 403 | * @param bool $include_unpublished Optional. Whether to include 'pending', 'future', and 'draft' posts. |
| 404 | * Default false. |
402 | 405 | * @return string[] Amount of posts each user has written, as strings, keyed by user ID. |
403 | 406 | */ |
404 | | function count_many_users_posts( $users, $post_type = 'post', $public_only = false ) { |
| 407 | function count_many_users_posts( $users, $post_type = 'post', $public_only = false, $include_unpublished = false ) { |
405 | 408 | global $wpdb; |
406 | 409 | |
407 | 410 | $count = array(); |
… |
… |
function count_many_users_posts( $users, $post_type = 'post', $public_only = fal |
410 | 413 | } |
411 | 414 | |
412 | 415 | $userlist = implode( ',', array_map( 'absint', $users ) ); |
413 | | $where = get_posts_by_author_sql( $post_type, true, null, $public_only ); |
| 416 | $where = get_posts_by_author_sql( $post_type, true, null, $public_only, $include_unpublished ); |
414 | 417 | |
415 | 418 | $result = $wpdb->get_results( "SELECT post_author, COUNT(*) FROM $wpdb->posts $where AND post_author IN ($userlist) GROUP BY post_author", ARRAY_N ); |
416 | 419 | foreach ( $result as $row ) { |