Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/js/_enqueues/wp/api-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand Down