Added an extra bonus in redirect_canonical()
https://github.com/dd32/wordpress-develop/commit/648ad2a505e1817c9424800feacc06b0801fe630
redirect_canonical(): Don't attempt a ?page to /page/ redirect if the base url is unknown.
When redirect_canonical() attempts to redirect from ?page=2 to /page/2/ if the base-url is unknown the result is an attempt to redirect to /2/ which through a series of unfortunate assumptions in the code (Only full URLs are expected) results in an attempt to redirect to ://hostname.example/2/ and causes a series of php warnings such as:
Warning: Undefined array key "scheme" in wp-includes/canonical.php on line 752
Warning: Undefined array key "host" in wp-includes/canonical.php on line 717
Warning: Undefined array key "host" in wp-includes/canonical.php on line 728
Warning: Undefined array key "host" in wp-includes/canonical.php on line 731
By only attempting to perform the singular pagination redirects when we actually have a singular permalink to redirect to, it prevents a chain of awkward warnings that appear unrelated.
Unfortunately I couldn't immediately figure out how to trigger it on a vanilla install, but here's the type of request from GlotPress:
GET https://translate.wordpress.test/projects/meta/wordpress-org/en-au/default/?name=blahblahblah&page=2
which eventually attempts:
redirect_canonical( $requested_url = '://translate.wordpress.test/2/?name=blahblahblah', $do_redirect = FALSE )
As such, there's an alternate way that could be avoided, and may work better in some situations, but the above change resolves the main warning.
-
|
|
|
|
| 615 | 618 | unset( $redirect['port'] ); |
| 616 | 619 | } |
| 617 | 620 | |
| | 621 | // If the redirect scheme is unknown, default to the current scheme. |
| | 622 | if ( empty( $redirect['scheme'] ) ) { |
| | 623 | $redirect['scheme'] = is_ssl() ? 'https' : 'http'; |
| | 624 | } |
| | 625 | |
| 618 | 626 | // Trailing /index.php. |
| 619 | 627 | $redirect['path'] = preg_replace( '|/' . preg_quote( $wp_rewrite->index, '|' ) . '/*?$|', '/', $redirect['path'] ); |