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. Built from https://develop.svn.wordpress.org/trunk@42965 git-svn-id: http://core.svn.wordpress.org/trunk@42794 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
d3f054b5a9
commit
b76da1fdf3
|
@ -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.
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
!function(a){function b(a){return a=b.buildAjaxOptions(a),b.transport(a)}var c=window.wpApiSettings;b.buildAjaxOptions=function(b){var d,e,f,g,h,i=b.url,j=b.path;if("string"==typeof b.namespace&&"string"==typeof b.endpoint&&(d=b.namespace.replace(/^\/|\/$/g,""),e=b.endpoint.replace(/^\//,""),j=e?d+"/"+e:d),"string"==typeof j&&(i=c.root+j.replace(/^\//,"")),g=!(b.data&&b.data._wpnonce),f=b.headers||{},g)for(h in f)if(f.hasOwnProperty(h)&&"x-wp-nonce"===h.toLowerCase()){g=!1;break}return g&&(f=a.extend({"X-WP-Nonce":c.nonce},f)),b=a.extend({},b,{headers:f,url:i}),delete b.path,delete b.namespace,delete b.endpoint,b},b.transport=a.ajax,window.wp=window.wp||{},window.wp.apiRequest=b}(jQuery);
|
!function(a){function b(a){return a=b.buildAjaxOptions(a),b.transport(a)}var c=window.wpApiSettings;b.buildAjaxOptions=function(b){var d,e,f,g,h,i,j=b.url,k=b.path;if("string"==typeof b.namespace&&"string"==typeof b.endpoint&&(d=b.namespace.replace(/^\/|\/$/g,""),e=b.endpoint.replace(/^\//,""),k=e?d+"/"+e:d),"string"==typeof k&&(f=c.root,k=k.replace(/^\//,""),"string"==typeof f&&-1!==f.indexOf("?")&&(k=k.replace("?","&")),j=f+k),h=!(b.data&&b.data._wpnonce),g=b.headers||{},h)for(i in g)if(g.hasOwnProperty(i)&&"x-wp-nonce"===i.toLowerCase()){h=!1;break}return h&&(g=a.extend({"X-WP-Nonce":c.nonce},g)),b=a.extend({},b,{headers:g,url:j}),delete b.path,delete b.namespace,delete b.endpoint,b},b.transport=a.ajax,window.wp=window.wp||{},window.wp.apiRequest=b}(jQuery);
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '5.0-alpha-42964';
|
$wp_version = '5.0-alpha-42965';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue