Ticket #50233: 50233.1.diff
File 50233.1.diff, 2.5 KB (added by , 4 years ago) |
---|
-
src/wp-includes/canonical.php
27 27 * or query in an attempt to figure the correct page to go to. 28 28 * 29 29 * @since 2.3.0 30 * 30 * @since 5.6.0 checks comments page count to limit pagination 31 31 * @global WP_Rewrite $wp_rewrite WordPress rewrite component. 32 32 * @global bool $is_IIS 33 33 * @global WP_Query $wp_query WordPress Query object. … … 490 490 && ( 'newest' === $default_comments_page && $cpage > 0 491 491 || 'newest' !== $default_comments_page && $cpage > 1 ) 492 492 ) { 493 $addl_path = ( ! empty( $addl_path ) ? trailingslashit( $addl_path ) : '' ); 494 $addl_path .= user_trailingslashit( $wp_rewrite->comments_pagination_base . '-' . $cpage, 'commentpaged' ); 495 493 //checks comments page count to limit pagination 494 $per_page = get_option( 'comments_per_page' ); 495 $comments_total_pages = ceil( ( $wp_query->post->comment_count ) / $per_page );//get total number of pages for comments 496 if ( $cpage <= $comments_total_pages ) { 497 $addl_path = ( ! empty( $addl_path ) ? trailingslashit( $addl_path ) : '' ); 498 $addl_path .= user_trailingslashit( $wp_rewrite->comments_pagination_base . '-' . $cpage, 'commentpaged' ); 499 } 496 500 $redirect['query'] = remove_query_arg( 'cpage', $redirect['query'] ); 497 501 } 498 502 499 503 // Strip off trailing /index.php/. 500 504 $redirect['path'] = preg_replace( '|/' . preg_quote( $wp_rewrite->index, '|' ) . '/?$|', '/', $redirect['path'] ); 501 505 $redirect['path'] = user_trailingslashit( $redirect['path'] ); -
tests/phpunit/tests/link/wpGetCanonicalURL.php
152 152 } 153 153 154 154 /** 155 * Limit pagination for comments. 156 * 157 * @ticket 50233 158 */ 159 public function test_comments_limit_paged_with_plain_permalink_structure() { 160 $cpage = 5; 161 162 $link = add_query_arg( 163 array( 164 'cpage' => $cpage, 165 'foo' => 'bar', 166 ), 167 get_permalink( self::$post_id ) 168 ); 169 170 $this->go_to( $link ); 171 172 $expected = get_permalink( self::$post_id ) . '#comments'; 173 174 $this->assertSame( $expected, wp_get_canonical_url( self::$post_id ) ); 175 } 176 177 178 /** 155 179 * Filter callback for testing of filter usage. 156 180 * 157 181 * @return string