REST API: Handle api-request query parameters with plain permalinks.
When constructing the request URL, ensure that `?` is replaced with `&` when the API root already contains a `?`. Fixes an issue where requests were broken when sites had permalinks set to plain. Props aduth. Fixes #42382. git-svn-id: https://develop.svn.wordpress.org/trunk@42965 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
531abcbdd4
commit
495ac15555
@ -22,7 +22,7 @@
|
|||||||
apiRequest.buildAjaxOptions = function( options ) {
|
apiRequest.buildAjaxOptions = function( options ) {
|
||||||
var url = options.url;
|
var url = options.url;
|
||||||
var path = options.path;
|
var path = options.path;
|
||||||
var namespaceTrimmed, endpointTrimmed;
|
var namespaceTrimmed, endpointTrimmed, apiRoot;
|
||||||
var headers, addNonceHeader, headerName;
|
var headers, addNonceHeader, headerName;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@ -38,7 +38,16 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( typeof path === 'string' ) {
|
if ( typeof path === 'string' ) {
|
||||||
url = wpApiSettings.root + path.replace( /^\//, '' );
|
apiRoot = wpApiSettings.root;
|
||||||
|
path = path.replace( /^\//, '' );
|
||||||
|
|
||||||
|
// API root may already include query parameter prefix if site is
|
||||||
|
// configured to use plain permalinks.
|
||||||
|
if ( 'string' === typeof apiRoot && -1 !== apiRoot.indexOf( '?' ) ) {
|
||||||
|
path = path.replace( '?', '&' );
|
||||||
|
}
|
||||||
|
|
||||||
|
url = apiRoot + path;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If ?_wpnonce=... is present, no need to add a nonce header.
|
// If ?_wpnonce=... is present, no need to add a nonce header.
|
||||||
|
@ -140,9 +140,9 @@
|
|||||||
window.wpApiSettings.root = 'http://localhost/index.php?rest_route=/';
|
window.wpApiSettings.root = 'http://localhost/index.php?rest_route=/';
|
||||||
assert.deepEqual( wp.apiRequest.buildAjaxOptions( {
|
assert.deepEqual( wp.apiRequest.buildAjaxOptions( {
|
||||||
namespace: '/wp/v2/',
|
namespace: '/wp/v2/',
|
||||||
endpoint: '/posts'
|
endpoint: '/posts?orderby=title'
|
||||||
} ), {
|
} ), {
|
||||||
url: 'http://localhost/index.php?rest_route=/wp/v2/posts',
|
url: 'http://localhost/index.php?rest_route=/wp/v2/posts&orderby=title',
|
||||||
headers: nonceHeader
|
headers: nonceHeader
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user