~canonical-sysadmins/wordpress/5.1

« back to all changes in this revision

Viewing changes to wp-includes/comment-template.php

  • Committer: Barry Price
  • Date: 2016-01-07 06:09:02 UTC
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: barry.price@canonical.com-20160107060902-ck851ica42q3m8k6
new upstream release 4.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
736
736
                }
737
737
        }
738
738
 
739
 
        if ( $cpage ) {
 
739
        if ( $cpage && get_option( 'page_comments' ) ) {
740
740
                if ( $wp_rewrite->using_permalinks() ) {
741
741
                        if ( $cpage ) {
742
742
                                $link = trailingslashit( $link ) . $wp_rewrite->comments_pagination_base . '-' . $cpage;
1313
1313
                } else {
1314
1314
                        // If fetching the first page of 'newest', we need a top-level comment count.
1315
1315
                        $top_level_query = new WP_Comment_Query();
1316
 
                        $top_level_count = $top_level_query->query( array(
 
1316
                        $top_level_args  = array(
1317
1317
                                'count'   => true,
1318
1318
                                'orderby' => false,
1319
1319
                                'post_id' => $post->ID,
1320
1320
                                'parent'  => 0,
1321
 
                        ) );
 
1321
                                'status'  => 'approve',
 
1322
                        );
 
1323
 
 
1324
                        if ( isset( $comment_args['include_unapproved'] ) ) {
 
1325
                                $top_level_args['include_unapproved'] = $comment_args['include_unapproved'];
 
1326
                        }
 
1327
 
 
1328
                        $top_level_count = $top_level_query->query( $top_level_args );
1322
1329
 
1323
1330
                        $comment_args['offset'] = ( ceil( $top_level_count / $per_page ) - 1 ) * $per_page;
1324
1331
                }
1330
1337
        // Trees must be flattened before they're passed to the walker.
1331
1338
        $comments_flat = array();
1332
1339
        foreach ( $_comments as $_comment ) {
1333
 
                $comments_flat = array_merge( $comments_flat, array( $_comment ), $_comment->get_children( array(
 
1340
                $comments_flat[]  = $_comment;
 
1341
                $comment_children = $_comment->get_children( array(
1334
1342
                        'format' => 'flat',
1335
1343
                        'status' => $comment_args['status'],
1336
1344
                        'orderby' => $comment_args['orderby']
1337
 
                ) ) );
 
1345
                ) );
 
1346
 
 
1347
                foreach ( $comment_children as $comment_child ) {
 
1348
                        $comments_flat[] = $comment_child;
 
1349
                }
1338
1350
        }
1339
1351
 
1340
1352
        /**
1913
1925
         */
1914
1926
        $r = apply_filters( 'wp_list_comments_args', $r );
1915
1927
 
 
1928
        /*
 
1929
         * If 'page' or 'per_page' has been passed, and does not match what's in $wp_query,
 
1930
         * perform a separate comment query and allow Walker_Comment to paginate.
 
1931
         */
 
1932
        if ( is_singular() && ( $r['page'] || $r['per_page'] ) ) {
 
1933
                $current_cpage = get_query_var( 'cpage' );
 
1934
                if ( ! $current_cpage ) {
 
1935
                        $current_cpage = 'newest' === get_option( 'default_comments_page' ) ? 1 : $wp_query->max_num_comment_pages;
 
1936
                }
 
1937
 
 
1938
                $current_per_page = get_query_var( 'comments_per_page' );
 
1939
                if ( $r['page'] != $current_cpage || $r['per_page'] != $current_per_page ) {
 
1940
                        $comments = get_comments( array(
 
1941
                                'post_id' => get_queried_object_id(),
 
1942
                                'orderby' => 'comment_date_gmt',
 
1943
                                'order' => 'ASC',
 
1944
                                'status' => 'all',
 
1945
                        ) );
 
1946
                }
 
1947
        }
 
1948
 
1916
1949
        // Figure out what comments we'll be looping through ($_comments)
1917
1950
        if ( null !== $comments ) {
1918
1951
                $comments = (array) $comments;