mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-23 01:27:36 +01:00
REST API: Add HTTP/1.0 emulation to wp.apiRequest().
This allows for making REST API calls with the PUT and DELETE HTTP methods that may be blocked or unsupported by some server configurations. Props yakimun. Fixes #43605. Built from https://develop.svn.wordpress.org/trunk@49133 git-svn-id: http://core.svn.wordpress.org/trunk@48895 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
49a399db05
commit
ba5b09af09
@ -9,6 +9,7 @@
|
||||
* - Allows specifying only an endpoint namespace/path instead of a full URL.
|
||||
*
|
||||
* @since 4.9.0
|
||||
* @since 5.6.0 Added overriding of the "PUT" and "DELETE" methods with "POST".
|
||||
* @output wp-includes/js/api-request.js
|
||||
*/
|
||||
|
||||
@ -23,6 +24,7 @@
|
||||
apiRequest.buildAjaxOptions = function( options ) {
|
||||
var url = options.url;
|
||||
var path = options.path;
|
||||
var method = options.method;
|
||||
var namespaceTrimmed, endpointTrimmed, apiRoot;
|
||||
var headers, addNonceHeader, headerName;
|
||||
|
||||
@ -76,10 +78,23 @@
|
||||
}, headers );
|
||||
}
|
||||
|
||||
if ( typeof method === 'string' ) {
|
||||
method = method.toUpperCase();
|
||||
|
||||
if ( 'PUT' === method || 'DELETE' === method ) {
|
||||
headers = $.extend( {
|
||||
'X-HTTP-Method-Override': method
|
||||
}, headers );
|
||||
|
||||
method = 'POST';
|
||||
}
|
||||
}
|
||||
|
||||
// Do not mutate the original options object.
|
||||
options = $.extend( {}, options, {
|
||||
headers: headers,
|
||||
url: url
|
||||
url: url,
|
||||
method: method
|
||||
} );
|
||||
|
||||
delete options.path;
|
||||
|
2
wp-includes/js/api-request.min.js
vendored
2
wp-includes/js/api-request.min.js
vendored
@ -1,2 +1,2 @@
|
||||
/*! This file is auto-generated */
|
||||
!function(s){var w=window.wpApiSettings;function n(e){return e=n.buildAjaxOptions(e),n.transport(e)}n.buildAjaxOptions=function(e){var n,t,a,p,r,o,i=e.url,d=e.path;if("string"==typeof e.namespace&&"string"==typeof e.endpoint&&(n=e.namespace.replace(/^\/|\/$/g,""),d=(t=e.endpoint.replace(/^\//,""))?n+"/"+t:n),"string"==typeof d&&(a=w.root,d=d.replace(/^\//,""),"string"==typeof a&&-1!==a.indexOf("?")&&(d=d.replace("?","&")),i=a+d),r=!(e.data&&e.data._wpnonce),p=e.headers||{},r)for(o in p)if(p.hasOwnProperty(o)&&"x-wp-nonce"===o.toLowerCase()){r=!1;break}return r&&(p=s.extend({"X-WP-Nonce":w.nonce},p)),delete(e=s.extend({},e,{headers:p,url:i})).path,delete e.namespace,delete e.endpoint,e},n.transport=s.ajax,window.wp=window.wp||{},window.wp.apiRequest=n}(jQuery);
|
||||
!function(w){var c=window.wpApiSettings;function n(e){return e=n.buildAjaxOptions(e),n.transport(e)}n.buildAjaxOptions=function(e){var n,t,o,r,p,a,i=e.url,d=e.path,s=e.method;if("string"==typeof e.namespace&&"string"==typeof e.endpoint&&(n=e.namespace.replace(/^\/|\/$/g,""),d=(t=e.endpoint.replace(/^\//,""))?n+"/"+t:n),"string"==typeof d&&(o=c.root,d=d.replace(/^\//,""),"string"==typeof o&&-1!==o.indexOf("?")&&(d=d.replace("?","&")),i=o+d),p=!(e.data&&e.data._wpnonce),r=e.headers||{},p)for(a in r)if(r.hasOwnProperty(a)&&"x-wp-nonce"===a.toLowerCase()){p=!1;break}return p&&(r=w.extend({"X-WP-Nonce":c.nonce},r)),"string"==typeof s&&("PUT"!==(s=s.toUpperCase())&&"DELETE"!==s||(r=w.extend({"X-HTTP-Method-Override":s},r),s="POST")),delete(e=w.extend({},e,{headers:r,url:i,method:s})).path,delete e.namespace,delete e.endpoint,e},n.transport=w.ajax,window.wp=window.wp||{},window.wp.apiRequest=n}(jQuery);
|
@ -13,7 +13,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.6-alpha-49132';
|
||||
$wp_version = '5.6-alpha-49133';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user