mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-31 13:37:51 +01:00
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. Built from https://develop.svn.wordpress.org/trunk@48133 git-svn-id: http://core.svn.wordpress.org/trunk@47902 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
446d06c45d
commit
0c91c23277
@ -1330,6 +1330,7 @@ function wp_comment_form_unfiltered_html_nonce() {
|
||||
* Will not try to get the comments if the post has none.
|
||||
*
|
||||
* @since 1.5.0
|
||||
* @since 5.5.0 Removed the need to use the $user_ID global.
|
||||
*
|
||||
* @global WP_Query $wp_query WordPress Query object.
|
||||
* @global WP_Post $post Global post object.
|
||||
@ -1337,7 +1338,6 @@ function wp_comment_form_unfiltered_html_nonce() {
|
||||
* @global int $id
|
||||
* @global WP_Comment $comment Global comment object.
|
||||
* @global string $user_login
|
||||
* @global int $user_ID
|
||||
* @global string $user_identity
|
||||
* @global bool $overridden_cpage
|
||||
* @global bool $withcomments
|
||||
@ -1347,7 +1347,7 @@ function wp_comment_form_unfiltered_html_nonce() {
|
||||
* Default false.
|
||||
*/
|
||||
function comments_template( $file = '/comments.php', $separate_comments = false ) {
|
||||
global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage;
|
||||
global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_identity, $overridden_cpage;
|
||||
|
||||
if ( ! ( is_single() || is_page() || $withcomments ) || empty( $post ) ) {
|
||||
return;
|
||||
@ -1396,14 +1396,9 @@ function comments_template( $file = '/comments.php', $separate_comments = false
|
||||
$comment_args['hierarchical'] = false;
|
||||
}
|
||||
|
||||
if ( $user_ID ) {
|
||||
$comment_args['include_unapproved'] = array( $user_ID );
|
||||
} else {
|
||||
$unapproved_email = wp_get_unapproved_comment_author_email();
|
||||
|
||||
if ( $unapproved_email ) {
|
||||
$comment_args['include_unapproved'] = array( $unapproved_email );
|
||||
}
|
||||
$include_unapproved = wp_get_include_unapproved_comments_argument();
|
||||
if ( $include_unapproved ) {
|
||||
$comment_args['include_unapproved'] = $include_unapproved;
|
||||
}
|
||||
|
||||
$per_page = 0;
|
||||
|
@ -1132,6 +1132,36 @@ function get_page_of_comment( $comment_ID, $args = array() ) {
|
||||
),
|
||||
);
|
||||
|
||||
$include_unapproved = wp_get_include_unapproved_comments_argument();
|
||||
if ( $include_unapproved ) {
|
||||
$comment_args['include_unapproved'] = $include_unapproved;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the arguments used to query comments in get_page_of_comment().
|
||||
*
|
||||
* @since 5.5.0
|
||||
*
|
||||
* @see WP_Comment_Query::__construct()
|
||||
*
|
||||
* @param array $comment_args {
|
||||
* Array of WP_Comment_Query arguments.
|
||||
*
|
||||
* @type string $type Limit paginated comments to those matching a given type. Accepts 'comment',
|
||||
* 'trackback', 'pingback', 'pings' (trackbacks and pingbacks), or 'all'.
|
||||
* Default is 'all'.
|
||||
* @type int $post_id ID of the post.
|
||||
* @type string $fields Comment fields to return.
|
||||
* @type bool $count Whether to return a comment count (true) or array of
|
||||
* comment objects (false)
|
||||
* @type string $status Comment status.
|
||||
* @type int $parent Parent ID of comment to retrieve children of.
|
||||
* @type array $date_query Date query clauses to limit comments by. See WP_Date_Query.
|
||||
* @type array $include_unapproved Array of IDs or email addresses whose unapproved comments
|
||||
* will be included in paginated comments.
|
||||
* }
|
||||
*/
|
||||
$comment_args = apply_filters( 'get_page_of_comment_query_args', $comment_args );
|
||||
$comment_query = new WP_Comment_Query();
|
||||
$older_comment_count = $comment_query->query( $comment_args );
|
||||
|
||||
@ -1896,6 +1926,33 @@ function wp_get_unapproved_comment_author_email() {
|
||||
return $commenter_email;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get include unapproved comments query argument.
|
||||
*
|
||||
* Used to include unapproved comments of currrent commenters to
|
||||
* keep them informed their comments were successfully saved.
|
||||
*
|
||||
* @since 5.5.0
|
||||
*
|
||||
* @return array The unapproved comments query argument.
|
||||
*/
|
||||
function wp_get_include_unapproved_comments_argument() {
|
||||
$user_id = get_current_user_id();
|
||||
$include_unapproved = array();
|
||||
|
||||
if ( $user_id ) {
|
||||
$include_unapproved = array( $user_id );
|
||||
} else {
|
||||
$unapproved_email = wp_get_unapproved_comment_author_email();
|
||||
|
||||
if ( $unapproved_email ) {
|
||||
$include_unapproved = array( $unapproved_email );
|
||||
}
|
||||
}
|
||||
|
||||
return $include_unapproved;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a comment into the database.
|
||||
*
|
||||
|
@ -13,7 +13,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.5-alpha-48132';
|
||||
$wp_version = '5.5-alpha-48133';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user