Skip to content

Commit

Permalink
Editor: Update build_comment_query_vars_from_block from Gutenberg
Browse files Browse the repository at this point in the history
Follow-up for [53138].
See #55505.



git-svn-id: https://develop.svn.wordpress.org/trunk@53142 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
gziolo committed Apr 11, 2022
1 parent 65e8a87 commit cab6fec
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions src/wp-includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -1392,24 +1392,25 @@ function build_comment_query_vars_from_block( $block ) {
$comment_args['hierarchical'] = false;
}

$per_page = get_option( 'comments_per_page' );
$default_page = get_option( 'default_comments_page' );

if ( $per_page > 0 ) {
$comment_args['number'] = $per_page;

$page = (int) get_query_var( 'cpage' );
if ( $page ) {
$comment_args['paged'] = $page;
} elseif ( 'oldest' === $default_page ) {
$comment_args['paged'] = 1;
} elseif ( 'newest' === $default_page ) {
$comment_args['paged'] = (int) ( new WP_Comment_Query( $comment_args ) )->max_num_pages;
}
// Set the `cpage` query var to ensure the previous and next pagination links are correct
// when inheriting the Discussion Settings.
if ( 0 === $page && isset( $comment_args['paged'] ) && $comment_args['paged'] > 0 ) {
set_query_var( 'cpage', $comment_args['paged'] );
if ( get_option( 'page_comments' ) === '1' || get_option( 'page_comments' ) === true ) {
$per_page = get_option( 'comments_per_page' );
$default_page = get_option( 'default_comments_page' );
if ( $per_page > 0 ) {
$comment_args['number'] = $per_page;

$page = (int) get_query_var( 'cpage' );
if ( $page ) {
$comment_args['paged'] = $page;
} elseif ( 'oldest' === $default_page ) {
$comment_args['paged'] = 1;
} elseif ( 'newest' === $default_page ) {
$comment_args['paged'] = (int) ( new WP_Comment_Query( $comment_args ) )->max_num_pages;
}
// Set the `cpage` query var to ensure the previous and next pagination links are correct
// when inheriting the Discussion Settings.
if ( 0 === $page && isset( $comment_args['paged'] ) && $comment_args['paged'] > 0 ) {
set_query_var( 'cpage', $comment_args['paged'] );
}
}
}

Expand Down

0 comments on commit cab6fec

Please sign in to comment.