Skip to content

Commit 197f0a7

Browse files
Coding Standards: Move count() usage in wp_dashboard_recent_comments().
While the rule to discourage using functions like `count()` in a loop condition is a recommendation/best practice rule from the `WordPress-Extra` ruleset and does not directly apply to WordPress core, this is intended as a minor readability and code clarity improvement. Follow-up to [10090], [17556], [20609], [26144]. Props krunal265, johnbillion, audrasjb, dhruvang21, SergeyBiryukov. Fixes #56499. git-svn-id: https://develop.svn.wordpress.org/trunk@60643 602fd350-edb4-49c9-b593-d223f7449a82
1 parent dd2d7ef commit 197f0a7

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/wp-admin/includes/dashboard.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,8 +1074,10 @@ function wp_dashboard_recent_comments( $total_items = 5 ) {
10741074
$comments_query['status'] = 'approve';
10751075
}
10761076

1077-
while ( count( $comments ) < $total_items && $possible = get_comments( $comments_query ) ) {
1078-
if ( ! is_array( $possible ) ) {
1077+
do {
1078+
$possible = get_comments( $comments_query );
1079+
1080+
if ( empty( $possible ) || ! is_array( $possible ) ) {
10791081
break;
10801082
}
10811083

@@ -1088,16 +1090,17 @@ function wp_dashboard_recent_comments( $total_items = 5 ) {
10881090
continue;
10891091
}
10901092

1091-
$comments[] = $comment;
1093+
$comments[] = $comment;
1094+
$comments_count = count( $comments );
10921095

1093-
if ( count( $comments ) === $total_items ) {
1096+
if ( $comments_count === $total_items ) {
10941097
break 2;
10951098
}
10961099
}
10971100

10981101
$comments_query['offset'] += $comments_query['number'];
10991102
$comments_query['number'] = $total_items * 10;
1100-
}
1103+
} while ( $comments_count < $total_items );
11011104

11021105
if ( $comments ) {
11031106
echo '<div id="latest-comments" class="activity-block table-view-list">';

0 commit comments

Comments
 (0)