Make WordPress Core


Ignore:
Timestamp:
10/16/2023 12:05:28 AM (2 years ago)
Author:
costdev
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/link-template.php

    r56767 r56939  
    24322432        preg_match( $qs_regex, $request, $qs_match );
    24332433
     2434        $parts   = array();
     2435        $parts[] = untrailingslashit( get_bloginfo( 'url' ) );
     2436
    24342437        if ( ! empty( $qs_match[0] ) ) {
    24352438            $query_string = $qs_match[0];
     
    24432446        $request = ltrim( $request, '/' );
    24442447
    2445         $base = trailingslashit( get_bloginfo( 'url' ) );
    2446 
    24472448        if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' !== $request ) ) {
    2448             $base .= $wp_rewrite->index . '/';
    2449         }
     2449            $parts[] = $wp_rewrite->index;
     2450        }
     2451
     2452        $parts[] = untrailingslashit( $request );
    24502453
    24512454        if ( $pagenum > 1 ) {
    2452             $request = ( ( ! empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( $wp_rewrite->pagination_base . '/' . $pagenum, 'paged' );
    2453         }
    2454 
    2455         $result = $base . $request . $query_string;
     2455            $parts[] = $wp_rewrite->pagination_base;
     2456            $parts[] = $pagenum;
     2457        }
     2458
     2459        $result = user_trailingslashit( implode( '/', array_filter( $parts ) ), 'paged' );
     2460        if ( ! empty( $query_string ) ) {
     2461            $result .= $query_string;
     2462        }
    24562463    }
    24572464
Note: See TracChangeset for help on using the changeset viewer.