<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[41206] trunk: REST API: Allow overriding `jQuery.ajax` calls from within wp-admin</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/41206">41206</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/41206","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>jnylen0</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2017-08-02 16:44:05 +0000 (Wed, 02 Aug 2017)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>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 <a href="https://core.trac.wordpress.org/ticket/40919">#40919</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminjswidgetsmediavideowidgetjs">trunk/src/wp-admin/js/widgets/media-video-widget.js</a></li>
<li><a href="#trunksrcwpadminjswidgetsmediawidgetsjs">trunk/src/wp-admin/js/widgets/media-widgets.js</a></li>
<li><a href="#trunksrcwpincludesjsmediaviewsembedlinkjs">trunk/src/wp-includes/js/media/views/embed/link.js</a></li>
<li><a href="#trunksrcwpincludesjsmediaviewsjs">trunk/src/wp-includes/js/media-views.js</a></li>
<li><a href="#trunksrcwpincludesmediaphp">trunk/src/wp-includes/media.php</a></li>
<li><a href="#trunksrcwpincludesscriptloaderphp">trunk/src/wp-includes/script-loader.php</a></li>
<li><a href="#trunktestsqunitindexhtml">trunk/tests/qunit/index.html</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesjsapirequestjs">trunk/src/wp-includes/js/api-request.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminjswidgetsmediavideowidgetjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/js/widgets/media-video-widget.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/js/widgets/media-video-widget.js       2017-08-02 05:34:32 UTC (rev 41205)
+++ trunk/src/wp-admin/js/widgets/media-video-widget.js 2017-08-02 16:44:05 UTC (rev 41206)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -110,13 +110,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                control.fetchEmbedDfd.abort();
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        control.fetchEmbedDfd = jQuery.ajax({
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 control.fetchEmbedDfd = wp.apiRequest({
</ins><span class="cx" style="display: block; padding: 0 10px">                                 url: wp.media.view.settings.oEmbedProxyUrl,
</span><span class="cx" style="display: block; padding: 0 10px">                                data: {
</span><span class="cx" style="display: block; padding: 0 10px">                                        url: control.model.get( 'url' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                        maxwidth: control.model.get( 'width' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                        maxheight: control.model.get( 'height' ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        _wpnonce: wp.media.view.settings.nonce.wpRestApi,
</del><span class="cx" style="display: block; padding: 0 10px">                                         discover: false
</span><span class="cx" style="display: block; padding: 0 10px">                                },
</span><span class="cx" style="display: block; padding: 0 10px">                                type: 'GET',
</span></span></pre></div>
<a id="trunksrcwpadminjswidgetsmediawidgetsjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/js/widgets/media-widgets.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/js/widgets/media-widgets.js    2017-08-02 05:34:32 UTC (rev 41205)
+++ trunk/src/wp-admin/js/widgets/media-widgets.js      2017-08-02 16:44:05 UTC (rev 41206)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -200,13 +200,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                                        embedLinkView.model.attributes.url = url;
</span><span class="cx" style="display: block; padding: 0 10px">                                                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                embedLinkView.dfd = $.ajax({
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                         embedLinkView.dfd = wp.apiRequest({
</ins><span class="cx" style="display: block; padding: 0 10px">                                                         url: wp.media.view.settings.oEmbedProxyUrl,
</span><span class="cx" style="display: block; padding: 0 10px">                                                        data: {
</span><span class="cx" style="display: block; padding: 0 10px">                                                                url: url,
</span><span class="cx" style="display: block; padding: 0 10px">                                                                maxwidth: embedLinkView.model.get( 'width' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                                                maxheight: embedLinkView.model.get( 'height' ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                                _wpnonce: wp.media.view.settings.nonce.wpRestApi,
</del><span class="cx" style="display: block; padding: 0 10px">                                                                 discover: false
</span><span class="cx" style="display: block; padding: 0 10px">                                                        },
</span><span class="cx" style="display: block; padding: 0 10px">                                                        type: 'GET',
</span></span></pre></div>
<a id="trunksrcwpincludesjsapirequestjs"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/src/wp-includes/js/api-request.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/js/api-request.js                           (rev 0)
+++ trunk/src/wp-includes/js/api-request.js     2017-08-02 16:44:05 UTC (rev 41206)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,87 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/**
+ * Thin jQuery.ajax wrapper for WP REST API requests.
+ *
+ * Currently only applies to requests that do not use the `wp-api.js` Backbone
+ * client library, though this may change.  Serves several purposes:
+ *
+ * - Allows overriding these requests as needed by customized WP installations.
+ * - Sends the REST API nonce as a request header.
+ * - Allows specifying only an endpoint namespace/path instead of a full URL.
+ *
+ * @namespace wp.apiRequest
+ * @since     4.9.0
+ */
+
+( function( $ ) {
+       var wpApiSettings = window.wpApiSettings;
+
+       function apiRequest( options ) {
+               options = apiRequest.buildAjaxOptions( options );
+               return apiRequest.transport( options );
+       };
+
+       apiRequest.buildAjaxOptions = function( options ) {
+               var url = options.url;
+               var path = options.path;
+               var namespaceTrimmed, endpointTrimmed;
+               var headers, addNonceHeader, headerName;
+
+               if (
+                       typeof options.namespace === 'string' &&
+                       typeof options.endpoint === 'string'
+               ) {
+                       namespaceTrimmed = options.namespace.replace( /^\/|\/$/g, '' );
+                       endpointTrimmed = options.endpoint.replace( /^\//, '' );
+                       if ( endpointTrimmed ) {
+                               path = namespaceTrimmed + '/' + endpointTrimmed;
+                       } else {
+                               path = namespaceTrimmed;
+                       }
+               }
+               if ( typeof path === 'string' ) {
+                       url = wpApiSettings.root + path.replace( /^\//, '' );
+               }
+
+               // If ?_wpnonce=... is present, no need to add a nonce header.
+               addNonceHeader = ! ( options.data && options.data._wpnonce );
+
+               headers = options.headers || {};
+
+               // If an 'X-WP-Nonce' header (or any case-insensitive variation
+               // thereof) was specified, no need to add a nonce header.
+               if ( addNonceHeader ) {
+                       for ( headerName in headers ) {
+                               if ( headers.hasOwnProperty( headerName ) ) {
+                                       if ( headerName.toLowerCase() === 'x-wp-nonce' ) {
+                                               addNonceHeader = false;
+                                               break;
+                                       }
+                               }
+                       }
+               }
+
+               if ( addNonceHeader ) {
+                       // Do not mutate the original headers object, if any.
+                       headers = $.extend( {
+                               'X-WP-Nonce': wpApiSettings.nonce
+                       }, headers );
+               }
+
+               // Do not mutate the original options object.
+               options = $.extend( {}, options, {
+                       headers: headers,
+                       url: url
+               } );
+
+               delete options.path;
+               delete options.namespace;
+               delete options.endpoint;
+
+               return options;
+       };
+
+       apiRequest.transport = $.ajax;
+
+       window.wp = window.wp || {};
+       window.wp.apiRequest = apiRequest;
+} )( jQuery );
</ins></span></pre></div>
<a id="trunksrcwpincludesjsmediaviewsembedlinkjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/js/media/views/embed/link.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/js/media/views/embed/link.js        2017-08-02 05:34:32 UTC (rev 41205)
+++ trunk/src/wp-includes/js/media/views/embed/link.js  2017-08-02 16:44:05 UTC (rev 41206)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -53,13 +53,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        url = 'https://www.youtube.com/watch?v=' + youTubeEmbedMatch[ 1 ];
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                this.dfd = $.ajax({
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         this.dfd = wp.apiRequest({
</ins><span class="cx" style="display: block; padding: 0 10px">                         url: wp.media.view.settings.oEmbedProxyUrl,
</span><span class="cx" style="display: block; padding: 0 10px">                        data: {
</span><span class="cx" style="display: block; padding: 0 10px">                                url: url,
</span><span class="cx" style="display: block; padding: 0 10px">                                maxwidth: this.model.get( 'width' ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                maxheight: this.model.get( 'height' ),
-                               _wpnonce: wp.media.view.settings.nonce.wpRestApi
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         maxheight: this.model.get( 'height' )
</ins><span class="cx" style="display: block; padding: 0 10px">                         },
</span><span class="cx" style="display: block; padding: 0 10px">                        type: 'GET',
</span><span class="cx" style="display: block; padding: 0 10px">                        dataType: 'json',
</span></span></pre></div>
<a id="trunksrcwpincludesjsmediaviewsjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/js/media-views.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/js/media-views.js   2017-08-02 05:34:32 UTC (rev 41205)
+++ trunk/src/wp-includes/js/media-views.js     2017-08-02 16:44:05 UTC (rev 41206)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4642,13 +4642,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        url = 'https://www.youtube.com/watch?v=' + youTubeEmbedMatch[ 1 ];
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                this.dfd = $.ajax({
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         this.dfd = wp.apiRequest({
</ins><span class="cx" style="display: block; padding: 0 10px">                         url: wp.media.view.settings.oEmbedProxyUrl,
</span><span class="cx" style="display: block; padding: 0 10px">                        data: {
</span><span class="cx" style="display: block; padding: 0 10px">                                url: url,
</span><span class="cx" style="display: block; padding: 0 10px">                                maxwidth: this.model.get( 'width' ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                maxheight: this.model.get( 'height' ),
-                               _wpnonce: wp.media.view.settings.nonce.wpRestApi
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         maxheight: this.model.get( 'height' )
</ins><span class="cx" style="display: block; padding: 0 10px">                         },
</span><span class="cx" style="display: block; padding: 0 10px">                        type: 'GET',
</span><span class="cx" style="display: block; padding: 0 10px">                        dataType: 'json',
</span></span></pre></div>
<a id="trunksrcwpincludesmediaphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/media.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/media.php   2017-08-02 05:34:32 UTC (rev 41205)
+++ trunk/src/wp-includes/media.php     2017-08-02 16:44:05 UTC (rev 41206)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3437,7 +3437,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">                'captions'  => ! apply_filters( 'disable_captions', '' ),
</span><span class="cx" style="display: block; padding: 0 10px">                'nonce'     => array(
</span><span class="cx" style="display: block; padding: 0 10px">                        'sendToEditor' => wp_create_nonce( 'media-send-to-editor' ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'wpRestApi'    => wp_create_nonce( 'wp_rest' ),
</del><span class="cx" style="display: block; padding: 0 10px">                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                'post'    => array(
</span><span class="cx" style="display: block; padding: 0 10px">                        'id' => 0,
</span></span></pre></div>
<a id="trunksrcwpincludesscriptloaderphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/script-loader.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/script-loader.php   2017-08-02 05:34:32 UTC (rev 41205)
+++ trunk/src/wp-includes/script-loader.php     2017-08-02 16:44:05 UTC (rev 41206)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -133,6 +133,14 @@
</span><span class="cx" style="display: block; padding: 0 10px">                'broken' => __('An unidentified error has occurred.')
</span><span class="cx" style="display: block; padding: 0 10px">        ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        $scripts->add( 'wp-api-request', "/wp-includes/js/api-request$suffix.js", array( 'jquery' ), false, 1 );
+       // `wpApiSettings` is also used by `wp-api`, which depends on this script.
+       did_action( 'init' ) && $scripts->localize( 'wp-api-request', 'wpApiSettings', array(
+               'root'          => esc_url_raw( get_rest_url() ),
+               'nonce'         => ( wp_installing() && ! is_multisite() ) ? '' : wp_create_nonce( 'wp_rest' ),
+               'versionString' => 'wp/v2/',
+       ) );
+
</ins><span class="cx" style="display: block; padding: 0 10px">         $scripts->add( 'wp-pointer', "/wp-includes/js/wp-pointer$suffix.js", array( 'jquery-ui-widget', 'jquery-ui-position' ), '20111129a', 1 );
</span><span class="cx" style="display: block; padding: 0 10px">        did_action( 'init' ) && $scripts->localize( 'wp-pointer', 'wpPointerL10n', array(
</span><span class="cx" style="display: block; padding: 0 10px">                'dismiss' => __('Dismiss'),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -566,17 +574,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        // To enqueue media-views or media-editor, call wp_enqueue_media().
</span><span class="cx" style="display: block; padding: 0 10px">        // Both rely on numerous settings, styles, and templates to operate correctly.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        $scripts->add( 'media-views',  "/wp-includes/js/media-views$suffix.js",  array( 'utils', 'media-models', 'wp-plupload', 'jquery-ui-sortable', 'wp-mediaelement' ), false, 1 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $scripts->add( 'media-views',  "/wp-includes/js/media-views$suffix.js",  array( 'utils', 'media-models', 'wp-plupload', 'jquery-ui-sortable', 'wp-mediaelement', 'wp-api-request' ), false, 1 );
</ins><span class="cx" style="display: block; padding: 0 10px">         $scripts->add( 'media-editor', "/wp-includes/js/media-editor$suffix.js", array( 'shortcode', 'media-views' ), false, 1 );
</span><span class="cx" style="display: block; padding: 0 10px">        $scripts->add( 'media-audiovideo', "/wp-includes/js/media-audiovideo$suffix.js", array( 'media-editor' ), false, 1 );
</span><span class="cx" style="display: block; padding: 0 10px">        $scripts->add( 'mce-view', "/wp-includes/js/mce-view$suffix.js", array( 'shortcode', 'jquery', 'media-views', 'media-audiovideo' ), false, 1 );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        $scripts->add( 'wp-api', "/wp-includes/js/wp-api$suffix.js", array( 'jquery', 'backbone', 'underscore' ), false, 1 );
-       did_action( 'init' ) && $scripts->localize( 'wp-api', 'wpApiSettings', array(
-               'root'          => esc_url_raw( get_rest_url() ),
-               'nonce'         => ( wp_installing() && ! is_multisite() ) ? '' : wp_create_nonce( 'wp_rest' ),
-               'versionString' => 'wp/v2/',
-       ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $scripts->add( 'wp-api', "/wp-includes/js/wp-api$suffix.js", array( 'jquery', 'backbone', 'underscore', 'wp-api-request' ), false, 1 );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        if ( is_admin() ) {
</span><span class="cx" style="display: block; padding: 0 10px">                $scripts->add( 'admin-tags', "/wp-admin/js/tags$suffix.js", array( 'jquery', 'wp-ajax-response' ), false, 1 );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -669,12 +672,12 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $scripts->add( 'admin-gallery', "/wp-admin/js/gallery$suffix.js", array( 'jquery-ui-sortable' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $scripts->add( 'admin-widgets', "/wp-admin/js/widgets$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable' ), false, 1 );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $scripts->add( 'media-widgets', "/wp-admin/js/widgets/media-widgets$suffix.js", array( 'jquery', 'media-models', 'media-views' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $scripts->add( 'media-widgets', "/wp-admin/js/widgets/media-widgets$suffix.js", array( 'jquery', 'media-models', 'media-views', 'wp-api-request' ) );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $scripts->add_inline_script( 'media-widgets', 'wp.mediaWidgets.init();', 'after' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $scripts->add( 'media-audio-widget', "/wp-admin/js/widgets/media-audio-widget$suffix.js", array( 'media-widgets', 'media-audiovideo' ) );
</span><span class="cx" style="display: block; padding: 0 10px">                $scripts->add( 'media-image-widget', "/wp-admin/js/widgets/media-image-widget$suffix.js", array( 'media-widgets' ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $scripts->add( 'media-video-widget', "/wp-admin/js/widgets/media-video-widget$suffix.js", array( 'media-widgets', 'media-audiovideo' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $scripts->add( 'media-video-widget', "/wp-admin/js/widgets/media-video-widget$suffix.js", array( 'media-widgets', 'media-audiovideo', 'wp-api-request' ) );
</ins><span class="cx" style="display: block; padding: 0 10px">                 $scripts->add( 'text-widgets', "/wp-admin/js/widgets/text-widgets$suffix.js", array( 'jquery', 'backbone', 'editor', 'wp-util', 'wp-a11y' ) );
</span><span class="cx" style="display: block; padding: 0 10px">                $scripts->add_inline_script( 'text-widgets', 'wp.textWidgets.init();', 'after' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="trunktestsqunitindexhtml"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/qunit/index.html</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/qunit/index.html      2017-08-02 05:34:32 UTC (rev 41205)
+++ trunk/tests/qunit/index.html        2017-08-02 16:44:05 UTC (rev 41206)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -19,7 +19,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">                </script>
</span><span class="cx" style="display: block; padding: 0 10px">                <script>
</span><span class="cx" style="display: block; padding: 0 10px">                        var wpApiSettings = {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                'root': 'http://localhost/wp-json/'
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         root: 'http://localhost/wp-json/',
+                               nonce: 'not_a_real_nonce'
</ins><span class="cx" style="display: block; padding: 0 10px">                         };
</span><span class="cx" style="display: block; padding: 0 10px">                </script>
</span><span class="cx" style="display: block; padding: 0 10px">                <script src="../../src/wp-includes/js/wp-util.js"></script>
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -77,6 +78,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                <script src="../../src/wp-includes/js/customize-models.js"></script>
</span><span class="cx" style="display: block; padding: 0 10px">                <script src="../../src/wp-includes/js/shortcode.js"></script>
</span><span class="cx" style="display: block; padding: 0 10px">                <script src="../../src/wp-admin/js/customize-controls.js"></script>
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                <script src="../../src/wp-includes/js/api-request.js"></script>
</ins><span class="cx" style="display: block; padding: 0 10px">                 <script src="../../src/wp-includes/js/wp-api.js"></script>
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                <script type='text/javascript' src='../../src/wp-includes/js/jquery/ui/core.js'></script>
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -122,6 +124,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                <script src="wp-admin/js/customize-base.js"></script>
</span><span class="cx" style="display: block; padding: 0 10px">                <script src="wp-admin/js/customize-header.js"></script>
</span><span class="cx" style="display: block; padding: 0 10px">                <script src="wp-includes/js/shortcode.js"></script>
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                <script src="wp-includes/js/api-request.js"></script>
</ins><span class="cx" style="display: block; padding: 0 10px">                 <script src="wp-includes/js/wp-api.js"></script>
</span><span class="cx" style="display: block; padding: 0 10px">                <script src="wp-admin/js/customize-controls.js"></script>
</span><span class="cx" style="display: block; padding: 0 10px">                <script src="wp-admin/js/customize-controls-utils.js"></script>
</span></span></pre>
</div>
</div>

</body>
</html>