Make WordPress Core

Changeset 12715


Ignore:
Timestamp:
01/12/2010 10:38:26 PM (17 years ago)
Author:
westi
Message:

Improve get_pending_comments_num() to be a little more predictable and revert the erroneous change in [12596]. See #11882.

Location:
trunk/wp-admin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/edit-comments.php

    r12616 r12715  
    245245        $_comment_post_ids[] = $_c->comment_post_ID;
    246246}
    247 $_comment_pending_count_temp = (array) get_pending_comments_num($_comment_post_ids);
    248 foreach ( (array) $_comment_post_ids as $_cpid )
    249         $_comment_pending_count[$_cpid] = isset( $_comment_pending_count_temp[$_cpid] ) ? $_comment_pending_count_temp[$_cpid] : 0;
    250 if ( empty($_comment_pending_count) )
    251         $_comment_pending_count = array();
     247
     248$_comment_pending_count = get_pending_comments_num($_comment_post_ids);
    252249
    253250$comments = array_slice($_comments, 0, $comments_per_page);
  • trunk/wp-admin/includes/comment.php

    r12595 r12715  
    110110        $single = false;
    111111        if ( !is_array($post_id) ) {
    112                 $post_id = (array) $post_id;
     112                $post_id_array = (array) $post_id;
    113113                $single = true;
     114        } else {
     115                $post_id_array = $post_id;
    114116        }
    115         $post_id = array_map('intval', $post_id);
    116         $post_id = "'" . implode("', '", $post_id) . "'";
     117        $post_id_array = array_map('intval', $post_id_array);
     118        $post_id_in = "'" . implode("', '", $post_id_array) . "'";
    117119
    118         $pending = $wpdb->get_results( "SELECT comment_post_ID, COUNT(comment_ID) as num_comments FROM $wpdb->comments WHERE comment_post_ID IN ( $post_id ) AND comment_approved = '0' GROUP BY comment_post_ID", ARRAY_N );
     120        $pending = $wpdb->get_results( "SELECT comment_post_ID, COUNT(comment_ID) as num_comments FROM $wpdb->comments WHERE comment_post_ID IN ( $post_id_in ) AND comment_approved = '0' GROUP BY comment_post_ID", ARRAY_A );
    119121
    120         if ( empty($pending) )
    121                 return 0;
     122        if ( $single ) {
     123                if ( empty($pending) )
     124                        return 0;
     125                else
     126                        return absint($pending[0]['num_comments']);
     127        }
     128       
     129        $pending_keyed = array();
     130       
     131        // Default to zero pending for all posts in request
     132        foreach ( $post_id_array as $id )
     133                $pending_keyed[$id] = 0;
    122134
    123         if ( $single )
    124                 return $pending[0][1];
    125 
    126         $pending_keyed = array();
    127         foreach ( $pending as $pend )
    128                 $pending_keyed[$pend[0]] = $pend[1];
     135        if ( !empty($pending) )
     136                foreach ( $pending as $pend )
     137                        $pending_keyed[$pend['comment_post_ID']] = absint($pend['num_comments']);
    129138
    130139        return $pending_keyed;
  • trunk/wp-admin/includes/template.php

    r12702 r12715  
    22642264                                if ( 'single' !== $mode ) {
    22652265                                        if ( isset( $_comment_pending_count[$post->ID] ) ) {
    2266                                                 $pending_comments = absint( $_comment_pending_count[$post->ID] );
     2266                                                $pending_comments = $_comment_pending_count[$post->ID];
    22672267                                        } else {
    22682268                                                $_comment_pending_count_temp = get_pending_comments_num( array( $post->ID ) );
    2269                                                 $pending_comments = $_comment_pending_count[$post->ID] = $_comment_pending_count_temp;
     2269                                                $pending_comments = $_comment_pending_count[$post->ID] = $_comment_pending_count_temp[$post->ID];
    22702270                                        }
    22712271                                        if ( $user_can ) {
Note: See TracChangeset for help on using the changeset viewer.