Make WordPress Core

Ticket #19623: 19623.3.diff

File 19623.3.diff, 3.6 KB (added by jesin, 11 years ago)

19623-2.diff patch with line number changes

  • wp-includes/comment-template.php

     
    11011101         */
    11021102        $comment_author_url = esc_url($commenter['comment_author_url']);
    11031103
    1104         /** @todo Use API instead of SELECTs. */
    1105         if ( $user_ID) {
    1106                 $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND (comment_approved = '1' OR ( user_id = %d AND comment_approved = '0' ) )  ORDER BY comment_date_gmt", $post->ID, $user_ID));
    1107         } else if ( empty($comment_author) ) {
    1108                 $comments = get_comments( array('post_id' => $post->ID, 'status' => 'approve', 'order' => 'ASC') );
    1109         } else {
    1110                 $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND ( comment_approved = '1' OR ( comment_author = %s AND comment_author_email = %s AND comment_approved = '0' ) ) ORDER BY comment_date_gmt", $post->ID, wp_specialchars_decode($comment_author,ENT_QUOTES), $comment_author_email));
     1104        $args = array(
     1105                        'order' => 'ASC',
     1106                        'post_id' => $post->ID,
     1107                        'status' => 'approve'
     1108        );
     1109        if ( $user_ID ) {
     1110                $args['unapproved_user_id'] = $user_ID;
     1111        } else if ( ! empty( $comment_author ) ) {
     1112                $args['unapproved_author'] = wp_specialchars_decode( $comment_author, ENT_QUOTES );
     1113                $args['unapproved_author_email'] = $comment_author_email;
    11111114        }
     1115        $comments = get_comments( $args );
    11121116
    11131117        /**
    11141118         * Filter the comments array.
  • wp-includes/comment.php

     
    241241                        'order' => 'DESC',
    242242                        'parent' => '',
    243243                        'post_ID' => '',
    244                         'post_id' => 0,
     244                        'post_id' => '',
     245                        'post__in' => '',
    245246                        'post_author' => '',
    246247                        'post_name' => '',
    247248                        'post_parent' => '',
     
    249250                        'post_type' => '',
    250251                        'status' => '',
    251252                        'type' => '',
     253                        'unapproved_author' => '',
     254                        'unapproved_author_email' => '',
     255                        'unapproved_user_id' => '',
    252256                        'user_id' => '',
    253257                        'search' => '',
    254258                        'count' => false,
     
    288292                if ( $cache = wp_cache_get( $cache_key, 'comment' ) )
    289293                        return $cache;
    290294
     295                if ( empty( $post_id ) && empty( $post__in ) )
     296                        $post_id = 0;
     297
    291298                $post_id = absint($post_id);
    292299
    293300                if ( 'hold' == $status )
     
    299306                else
    300307                        $approved = "( comment_approved = '0' OR comment_approved = '1' )";
    301308
     309                $where = $approved;
     310
     311                if ( ( '' != $unapproved_user_id || '' !== $unapproved_author || '' != $unapproved_author_email ) ) {
     312                        $where = '( ' . $where . ' OR ( comment_approved = 0 ';
     313                        if ( '' !== $unapproved_author )
     314                                $where .= $wpdb->prepare( ' AND comment_author = %s', $unapproved_author );
     315                        if ( '' !== $unapproved_author_email )
     316                                $where .= $wpdb->prepare( ' AND comment_author_email = %s', $unapproved_author_email );
     317                        if ( '' !== $unapproved_user_id )
     318                                $where .= $wpdb->prepare( ' AND user_id = %d', $unapproved_user_id );
     319                        $where .= ' ) ) ';
     320                }
     321
    302322                $order = ( 'ASC' == strtoupper($order) ) ? 'ASC' : 'DESC';
    303323
    304324                if ( ! empty( $orderby ) ) {
     
    356376                        $fields = '*';
    357377
    358378                $join = '';
    359                 $where = $approved;
    360379
    361380                if ( ! empty($post_id) )
    362381                        $where .= $wpdb->prepare( ' AND comment_post_ID = %d', $post_id );
     382                if ( '' != $post__in && is_array( $post__in ) && ! empty( $post__in ) ) {
     383                        $_post__in = implode( ',', array_map( 'absint', $post__in ) );
     384                        $where .= " AND comment_post_ID IN ($_post__in)";
     385                }
    363386                if ( '' !== $author_email )
    364387                        $where .= $wpdb->prepare( ' AND comment_author_email = %s', $author_email );
    365388                if ( '' !== $karma )