Comments: Remove wp_get_include_unapproved_comments_argument() for now.

The function seems too specific and low-level for an abstraction, is only used in two places, and does not provide a significant benefit in terms of reducing code duplication.

Follow-up to [48133].

See #8973.

git-svn-id: https://develop.svn.wordpress.org/trunk@48140 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2020-06-23 13:51:03 +00:00
parent 0a301ec4b5
commit 6408e197bd
2 changed files with 32 additions and 48 deletions

View File

@ -1330,7 +1330,6 @@ 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.
@ -1396,9 +1395,14 @@ function comments_template( $file = '/comments.php', $separate_comments = false
$comment_args['hierarchical'] = false;
}
$include_unapproved = wp_get_include_unapproved_comments_argument();
if ( $include_unapproved ) {
$comment_args['include_unapproved'] = $include_unapproved;
if ( is_user_logged_in() ) {
$comment_args['include_unapproved'] = array( get_current_user_id() );
} else {
$unapproved_email = wp_get_unapproved_comment_author_email();
if ( $unapproved_email ) {
$comment_args['include_unapproved'] = array( $unapproved_email );
}
}
$per_page = 0;
@ -2097,7 +2101,7 @@ function wp_list_comments( $args = array(), $comments = null ) {
);
if ( is_user_logged_in() ) {
$comment_args['include_unapproved'] = get_current_user_id();
$comment_args['include_unapproved'] = array( get_current_user_id() );
} else {
$unapproved_email = wp_get_unapproved_comment_author_email();

View File

@ -1054,13 +1054,14 @@ function get_comment_pages_count( $comments = null, $per_page = null, $threaded
* @param int $comment_ID Comment ID.
* @param array $args {
* Array of optional 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 $per_page Per-page count to use when calculating pagination. Defaults to the value of the
* 'comments_per_page' option.
* @type int|string $max_depth If greater than 1, comment page will be determined for the top-level parent of
* `$comment_ID`. Defaults to the value of the 'thread_comments_depth' option.
* @type string $type Limit paginated comments to those matching a given type.
* Accepts 'comment', 'trackback', 'pingback', 'pings'
* (trackbacks and pingbacks), or 'all'. Default 'all'.
* @type int $per_page Per-page count to use when calculating pagination.
* Defaults to the value of the 'comments_per_page' option.
* @type int|string $max_depth If greater than 1, comment page will be determined
* for the top-level parent `$comment_ID`.
* Defaults to the value of the 'thread_comments_depth' option.
* } *
* @return int|null Comment page number or null on error.
*/
@ -1132,9 +1133,14 @@ 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;
if ( is_user_logged_in() ) {
$comment_args['include_unapproved'] = array( get_current_user_id() );
} else {
$unapproved_email = wp_get_unapproved_comment_author_email();
if ( $unapproved_email ) {
$comment_args['include_unapproved'] = array( $unapproved_email );
}
}
/**
@ -1147,13 +1153,13 @@ function get_page_of_comment( $comment_ID, $args = array() ) {
* @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 string $type Limit paginated comments to those matching a given type.
* Accepts 'comment', 'trackback', 'pingback', 'pings'
* (trackbacks and pingbacks), or 'all'. Default '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 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.
@ -1162,6 +1168,7 @@ function get_page_of_comment( $comment_ID, $args = array() ) {
* }
*/
$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 );
@ -1926,33 +1933,6 @@ 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.
*