Make WordPress Core

Ticket #19623: 19623-2.diff

File 19623-2.diff, 3.6 KB (added by hardy101, 13 years ago)

Best of simonwheatley's patch with some streamlining

  • wp-includes/comment.php

     
    212212                        'order' => 'DESC',
    213213                        'parent' => '',
    214214                        'post_ID' => '',
    215                         'post_id' => 0,
     215                        'post_id' => '',
     216                        'post__in' => '',
    216217                        'post_author' => '',
    217218                        'post_name' => '',
    218219                        'post_parent' => '',
     
    220221                        'post_type' => '',
    221222                        'status' => '',
    222223                        'type' => '',
     224                        'unapproved_author' => '',
     225                        'unapproved_author_email' => '',
     226                        'unapproved_user_id' => '',
    223227                        'user_id' => '',
    224228                        'search' => '',
    225229                        'count' => false
     
    242246                        return $cache;
    243247                }
    244248
     249                if ( empty( $post_id ) && empty( $post__in ) )
     250                        $post_id = 0;
     251
    245252                $post_id = absint($post_id);
    246253
    247254                if ( 'hold' == $status )
     
    255262                else
    256263                        $approved = "( comment_approved = '0' OR comment_approved = '1' )";
    257264
     265                $where = $approved;
     266
     267                if ( ( '' != $unapproved_user_id || '' !== $unapproved_author || '' != $unapproved_author_email ) ) {
     268                        $where = '( ' . $where . ' OR ( comment_approved = 0 ';
     269                        if ( '' !== $unapproved_author )
     270                                $where .= $wpdb->prepare( ' AND comment_author = %s', $unapproved_author );
     271                        if ( '' !== $unapproved_author_email )
     272                                $where .= $wpdb->prepare( ' AND comment_author_email = %s', $unapproved_author_email );
     273                        if ( '' !== $unapproved_user_id )
     274                                $where .= $wpdb->prepare( ' AND user_id = %d', $unapproved_user_id );
     275                        $where .= ' ) ) ';
     276                }
     277               
    258278                $order = ( 'ASC' == strtoupper($order) ) ? 'ASC' : 'DESC';
    259279
    260280                if ( ! empty( $orderby ) ) {
     
    302322                        $fields = '*';
    303323
    304324                $join = '';
    305                 $where = $approved;
    306325
    307326                if ( ! empty($post_id) )
    308327                        $where .= $wpdb->prepare( ' AND comment_post_ID = %d', $post_id );
     328                if ( '' != $post__in && is_array($post__in) && !empty($post__in) ) {
     329                        $_post__in = implode(',', array_map( 'absint', $post__in ));
     330                        $where .= " AND comment_post_ID IN ($_post__in)";
     331                }
    309332                if ( '' !== $author_email )
    310333                        $where .= $wpdb->prepare( ' AND comment_author_email = %s', $author_email );
    311334                if ( '' !== $karma )
  • wp-includes/comment-template.php

     
    881881         */
    882882        $comment_author_url = esc_url($commenter['comment_author_url']);
    883883
    884         /** @todo Use API instead of SELECTs. */
     884        $args = array(
     885                'order' => 'ASC',
     886                'post_id' => $post->ID,
     887                'status' => 'approve'
     888        );
    885889        if ( $user_ID) {
    886                 $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));
    887         } else if ( empty($comment_author) ) {
    888                 $comments = get_comments( array('post_id' => $post->ID, 'status' => 'approve', 'order' => 'ASC') );
    889         } else {
    890                 $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));
     890                $args[ 'unapproved_user_id' ] = $user_ID;
     891        } else if ( ! empty($comment_author) ) {
     892                $args[ 'unapproved_author' ] = wp_specialchars_decode($comment_author,ENT_QUOTES);
     893                $args[ 'unapproved_author_email' ] = $comment_author_email;
    891894        }
     895        $comments = get_comments( $args );
    892896
    893897        // keep $comments for legacy's sake
    894898        $wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID );