Make WordPress Core

Changeset 32600


Ignore:
Timestamp:
05/25/2015 05:58:52 PM (9 years ago)
Author:
wonderboymusic
Message:

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.

Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-comments-list-table.php

    r32516 r32600  
    117117
    118118        $_comments = get_comments( $args );
    119 
    120         update_comment_cache( $_comments );
    121 
    122         $this->items = array_slice( $_comments, 0, $comments_per_page );
    123         $this->extra_items = array_slice( $_comments, $comments_per_page );
    124 
    125         $total_comments = get_comments( array_merge( $args, array('count' => true, 'offset' => 0, 'number' => 0) ) );
    126 
    127         $_comment_post_ids = array();
    128         foreach ( $_comments as $_c ) {
    129             $_comment_post_ids[] = $_c->comment_post_ID;
    130         }
    131 
    132         $_comment_post_ids = array_unique( $_comment_post_ids );
    133 
    134         $this->pending_count = get_pending_comments_num( $_comment_post_ids );
     119        if ( is_array( $_comments ) ) {
     120            update_comment_cache( $_comments );
     121
     122            $this->items = array_slice( $_comments, 0, $comments_per_page );
     123            $this->extra_items = array_slice( $_comments, $comments_per_page );
     124
     125            $_comment_post_ids = array_unique( wp_list_pluck( $_comments, 'comment_post_ID' ) );
     126
     127            $this->pending_count = get_pending_comments_num( $_comment_post_ids );
     128        }
     129
     130        $total_comments = get_comments( array_merge( $args, array(
     131            'count' => true,
     132            'offset' => 0,
     133            'number' => 0
     134        ) ) );
    135135
    136136        $this->set_pagination_args( array(
  • trunk/src/wp-admin/includes/dashboard.php

    r32175 r32600  
    767767
    768768    while ( count( $comments ) < $total_items && $possible = get_comments( $comments_query ) ) {
     769        if ( ! is_array( $possible ) ) {
     770            break;
     771        }
    769772        foreach ( $possible as $comment ) {
    770773            if ( ! current_user_can( 'read_post', $comment->comment_post_ID ) )
  • trunk/src/wp-includes/class-wp-xmlrpc-server.php

    r32591 r32600  
    31973197            $number = absint($struct['number']);
    31983198
    3199         $comments = get_comments( array('status' => $status, 'post_id' => $post_id, 'offset' => $offset, 'number' => $number ) );
     3199        $comments = get_comments( array( 'status' => $status, 'post_id' => $post_id, 'offset' => $offset, 'number' => $number ) );
    32003200
    32013201        $comments_struct = array();
    3202 
    3203         foreach ( $comments as $comment ) {
    3204             $comments_struct[] = $this->_prepare_comment( $comment );
     3202        if ( is_array( $comments ) ) {
     3203            foreach ( $comments as $comment ) {
     3204                $comments_struct[] = $this->_prepare_comment( $comment );
     3205            }
    32053206        }
    32063207
  • trunk/src/wp-includes/default-widgets.php

    r32589 r32600  
    10101010
    10111011        $output .= '<ul id="recentcomments">';
    1012         if ( $comments ) {
     1012        if ( is_array( $comments ) && $comments ) {
    10131013            // Prime cache for associated posts. (Prime post term cache if we need it for permalinks.)
    10141014            $post_ids = array_unique( wp_list_pluck( $comments, 'comment_post_ID' ) );
Note: See TracChangeset for help on using the changeset viewer.