Ticket #16506: 16506.b.diff

File 16506.b.diff, 1.8 KB (added by filosofo, 2 years ago)
  • wp-includes/default-widgets.php

     
    640640                if ( ! $number = absint( $instance['number'] ) ) 
    641641                        $number = 5; 
    642642 
    643                 $comments = get_comments( array( 'number' => $number, 'status' => 'approve' ) ); 
     643                $comments = get_comments( array( 'number' => $number, 'status' => 'approve', 'post_status' => 'publish' ) ); 
    644644                $output .= $before_widget; 
    645645                if ( $title ) 
    646646                        $output .= $before_title . $title . $after_title; 
  • wp-includes/comment.php

     
    213213                        'parent' => '', 
    214214                        'post_ID' => '', 
    215215                        'post_id' => 0, 
     216                        'post_author' => '', 
     217                        'post_name' => '', 
     218                        'post_parent' => '', 
     219                        'post_status' => '', 
     220                        'post_type' => '', 
    216221                        'status' => '', 
    217222                        'type' => '', 
    218223                        'user_id' => '', 
     
    319324                if ( '' !== $search ) 
    320325                        $where .= $this->get_search_sql( $search, array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content' ) ); 
    321326 
     327                $post_fields = array_filter( compact( array( 'post_author', 'post_name', 'post_parent', 'post_status', 'post_type', ) ) ); 
     328                if ( ! empty( $post_fields ) ) { 
     329                        $join = "JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID"; 
     330                        foreach( $post_fields as $field_name => $field_value ) 
     331                                $where .= $wpdb->prepare( " AND {$wpdb->posts}.{$field_name} = %s", $field_value ); 
     332                } 
     333 
    322334                $pieces = array( 'fields', 'join', 'where', 'orderby', 'order', 'limits' ); 
    323335                $clauses = apply_filters_ref_array( 'comments_clauses', array( compact( $pieces ), &$this ) ); 
    324336                foreach ( $pieces as $piece )