~canonical-sysadmins/wordpress/4.5.1

« back to all changes in this revision

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

  • Committer: Haw Loeung
  • Date: 2016-02-03 02:21:54 UTC
  • mfrom: (1.1.13 upstream)
  • Revision ID: haw.loeung@canonical.com-20160203022154-0xy5mh0a1wc09e1f
Merge WP4.4.2 from upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1285
1285
                'order' => 'ASC',
1286
1286
                'status'  => 'approve',
1287
1287
                'post_id' => $post->ID,
1288
 
                'hierarchical' => 'threaded',
1289
1288
                'no_found_rows' => false,
1290
1289
                'update_comment_meta_cache' => false, // We lazy-load comment meta for performance.
1291
1290
        );
1292
1291
 
 
1292
        if ( get_option('thread_comments') ) {
 
1293
                $comment_args['hierarchical'] = 'threaded';
 
1294
        } else {
 
1295
                $comment_args['hierarchical'] = false;
 
1296
        }
 
1297
 
1293
1298
        if ( $user_ID ) {
1294
1299
                $comment_args['include_unapproved'] = array( $user_ID );
1295
1300
        } elseif ( ! empty( $comment_author_email ) ) {
1317
1322
                                'count'   => true,
1318
1323
                                'orderby' => false,
1319
1324
                                'post_id' => $post->ID,
1320
 
                                'parent'  => 0,
1321
1325
                                'status'  => 'approve',
1322
1326
                        );
1323
1327
 
 
1328
                        if ( $comment_args['hierarchical'] ) {
 
1329
                                $top_level_args['parent'] = 0;
 
1330
                        }
 
1331
 
1324
1332
                        if ( isset( $comment_args['include_unapproved'] ) ) {
1325
1333
                                $top_level_args['include_unapproved'] = $comment_args['include_unapproved'];
1326
1334
                        }
1335
1343
        $_comments = $comment_query->comments;
1336
1344
 
1337
1345
        // Trees must be flattened before they're passed to the walker.
1338
 
        $comments_flat = array();
1339
 
        foreach ( $_comments as $_comment ) {
1340
 
                $comments_flat[]  = $_comment;
1341
 
                $comment_children = $_comment->get_children( array(
1342
 
                        'format' => 'flat',
1343
 
                        'status' => $comment_args['status'],
1344
 
                        'orderby' => $comment_args['orderby']
1345
 
                ) );
 
1346
        if ( $comment_args['hierarchical'] ) {
 
1347
                $comments_flat = array();
 
1348
                foreach ( $_comments as $_comment ) {
 
1349
                        $comments_flat[]  = $_comment;
 
1350
                        $comment_children = $_comment->get_children( array(
 
1351
                                'format' => 'flat',
 
1352
                                'status' => $comment_args['status'],
 
1353
                                'orderby' => $comment_args['orderby']
 
1354
                        ) );
1346
1355
 
1347
 
                foreach ( $comment_children as $comment_child ) {
1348
 
                        $comments_flat[] = $comment_child;
 
1356
                        foreach ( $comment_children as $comment_child ) {
 
1357
                                $comments_flat[] = $comment_child;
 
1358
                        }
1349
1359
                }
 
1360
        } else {
 
1361
                $comments_flat = $_comments;
1350
1362
        }
1351
1363
 
1352
1364
        /**
1925
1937
         */
1926
1938
        $r = apply_filters( 'wp_list_comments_args', $r );
1927
1939
 
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
 
 
1949
1940
        // Figure out what comments we'll be looping through ($_comments)
1950
1941
        if ( null !== $comments ) {
1951
1942
                $comments = (array) $comments;
1960
1951
                        $_comments = $comments;
1961
1952
                }
1962
1953
        } else {
1963
 
                if ( empty($wp_query->comments) )
1964
 
                        return;
1965
 
                if ( 'all' != $r['type'] ) {
1966
 
                        if ( empty($wp_query->comments_by_type) )
1967
 
                                $wp_query->comments_by_type = separate_comments($wp_query->comments);
1968
 
                        if ( empty($wp_query->comments_by_type[$r['type']]) )
 
1954
                /*
 
1955
                 * If 'page' or 'per_page' has been passed, and does not match what's in $wp_query,
 
1956
                 * perform a separate comment query and allow Walker_Comment to paginate.
 
1957
                 */
 
1958
                if ( $r['page'] || $r['per_page'] ) {
 
1959
                        $current_cpage = get_query_var( 'cpage' );
 
1960
                        if ( ! $current_cpage ) {
 
1961
                                $current_cpage = 'newest' === get_option( 'default_comments_page' ) ? 1 : $wp_query->max_num_comment_pages;
 
1962
                        }
 
1963
 
 
1964
                        $current_per_page = get_query_var( 'comments_per_page' );
 
1965
                        if ( $r['page'] != $current_cpage || $r['per_page'] != $current_per_page ) {
 
1966
 
 
1967
                                $comments = get_comments( array(
 
1968
                                        'post_id' => get_the_ID(),
 
1969
                                        'orderby' => 'comment_date_gmt',
 
1970
                                        'order' => 'ASC',
 
1971
                                        'status' => 'all',
 
1972
                                ) );
 
1973
 
 
1974
                                if ( 'all' != $r['type'] ) {
 
1975
                                        $comments_by_type = separate_comments( $comments );
 
1976
                                        if ( empty( $comments_by_type[ $r['type'] ] ) ) {
 
1977
                                                return;
 
1978
                                        }
 
1979
 
 
1980
                                        $_comments = $comments_by_type[ $r['type'] ];
 
1981
                                } else {
 
1982
                                        $_comments = $comments;
 
1983
                                }
 
1984
                        }
 
1985
 
 
1986
                // Otherwise, fall back on the comments from `$wp_query->comments`.
 
1987
                } else {
 
1988
                        if ( empty($wp_query->comments) )
1969
1989
                                return;
1970
 
                        $_comments = $wp_query->comments_by_type[$r['type']];
1971
 
                } else {
1972
 
                        $_comments = $wp_query->comments;
1973
 
                }
1974
 
 
1975
 
                // Pagination is already handled by `WP_Comment_Query`, so we tell Walker not to bother.
1976
 
                if ( $wp_query->max_num_comment_pages ) {
1977
 
                        $default_comments_page = get_option( 'default_comments_page' );
1978
 
                        $cpage = get_query_var( 'cpage' );
1979
 
                        if ( 'newest' === $default_comments_page ) {
1980
 
                                $r['cpage'] = $cpage;
1981
 
 
1982
 
                        // When first page shows oldest comments, post permalink is the same as the comment permalink.
1983
 
                        } elseif ( $cpage == 1 ) {
1984
 
                                $r['cpage'] = '';
 
1990
                        if ( 'all' != $r['type'] ) {
 
1991
                                if ( empty($wp_query->comments_by_type) )
 
1992
                                        $wp_query->comments_by_type = separate_comments($wp_query->comments);
 
1993
                                if ( empty($wp_query->comments_by_type[$r['type']]) )
 
1994
                                        return;
 
1995
                                $_comments = $wp_query->comments_by_type[$r['type']];
1985
1996
                        } else {
1986
 
                                $r['cpage'] = $cpage;
1987
 
                        }
1988
 
 
1989
 
                        $r['page'] = 0;
1990
 
                        $r['per_page'] = 0;
 
1997
                                $_comments = $wp_query->comments;
 
1998
                        }
 
1999
 
 
2000
                        if ( $wp_query->max_num_comment_pages ) {
 
2001
                                $default_comments_page = get_option( 'default_comments_page' );
 
2002
                                $cpage = get_query_var( 'cpage' );
 
2003
                                if ( 'newest' === $default_comments_page ) {
 
2004
                                        $r['cpage'] = $cpage;
 
2005
 
 
2006
                                /*
 
2007
                                 * When first page shows oldest comments, post permalink is the same as
 
2008
                                 * the comment permalink.
 
2009
                                 */
 
2010
                                } elseif ( $cpage == 1 ) {
 
2011
                                        $r['cpage'] = '';
 
2012
                                } else {
 
2013
                                        $r['cpage'] = $cpage;
 
2014
                                }
 
2015
 
 
2016
                                $r['page'] = 0;
 
2017
                                $r['per_page'] = 0;
 
2018
                        }
1991
2019
                }
1992
2020
        }
1993
2021