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.

git-svn-id: https://develop.svn.wordpress.org/trunk@56939 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Colin Stewart
2023-10-16 00:05:28 +00:00
parent f5e171652f
commit 60cd149b6f
3 changed files with 211 additions and 27 deletions

View File

@@ -4,28 +4,6 @@
*/
class Tests_Link extends WP_UnitTestCase {
public function get_pagenum_link_cb( $url ) {
return $url . '/WooHoo';
}
/**
* @ticket 8847
*/
public function test_get_pagenum_link_case_insensitivity() {
$old_req_uri = $_SERVER['REQUEST_URI'];
$this->set_permalink_structure( '/%year%/%monthnum%/%day%/%postname%/' );
add_filter( 'home_url', array( $this, 'get_pagenum_link_cb' ) );
$_SERVER['REQUEST_URI'] = '/woohoo';
$paged = get_pagenum_link( 2 );
remove_filter( 'home_url', array( $this, 'get_pagenum_link_cb' ) );
$this->assertSame( $paged, home_url( '/WooHoo/page/2/' ) );
$_SERVER['REQUEST_URI'] = $old_req_uri;
}
public function test_wp_get_shortlink() {
$post_id = self::factory()->post->create();
$post_id2 = self::factory()->post->create();