Make WordPress Core


Ignore:
Timestamp:
05/25/2015 05:58:52 PM (10 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.

File:
1 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(
Note: See TracChangeset for help on using the changeset viewer.