`get_comments()` can return `int`, so a few places need to check if the return value is traversable before passing what is assumed to be an `array`.

See #32444.

Built from https://develop.svn.wordpress.org/trunk@32600


git-svn-id: http://core.svn.wordpress.org/trunk@32570 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2015-05-25 17:59:25 +00:00
parent 053790537f
commit 19b8ef0c92
5 changed files with 21 additions and 17 deletions

View File

@ -116,22 +116,22 @@ class WP_Comments_List_Table extends WP_List_Table {
); );
$_comments = get_comments( $args ); $_comments = get_comments( $args );
if ( is_array( $_comments ) ) {
update_comment_cache( $_comments );
update_comment_cache( $_comments ); $this->items = array_slice( $_comments, 0, $comments_per_page );
$this->extra_items = array_slice( $_comments, $comments_per_page );
$this->items = array_slice( $_comments, 0, $comments_per_page ); $_comment_post_ids = array_unique( wp_list_pluck( $_comments, 'comment_post_ID' ) );
$this->extra_items = array_slice( $_comments, $comments_per_page );
$total_comments = get_comments( array_merge( $args, array('count' => true, 'offset' => 0, 'number' => 0) ) ); $this->pending_count = get_pending_comments_num( $_comment_post_ids );
$_comment_post_ids = array();
foreach ( $_comments as $_c ) {
$_comment_post_ids[] = $_c->comment_post_ID;
} }
$_comment_post_ids = array_unique( $_comment_post_ids ); $total_comments = get_comments( array_merge( $args, array(
'count' => true,
$this->pending_count = get_pending_comments_num( $_comment_post_ids ); 'offset' => 0,
'number' => 0
) ) );
$this->set_pagination_args( array( $this->set_pagination_args( array(
'total_items' => $total_comments, 'total_items' => $total_comments,

View File

@ -766,6 +766,9 @@ function wp_dashboard_recent_comments( $total_items = 5 ) {
$comments_query['status'] = 'approve'; $comments_query['status'] = 'approve';
while ( count( $comments ) < $total_items && $possible = get_comments( $comments_query ) ) { while ( count( $comments ) < $total_items && $possible = get_comments( $comments_query ) ) {
if ( ! is_array( $possible ) ) {
break;
}
foreach ( $possible as $comment ) { foreach ( $possible as $comment ) {
if ( ! current_user_can( 'read_post', $comment->comment_post_ID ) ) if ( ! current_user_can( 'read_post', $comment->comment_post_ID ) )
continue; continue;

View File

@ -3196,12 +3196,13 @@ class wp_xmlrpc_server extends IXR_Server {
if ( isset($struct['number']) ) if ( isset($struct['number']) )
$number = absint($struct['number']); $number = absint($struct['number']);
$comments = get_comments( array('status' => $status, 'post_id' => $post_id, 'offset' => $offset, 'number' => $number ) ); $comments = get_comments( array( 'status' => $status, 'post_id' => $post_id, 'offset' => $offset, 'number' => $number ) );
$comments_struct = array(); $comments_struct = array();
if ( is_array( $comments ) ) {
foreach ( $comments as $comment ) { foreach ( $comments as $comment ) {
$comments_struct[] = $this->_prepare_comment( $comment ); $comments_struct[] = $this->_prepare_comment( $comment );
}
} }
return $comments_struct; return $comments_struct;

View File

@ -1009,7 +1009,7 @@ class WP_Widget_Recent_Comments extends WP_Widget {
} }
$output .= '<ul id="recentcomments">'; $output .= '<ul id="recentcomments">';
if ( $comments ) { if ( is_array( $comments ) && $comments ) {
// Prime cache for associated posts. (Prime post term cache if we need it for permalinks.) // Prime cache for associated posts. (Prime post term cache if we need it for permalinks.)
$post_ids = array_unique( wp_list_pluck( $comments, 'comment_post_ID' ) ); $post_ids = array_unique( wp_list_pluck( $comments, 'comment_post_ID' ) );
_prime_post_caches( $post_ids, strpos( get_option( 'permalink_structure' ), '%category%' ), false ); _prime_post_caches( $post_ids, strpos( get_option( 'permalink_structure' ), '%category%' ), false );

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.3-alpha-32599'; $wp_version = '4.3-alpha-32600';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.