Make WordPress Core

Ticket #50233: 50233.2.patch

File 50233.2.patch, 2.2 KB (added by mukesh27, 4 years ago)

Minor changes

  • src/wp-includes/canonical.php

     
    2727 * or query in an attempt to figure the correct page to go to.
    2828 *
    2929 * @since 2.3.0
     30 * @since 5.6.0 checks comment page count to limit pagination.
    3031 *
    3132 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
    3233 * @global bool       $is_IIS
     
    490491                                && ( 'newest' === $default_comments_page && $cpage > 0
    491492                                        || 'newest' !== $default_comments_page && $cpage > 1 )
    492493                        ) {
    493                                 $addl_path  = ( ! empty( $addl_path ) ? trailingslashit( $addl_path ) : '' );
    494                                 $addl_path .= user_trailingslashit( $wp_rewrite->comments_pagination_base . '-' . $cpage, 'commentpaged' );
     494                                // checks comment page count to limit pagination.
     495                                $per_page             = get_option( 'comments_per_page' );
     496                                // get the total number of pages for comments.
     497                                $comments_total_pages = ceil( ( $wp_query->post->comment_count ) / $per_page );
     498                                if ( $cpage <= $comments_total_pages ) {
     499                                        $addl_path  = ( ! empty( $addl_path ) ? trailingslashit( $addl_path ) : '' );
     500                                        $addl_path .= user_trailingslashit( $wp_rewrite->comments_pagination_base . '-' . $cpage, 'commentpaged' );
     501                                }
    495502
    496503                                $redirect['query'] = remove_query_arg( 'cpage', $redirect['query'] );
    497504                        }
  • tests/phpunit/tests/link/wpGetCanonicalURL.php

     
    152152        }
    153153
    154154        /**
     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                $expected = get_permalink( self::$post_id ) . '#comments';
     172                $this->assertSame( $expected, wp_get_canonical_url( self::$post_id ) );
     173        }
     174
     175        /**
    155176         * Filter callback for testing of filter usage.
    156177         *
    157178         * @return string