diff --git a/wp-includes/comment-template.php b/wp-includes/comment-template.php index f792748a13..2482c0250e 100644 --- a/wp-includes/comment-template.php +++ b/wp-includes/comment-template.php @@ -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; diff --git a/wp-includes/comment.php b/wp-includes/comment.php index 744af98b9b..b4771df838 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -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. * diff --git a/wp-includes/version.php b/wp-includes/version.php index 0a7ff3c0ce..e2846fa8b9 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.