Make WordPress Core

Ticket #50233: 50233.patch

File 50233.patch, 1.6 KB (added by sumanm, 4 years ago)

This patch adds page limitation for comments non existing page and redirect to parent post

  • canonical.php

     
    2727 * or query in an attempt to figure the correct page to go to.
    2828 *
    2929 * @since 2.3.0
    30  *
     30 * @since 5.6.0 checks comments page count to limit pagination
    3131 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
    3232 * @global bool       $is_IIS
    3333 * @global WP_Query   $wp_query   WordPress Query object.
     
    490490                                && ( 'newest' === $default_comments_page && $cpage > 0
    491491                                        || 'newest' !== $default_comments_page && $cpage > 1 )
    492492                        ) {
    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                                }
    496500                                $redirect['query'] = remove_query_arg( 'cpage', $redirect['query'] );
    497501                        }
    498 
     502                       
    499503                        // Strip off trailing /index.php/.
    500504                        $redirect['path'] = preg_replace( '|/' . preg_quote( $wp_rewrite->index, '|' ) . '/?$|', '/', $redirect['path'] );
    501505                        $redirect['path'] = user_trailingslashit( $redirect['path'] );