Make WordPress Core

Ticket #12960: 12960.3.diff

File 12960.3.diff, 5.5 KB (added by donmhico, 5 years ago)
  • src/wp-admin/includes/class-wp-users-list-table.php

    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 { 
    387387         * Generate the list table rows.
    388388         *
    389389         * @since 3.1.0
     390         * @since 5.5.0 Include 'pending', 'future', and 'draft' posts in the count.
    390391         */
    391392        public function display_rows() {
    392393                // Query the post counts for this page.
    393394                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 );
    395396                }
    396397
    397398                foreach ( $this->items as $userid => $user_object ) {
  • src/wp-includes/post.php

    diff --git src/wp-includes/post.php src/wp-includes/post.php
    index 10eee1d25f..e3dc43fbe7 100644
    function get_private_posts_cap_sql( $post_type ) { 
    63716371 *
    63726372 * @since 3.0.0
    63736373 * @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.
    63746376 *
    63756377 * @see get_private_posts_cap_sql()
    63766378 * @global wpdb $wpdb WordPress database abstraction object.
    63776379 *
    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.
    63846388 * @return string SQL WHERE code that can be added to a query.
    63856389 */
    6386 function get_posts_by_author_sql( $post_type, $full = true, $post_author = null, $public_only = false ) {
     6390function get_posts_by_author_sql( $post_type, $full = true, $post_author = null, $public_only = false, $include_unpublished = false ) {
    63876391        global $wpdb;
    63886392
    63896393        if ( is_array( $post_type ) ) {
    function get_posts_by_author_sql( $post_type, $full = true, $post_author = null, 
    64286432                                        $post_status_sql .= " OR post_status = 'private'";
    64296433                                } // Else none.
    64306434                        } // Else none.
     6435
     6436                        if ( $include_unpublished ) {
     6437                                $post_status_sql .= " OR post_status = 'future' OR post_status = 'pending' OR post_status = 'draft'";
     6438                        }
    64316439                }
    64326440
    64336441                $post_type_clauses[] = "( post_type = '" . $post_type . "' AND ( $post_status_sql ) )";
  • src/wp-includes/user.php

    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 ) 
    393393 * Number of posts written by a list of users.
    394394 *
    395395 * @since 3.0.0
     396 * @since 5.5.0 Added the parameter `$include_unpublished` which will include 'pending', 'future', and 'draft' posts.
    396397 *
    397398 * @global wpdb $wpdb WordPress database abstraction object.
    398399 *
    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.
    402405 * @return string[] Amount of posts each user has written, as strings, keyed by user ID.
    403406 */
    404 function count_many_users_posts( $users, $post_type = 'post', $public_only = false ) {
     407function count_many_users_posts( $users, $post_type = 'post', $public_only = false, $include_unpublished = false ) {
    405408        global $wpdb;
    406409
    407410        $count = array();
    function count_many_users_posts( $users, $post_type = 'post', $public_only = fal 
    410413        }
    411414
    412415        $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 );
    414417
    415418        $result = $wpdb->get_results( "SELECT post_author, COUNT(*) FROM $wpdb->posts $where AND post_author IN ($userlist) GROUP BY post_author", ARRAY_N );
    416419        foreach ( $result as $row ) {