Changeset 36356
- Timestamp:
- 01/20/2016 05:23:02 AM (9 years ago)
- Location:
- branches/4.4
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.4
-
branches/4.4/src/wp-includes/comment-template.php
r36353 r36356 1935 1935 $r = apply_filters( 'wp_list_comments_args', $r ); 1936 1936 1937 /*1938 * If 'page' or 'per_page' has been passed, and does not match what's in $wp_query,1939 * perform a separate comment query and allow Walker_Comment to paginate.1940 */1941 if ( is_singular() && ( $r['page'] || $r['per_page'] ) ) {1942 $current_cpage = get_query_var( 'cpage' );1943 if ( ! $current_cpage ) {1944 $current_cpage = 'newest' === get_option( 'default_comments_page' ) ? 1 : $wp_query->max_num_comment_pages;1945 }1946 1947 $current_per_page = get_query_var( 'comments_per_page' );1948 if ( $r['page'] != $current_cpage || $r['per_page'] != $current_per_page ) {1949 $comments = get_comments( array(1950 'post_id' => get_queried_object_id(),1951 'orderby' => 'comment_date_gmt',1952 'order' => 'ASC',1953 'status' => 'all',1954 ) );1955 }1956 }1957 1958 1937 // Figure out what comments we'll be looping through ($_comments) 1959 1938 if ( null !== $comments ) { … … 1970 1949 } 1971 1950 } else { 1972 if ( empty($wp_query->comments) ) 1973 return; 1974 if ( 'all' != $r['type'] ) { 1975 if ( empty($wp_query->comments_by_type) ) 1976 $wp_query->comments_by_type = separate_comments($wp_query->comments); 1977 if ( empty($wp_query->comments_by_type[$r['type']]) ) 1951 /* 1952 * If 'page' or 'per_page' has been passed, and does not match what's in $wp_query, 1953 * perform a separate comment query and allow Walker_Comment to paginate. 1954 */ 1955 if ( is_singular() && ( $r['page'] || $r['per_page'] ) ) { 1956 $current_cpage = get_query_var( 'cpage' ); 1957 if ( ! $current_cpage ) { 1958 $current_cpage = 'newest' === get_option( 'default_comments_page' ) ? 1 : $wp_query->max_num_comment_pages; 1959 } 1960 1961 $current_per_page = get_query_var( 'comments_per_page' ); 1962 if ( $r['page'] != $current_cpage || $r['per_page'] != $current_per_page ) { 1963 $comments = get_comments( array( 1964 'post_id' => get_queried_object_id(), 1965 'orderby' => 'comment_date_gmt', 1966 'order' => 'ASC', 1967 'status' => 'all', 1968 ) ); 1969 1970 if ( 'all' != $r['type'] ) { 1971 $comments_by_type = separate_comments( $comments ); 1972 if ( empty( $comments_by_type[ $r['type'] ] ) ) { 1973 return; 1974 } 1975 1976 $_comments = $comments_by_type[ $r['type'] ]; 1977 } else { 1978 $_comments = $comments; 1979 } 1980 } 1981 1982 // Otherwise, fall back on the comments from `$wp_query->comments`. 1983 } else { 1984 if ( empty($wp_query->comments) ) 1978 1985 return; 1979 $_comments = $wp_query->comments_by_type[$r['type']]; 1980 } else { 1981 $_comments = $wp_query->comments; 1982 } 1983 1984 // Pagination is already handled by `WP_Comment_Query`, so we tell Walker not to bother. 1985 if ( $wp_query->max_num_comment_pages ) { 1986 $default_comments_page = get_option( 'default_comments_page' ); 1987 $cpage = get_query_var( 'cpage' ); 1988 if ( 'newest' === $default_comments_page ) { 1989 $r['cpage'] = $cpage; 1990 1991 // When first page shows oldest comments, post permalink is the same as the comment permalink. 1992 } elseif ( $cpage == 1 ) { 1993 $r['cpage'] = ''; 1986 if ( 'all' != $r['type'] ) { 1987 if ( empty($wp_query->comments_by_type) ) 1988 $wp_query->comments_by_type = separate_comments($wp_query->comments); 1989 if ( empty($wp_query->comments_by_type[$r['type']]) ) 1990 return; 1991 $_comments = $wp_query->comments_by_type[$r['type']]; 1994 1992 } else { 1995 $ r['cpage'] = $cpage;1993 $_comments = $wp_query->comments; 1996 1994 } 1997 1995 1998 $r['page'] = 0; 1999 $r['per_page'] = 0; 1996 if ( $wp_query->max_num_comment_pages ) { 1997 $default_comments_page = get_option( 'default_comments_page' ); 1998 $cpage = get_query_var( 'cpage' ); 1999 if ( 'newest' === $default_comments_page ) { 2000 $r['cpage'] = $cpage; 2001 2002 /* 2003 * When first page shows oldest comments, post permalink is the same as 2004 * the comment permalink. 2005 */ 2006 } elseif ( $cpage == 1 ) { 2007 $r['cpage'] = ''; 2008 } else { 2009 $r['cpage'] = $cpage; 2010 } 2011 2012 $r['page'] = 0; 2013 $r['per_page'] = 0; 2014 } 2000 2015 } 2001 2016 } -
branches/4.4/tests/phpunit/tests/comment/wpListComments.php
r36158 r36356 111 111 $this->assertSame( array( $comments[1], $comments[0] ), array_map( 'intval', $matches[1] ) ); 112 112 } 113 114 /** 115 * @ticket 35356 116 * @ticket 35175 117 */ 118 public function test_comments_param_should_be_respected_when_custom_pagination_params_are_passed() { 119 $p = self::factory()->post->create(); 120 121 $comments = array(); 122 $now = time(); 123 for ( $i = 0; $i <= 5; $i++ ) { 124 $comments[] = self::factory()->comment->create( array( 125 'comment_post_ID' => $p, 126 'comment_date_gmt' => date( 'Y-m-d H:i:s', $now - $i ), 127 'comment_author' => 'Commenter ' . $i, 128 ) ); 129 } 130 131 update_option( 'page_comments', true ); 132 update_option( 'comments_per_page', 2 ); 133 134 $_comments = array( get_comment( $comments[1] ), get_comment( $comments[3] ) ); 135 136 // Populate `$wp_query->comments` in order to show that it doesn't override `$_comments`. 137 $this->go_to( get_permalink( $p ) ); 138 get_echo( 'comments_template' ); 139 140 $found = wp_list_comments( array( 141 'echo' => false, 142 'per_page' => 1, 143 'page' => 2, 144 ), $_comments ); 145 146 preg_match_all( '|id="comment\-([0-9]+)"|', $found, $matches ); 147 $this->assertSame( array( $comments[3] ), array_map( 'intval', $matches[1] ) ); 148 } 113 149 }
Note: See TracChangeset
for help on using the changeset viewer.