diff --git a/wp-includes/js/api-request.js b/wp-includes/js/api-request.js index 51df7f6f64..885e5b47f8 100644 --- a/wp-includes/js/api-request.js +++ b/wp-includes/js/api-request.js @@ -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; diff --git a/wp-includes/js/api-request.min.js b/wp-includes/js/api-request.min.js index c0c0572bff..63b9c9c2fe 100644 --- a/wp-includes/js/api-request.min.js +++ b/wp-includes/js/api-request.min.js @@ -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); \ No newline at end of file +!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); \ No newline at end of file diff --git a/wp-includes/version.php b/wp-includes/version.php index 6546bd93da..fd9b782436 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.