From 46ba5721590de7d1d938fdeb7960f4bf0b55eaa9 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 18 Feb 2023 15:07:12 +0000 Subject: [PATCH] Coding Standards: Improve variables names in post and comment page link functions. This commit renames a few internal variables for better clarity and consistency: * `$nextpage` to `$next_page` in: * `get_next_posts_page_link()` * `get_next_posts_link()` * `get_next_comments_link()` * `$nextpage` to `$previous_page` in: * `get_previous_posts_page_link()` * `$prevpage` to `$previous_page` in: * `get_previous_comments_link()` Includes minor code layout fixes for better readability. Follow-up to [5045], [8502], [8961], [28111]. Props dalirajab, SergeyBiryukov. Fixes #57746. git-svn-id: https://develop.svn.wordpress.org/trunk@55364 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/link-template.php | 61 +++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 16 deletions(-) diff --git a/src/wp-includes/link-template.php b/src/wp-includes/link-template.php index e823282277..c151994cce 100644 --- a/src/wp-includes/link-template.php +++ b/src/wp-includes/link-template.php @@ -2481,9 +2481,11 @@ function get_next_posts_page_link( $max_page = 0 ) { if ( ! $paged ) { $paged = 1; } - $nextpage = (int) $paged + 1; - if ( ! $max_page || $max_page >= $nextpage ) { - return get_pagenum_link( $nextpage ); + + $next_page = (int) $paged + 1; + + if ( ! $max_page || $max_page >= $next_page ) { + return get_pagenum_link( $next_page ); } } } @@ -2530,13 +2532,13 @@ function get_next_posts_link( $label = null, $max_page = 0 ) { $paged = 1; } - $nextpage = (int) $paged + 1; + $next_page = (int) $paged + 1; if ( null === $label ) { $label = __( 'Next Page »' ); } - if ( ! is_single() && ( $nextpage <= $max_page ) ) { + if ( ! is_single() && ( $next_page <= $max_page ) ) { /** * Filters the anchor tag attributes for the next posts page link. * @@ -2546,7 +2548,12 @@ function get_next_posts_link( $label = null, $max_page = 0 ) { */ $attr = apply_filters( 'next_posts_link_attributes', '' ); - return '" . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) . ''; + return sprintf( + '%3$s', + next_posts( $max_page, false ), + $attr, + preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) + ); } } @@ -2579,11 +2586,13 @@ function get_previous_posts_page_link() { global $paged; if ( ! is_single() ) { - $nextpage = (int) $paged - 1; - if ( $nextpage < 1 ) { - $nextpage = 1; + $previous_page = (int) $paged - 1; + + if ( $previous_page < 1 ) { + $previous_page = 1; } - return get_pagenum_link( $nextpage ); + + return get_pagenum_link( $previous_page ); } } @@ -2631,7 +2640,13 @@ function get_previous_posts_link( $label = null ) { * @param string $attributes Attributes for the anchor tag. */ $attr = apply_filters( 'previous_posts_link_attributes', '' ); - return '" . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) . ''; + + return sprintf( + '%3$s', + previous_posts( false ), + $attr, + preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) + ); } } @@ -3079,7 +3094,7 @@ function get_next_comments_link( $label = '', $max_page = 0 ) { $page = 1; } - $nextpage = (int) $page + 1; + $next_page = (int) $page + 1; if ( empty( $max_page ) ) { $max_page = $wp_query->max_num_comment_pages; @@ -3089,7 +3104,7 @@ function get_next_comments_link( $label = '', $max_page = 0 ) { $max_page = get_comment_pages_count(); } - if ( $nextpage > $max_page ) { + if ( $next_page > $max_page ) { return; } @@ -3104,7 +3119,14 @@ function get_next_comments_link( $label = '', $max_page = 0 ) { * * @param string $attributes Attributes for the anchor tag. */ - return '' . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) . ''; + $attr = apply_filters( 'next_comments_link_attributes', '' ); + + return sprintf( + '%3$s', + esc_url( get_comments_pagenum_link( $next_page, $max_page ) ), + $attr, + preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) + ); } /** @@ -3138,7 +3160,7 @@ function get_previous_comments_link( $label = '' ) { return; } - $prevpage = (int) $page - 1; + $previous_page = (int) $page - 1; if ( empty( $label ) ) { $label = __( '« Older Comments' ); @@ -3151,7 +3173,14 @@ function get_previous_comments_link( $label = '' ) { * * @param string $attributes Attributes for the anchor tag. */ - return '' . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) . ''; + $attr = apply_filters( 'previous_comments_link_attributes', '' ); + + return sprintf( + '%3$s', + esc_url( get_comments_pagenum_link( $previous_page ) ), + $attr, + preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) + ); } /**