WordPress.org

Make WordPress Core


Ignore:
Timestamp:
06/23/2020 05:22:39 AM (3 months ago)
Author:
whyisjake
Message:

Comments: Ensure the proper comment count and pages for unapproved comments.

Previiously, unapproved comments can alter the comment count, returning incorrect page numbers.

Fixes #8973.

Props GregMulhauser, dd32, ryan, mrmist, hakre, solarissmoke, billerickson, ericlewis, SergeyBiryukov, chriscct7, dossy, lukecavanagh, renggo888, jdorner, matjack1, pento, audrasjb, imath, davidbaumwald, whyisjake.

File:
1 edited

Legend:

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

    r48121 r48133  
    11331133        );
    11341134
     1135        $include_unapproved = wp_get_include_unapproved_comments_argument();
     1136        if ( $include_unapproved ) {
     1137            $comment_args['include_unapproved'] = $include_unapproved;
     1138        }
     1139
     1140        /**
     1141         * Filters the arguments used to query comments in get_page_of_comment().
     1142         *
     1143         * @since 5.5.0
     1144         *
     1145         * @see WP_Comment_Query::__construct()
     1146         *
     1147         * @param array $comment_args {
     1148         *     Array of WP_Comment_Query arguments.
     1149         *
     1150         *     @type string $type               Limit paginated comments to those matching a given type. Accepts 'comment',
     1151         *                                      'trackback', 'pingback', 'pings' (trackbacks and pingbacks), or 'all'.
     1152         *                                      Default is 'all'.
     1153         *     @type int    $post_id            ID of the post.
     1154         *     @type string $fields             Comment fields to return.
     1155         *     @type bool   $count              Whether to return a comment count (true) or array of
     1156         *                                      comment objects (false)
     1157         *     @type string $status             Comment status.
     1158         *     @type int    $parent             Parent ID of comment to retrieve children of.
     1159         *     @type array  $date_query         Date query clauses to limit comments by. See WP_Date_Query.
     1160         *     @type array  $include_unapproved Array of IDs or email addresses whose unapproved comments
     1161         *                                      will be included in paginated comments.
     1162         * }
     1163         */
     1164        $comment_args        = apply_filters( 'get_page_of_comment_query_args', $comment_args );
    11351165        $comment_query       = new WP_Comment_Query();
    11361166        $older_comment_count = $comment_query->query( $comment_args );
     
    18951925
    18961926    return $commenter_email;
     1927}
     1928
     1929/**
     1930 * Get include unapproved comments query argument.
     1931 *
     1932 * Used to include unapproved comments of currrent commenters to
     1933 * keep them informed their comments were successfully saved.
     1934 *
     1935 * @since 5.5.0
     1936 *
     1937 * @return array The unapproved comments query argument.
     1938 */
     1939function wp_get_include_unapproved_comments_argument() {
     1940    $user_id            = get_current_user_id();
     1941    $include_unapproved = array();
     1942
     1943    if ( $user_id ) {
     1944        $include_unapproved = array( $user_id );
     1945    } else {
     1946        $unapproved_email = wp_get_unapproved_comment_author_email();
     1947
     1948        if ( $unapproved_email ) {
     1949            $include_unapproved = array( $unapproved_email );
     1950        }
     1951    }
     1952
     1953    return $include_unapproved;
    18971954}
    18981955
Note: See TracChangeset for help on using the changeset viewer.