REST API: Ensure rest_url() consistently has leading slash.

`rest_url()` inconsistent addes slashes to the passed path depending on whether the site has pretty permalinks enabled. Apart from being inconsistent, this also caused the unit tests to fail when pretty permalinks are enabled.

Props frank-klein.
Fixes #42452. See #41451.


git-svn-id: https://develop.svn.wordpress.org/trunk@42250 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan McCue
2017-11-28 07:09:43 +00:00
parent 209ede72de
commit 49852ed54f
2 changed files with 30 additions and 3 deletions
+3 -3
View File
@@ -307,6 +307,8 @@ function get_rest_url( $blog_id = null, $path = '/', $scheme = 'rest' ) {
$path = '/';
}
$path = '/' . ltrim( $path, '/' );
if ( is_multisite() && get_blog_option( $blog_id, 'permalink_structure' ) || get_option( 'permalink_structure' ) ) {
global $wp_rewrite;
@@ -316,7 +318,7 @@ function get_rest_url( $blog_id = null, $path = '/', $scheme = 'rest' ) {
$url = get_home_url( $blog_id, rest_get_url_prefix(), $scheme );
}
$url .= '/' . ltrim( $path, '/' );
$url .= $path;
} else {
$url = trailingslashit( get_home_url( $blog_id, '', $scheme ) );
// nginx only allows HTTP/1.0 methods when redirecting from / to /index.php
@@ -325,8 +327,6 @@ function get_rest_url( $blog_id = null, $path = '/', $scheme = 'rest' ) {
$url .= 'index.php';
}
$path = '/' . ltrim( $path, '/' );
$url = add_query_arg( 'rest_route', $path, $url );
}