From 24ca39bf896aa1be7daea2d56c28f1285b260843 Mon Sep 17 00:00:00 2001 From: gziolo Date: Mon, 23 Sep 2024 12:50:15 +0000 Subject: [PATCH] Comments: Pass $page as argument to comments functions Removes query alteration from `build_comment_query_vars_from_block` by introducing a new way to pass the `$page` as argument to functions handling pagination for the comments. Props cybr, santosguillamot, bernhard-reiter, gziolo. Fixes #60806. Built from https://develop.svn.wordpress.org/trunk@59081 git-svn-id: http://core.svn.wordpress.org/trunk@58477 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/blocks.php | 5 ----- wp-includes/link-template.php | 22 +++++++++++++++------- wp-includes/version.php | 2 +- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/wp-includes/blocks.php b/wp-includes/blocks.php index 9e3e470304..a53092e04e 100644 --- a/wp-includes/blocks.php +++ b/wp-includes/blocks.php @@ -2567,11 +2567,6 @@ function build_comment_query_vars_from_block( $block ) { $comment_args['paged'] = $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'] ); - } } } diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index 08320dc792..a3c285b850 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -3109,21 +3109,25 @@ function get_comments_pagenum_link( $pagenum = 1, $max_page = 0 ) { * Retrieves the link to the next comments page. * * @since 2.7.1 + * @since 6.7.0 Added the `page` parameter. * * @global WP_Query $wp_query WordPress Query object. * - * @param string $label Optional. Label for link text. Default empty. - * @param int $max_page Optional. Max page. Default 0. + * @param string $label Optional. Label for link text. Default empty. + * @param int $max_page Optional. Max page. Default 0. + * @param int|null $page Optional. Page number. Default null. * @return string|void HTML-formatted link for the next page of comments. */ -function get_next_comments_link( $label = '', $max_page = 0 ) { +function get_next_comments_link( $label = '', $max_page = 0, $page = null ) { global $wp_query; if ( ! is_singular() ) { return; } - $page = get_query_var( 'cpage' ); + if ( is_null( $page ) ) { + $page = get_query_var( 'cpage' ); + } if ( ! $page ) { $page = 1; @@ -3180,16 +3184,20 @@ function next_comments_link( $label = '', $max_page = 0 ) { * Retrieves the link to the previous comments page. * * @since 2.7.1 + * @since 6.7.0 Added the `page` parameter. * - * @param string $label Optional. Label for comments link text. Default empty. + * @param string $label Optional. Label for comments link text. Default empty. + * @param int|null $page Optional. Page number. Default null. * @return string|void HTML-formatted link for the previous page of comments. */ -function get_previous_comments_link( $label = '' ) { +function get_previous_comments_link( $label = '', $page = null ) { if ( ! is_singular() ) { return; } - $page = get_query_var( 'cpage' ); + if ( is_null( $page ) ) { + $page = get_query_var( 'cpage' ); + } if ( (int) $page <= 1 ) { return; diff --git a/wp-includes/version.php b/wp-includes/version.php index c971a64761..86fa988513 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.7-alpha-59080'; +$wp_version = '6.7-alpha-59081'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.