REST API: Allow overriding jQuery.ajax calls from within wp-admin

There are now 3 places where we call out to the REST API from within wp-admin.  This commit introduces a small library to allow overriding these calls, centralize nonce-passing logic, and eliminate the need to pass a full REST URL down to client code (this last feature is not yet used and will be explored in a separate ticket).

Fixes #40919.


git-svn-id: https://develop.svn.wordpress.org/trunk@41206 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
James Nylen
2017-08-02 16:44:05 +00:00
parent 9c1005410f
commit 1c28b4a3c8
8 changed files with 109 additions and 21 deletions

View File

@@ -110,13 +110,12 @@
control.fetchEmbedDfd.abort();
}
control.fetchEmbedDfd = jQuery.ajax({
control.fetchEmbedDfd = wp.apiRequest({
url: wp.media.view.settings.oEmbedProxyUrl,
data: {
url: control.model.get( 'url' ),
maxwidth: control.model.get( 'width' ),
maxheight: control.model.get( 'height' ),
_wpnonce: wp.media.view.settings.nonce.wpRestApi,
discover: false
},
type: 'GET',

View File

@@ -200,13 +200,12 @@ wp.mediaWidgets = ( function( $ ) {
embedLinkView.model.attributes.url = url;
}
embedLinkView.dfd = $.ajax({
embedLinkView.dfd = wp.apiRequest({
url: wp.media.view.settings.oEmbedProxyUrl,
data: {
url: url,
maxwidth: embedLinkView.model.get( 'width' ),
maxheight: embedLinkView.model.get( 'height' ),
_wpnonce: wp.media.view.settings.nonce.wpRestApi,
discover: false
},
type: 'GET',