From 13854cd7f5b2a99b0c88a8bdeaa4c59ca4703ca1 Mon Sep 17 00:00:00 2001 From: costdev Date: Mon, 16 Oct 2023 00:07:26 +0000 Subject: [PATCH] Posts, Post Types: Don't force trailing slash in `get_pagenum_link()`. Previously, a trailing slash was appended to the link returned from `get_pagenum_link()`. If the permalink structure didn't contain a trailing slash, this link could fail. This change removes trailing slashes and only appends one if the site is set for adding trailing slashes. This adds a new test file for the accompanying tests, `tests/phpunit/tests/link/getPagenumLink.php`, and moves an existing test for `get_pagenum_link()` to the same file. Props davemad-davenet, darkfate, Nazgul, scribu, nacin, obenland, chriscct7, jesin, matthewppelsheimer, audrasjb, petitphp, mukesh27, oglekler, mai21, webtechpooja, tejwanihemant, nicolefurlan, hellofromTonya, costdev. Fixes #2877. Built from https://develop.svn.wordpress.org/trunk@56939 git-svn-id: http://core.svn.wordpress.org/trunk@56450 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/link-template.php | 17 ++++++++++++----- wp-includes/version.php | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index e454ecebe0..9f3d9a97ee 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -2431,6 +2431,9 @@ function get_pagenum_link( $pagenum = 1, $escape = true ) { $qs_regex = '|\?.*?$|'; preg_match( $qs_regex, $request, $qs_match ); + $parts = array(); + $parts[] = untrailingslashit( get_bloginfo( 'url' ) ); + if ( ! empty( $qs_match[0] ) ) { $query_string = $qs_match[0]; $request = preg_replace( $qs_regex, '', $request ); @@ -2442,17 +2445,21 @@ function get_pagenum_link( $pagenum = 1, $escape = true ) { $request = preg_replace( '|^' . preg_quote( $wp_rewrite->index, '|' ) . '|i', '', $request ); $request = ltrim( $request, '/' ); - $base = trailingslashit( get_bloginfo( 'url' ) ); - if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' !== $request ) ) { - $base .= $wp_rewrite->index . '/'; + $parts[] = $wp_rewrite->index; } + $parts[] = untrailingslashit( $request ); + if ( $pagenum > 1 ) { - $request = ( ( ! empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( $wp_rewrite->pagination_base . '/' . $pagenum, 'paged' ); + $parts[] = $wp_rewrite->pagination_base; + $parts[] = $pagenum; } - $result = $base . $request . $query_string; + $result = user_trailingslashit( implode( '/', array_filter( $parts ) ), 'paged' ); + if ( ! empty( $query_string ) ) { + $result .= $query_string; + } } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index ab04a759b7..4471364753 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.4-beta4-56938'; +$wp_version = '6.4-beta4-56939'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.