Changeset 49716
- Timestamp:
- 12/01/2020 03:42:31 AM (4 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/js/_enqueues/admin/application-passwords.js
r49549 r49716 48 48 49 49 wp.apiRequest( { 50 path: '/wp/v2/users/' + userId + '/application-passwords ',50 path: '/wp/v2/users/' + userId + '/application-passwords?_locale=user', 51 51 method: 'POST', 52 52 data: request … … 95 95 96 96 wp.apiRequest( { 97 path: '/wp/v2/users/' + userId + '/application-passwords/' + uuid ,97 path: '/wp/v2/users/' + userId + '/application-passwords/' + uuid + '?_locale=user', 98 98 method: 'DELETE' 99 99 } ).always( function() { … … 124 124 125 125 wp.apiRequest( { 126 path: '/wp/v2/users/' + userId + '/application-passwords ',126 path: '/wp/v2/users/' + userId + '/application-passwords?_locale=user', 127 127 method: 'DELETE' 128 128 } ).always( function() { -
trunk/src/js/_enqueues/admin/auth-app.js
r49562 r49716 55 55 56 56 wp.apiRequest( { 57 path: '/wp/v2/users/me/application-passwords ',57 path: '/wp/v2/users/me/application-passwords?_locale=user', 58 58 method: 'POST', 59 59 data: request -
trunk/src/js/_enqueues/admin/site-health.js
r49537 r49716 272 272 if ( 'undefined' !== typeof( this.has_rest ) && this.has_rest ) { 273 273 wp.apiRequest( { 274 url: this.test,274 url: wp.url.addQueryArgs( this.test, { _locale: 'user' } ), 275 275 headers: this.headers 276 276 } ) -
trunk/src/js/_enqueues/wp/api-request.js
r49133 r49716 11 11 * @since 4.9.0 12 12 * @since 5.6.0 Added overriding of the "PUT" and "DELETE" methods with "POST". 13 * Added an "application/json" Accept header to all requests. 13 14 * @output wp-includes/js/api-request.js 14 15 */ … … 27 28 var method = options.method; 28 29 var namespaceTrimmed, endpointTrimmed, apiRoot; 29 var headers, addNonceHeader, headerName;30 var headers, addNonceHeader, addAcceptHeader, headerName; 30 31 31 32 if ( … … 56 57 // If ?_wpnonce=... is present, no need to add a nonce header. 57 58 addNonceHeader = ! ( options.data && options.data._wpnonce ); 59 addAcceptHeader = true; 58 60 59 61 headers = options.headers || {}; 60 62 61 // If an 'X-WP-Nonce' header (or any case-insensitive variation 62 // thereof) was specified, no need to add a nonce header. 63 if ( addNonceHeader ) { 64 for ( headerName in headers ) { 65 if ( headers.hasOwnProperty( headerName ) ) { 66 if ( headerName.toLowerCase() === 'x-wp-nonce' ) { 67 addNonceHeader = false; 68 break; 69 } 70 } 63 for ( headerName in headers ) { 64 if ( ! headers.hasOwnProperty( headerName ) ) { 65 continue; 66 } 67 68 // If an 'X-WP-Nonce' or 'Accept' header (or any case-insensitive variation 69 // thereof) was specified, no need to add the header again. 70 switch ( headerName.toLowerCase() ) { 71 case 'x-wp-nonce': 72 addNonceHeader = false; 73 break; 74 case 'accept': 75 addAcceptHeader = false; 76 break; 71 77 } 72 78 } … … 76 82 headers = $.extend( { 77 83 'X-WP-Nonce': wpApiSettings.nonce 84 }, headers ); 85 } 86 87 if ( addAcceptHeader ) { 88 headers = $.extend( { 89 'Accept': 'application/json, */*;q=0.1' 78 90 }, headers ); 79 91 } -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php
r49334 r49716 172 172 */ 173 173 public function test_background_updates() { 174 $this->load_admin_textdomain(); 174 175 return $this->site_health->get_test_background_updates(); 175 176 } … … 183 184 */ 184 185 public function test_dotorg_communication() { 186 $this->load_admin_textdomain(); 185 187 return $this->site_health->get_test_dotorg_communication(); 186 188 } … … 194 196 */ 195 197 public function test_loopback_requests() { 198 $this->load_admin_textdomain(); 196 199 return $this->site_health->get_test_loopback_requests(); 197 200 } … … 205 208 */ 206 209 public function test_authorization_header() { 210 $this->load_admin_textdomain(); 207 211 return $this->site_health->get_test_authorization_header(); 208 212 } … … 219 223 require_once ABSPATH . 'wp-admin/includes/class-wp-debug-data.php'; 220 224 } 225 226 $this->load_admin_textdomain(); 221 227 222 228 $sizes_data = WP_Debug_Data::get_sizes(); … … 255 261 256 262 return $all_sizes; 263 } 264 265 /** 266 * Loads the admin textdomain for Site Health tests. 267 * 268 * The {@see WP_Site_Health} class is defined in WP-Admin, while the REST API operates in a front-end context. 269 * This means that the translations for Site Health won't be loaded by default in {@see load_default_textdomain()}. 270 * 271 * @since 5.6.0 272 */ 273 protected function load_admin_textdomain() { 274 // Accounts for inner REST API requests in the admin. 275 if ( ! is_admin() ) { 276 $locale = determine_locale(); 277 load_textdomain( 'default', WP_LANG_DIR . "/admin-$locale.mo" ); 278 } 257 279 } 258 280 -
trunk/src/wp-includes/script-loader.php
r49649 r49716 1287 1287 $scripts->set_translations( 'plugin-install' ); 1288 1288 1289 $scripts->add( 'site-health', "/wp-admin/js/site-health$suffix.js", array( 'clipboard', 'jquery', 'wp-util', 'wp-a11y', 'wp-api-request' ), false, 1 );1289 $scripts->add( 'site-health', "/wp-admin/js/site-health$suffix.js", array( 'clipboard', 'jquery', 'wp-util', 'wp-a11y', 'wp-api-request', 'wp-url' ), false, 1 ); 1290 1290 $scripts->set_translations( 'site-health' ); 1291 1291 -
trunk/tests/qunit/wp-includes/js/api-request.js
r46586 r49716 3 3 var originalRootUrl = window.wpApiSettings.root; 4 4 5 var nonceHeader = { 'X-WP-Nonce': 'not_a_real_nonce' }; 5 var expectedHeaders = { 6 'X-WP-Nonce': 'not_a_real_nonce', 7 'Accept': 'application/json, */*;q=0.1' 8 }; 6 9 7 10 QUnit.module( 'wp-api-request', { … … 33 36 headers: { 34 37 'X-WP-Nonce': 'not_a_real_nonce', 38 'Accept': 'application/json, */*;q=0.1', 35 39 'Header-Name': 'value' 36 40 }, … … 65 69 66 70 assert.notStrictEqual( settings, settingsOriginal ); 67 assert.strictEqual( settings.headers, settingsOriginal.headers ); 71 72 var expected = { 73 Accept: 'application/json, */*;q=0.1' 74 }; 75 expected[ headerName ] = nonceHeader[ headerName ]; 68 76 69 77 assert.deepEqual( settings, { 70 78 url: 'aaaa', 71 headers: nonceHeader79 headers: expected 72 80 } ); 73 81 } ); … … 88 96 assert.deepEqual( settings, { 89 97 url: 'aaaa', 90 headers: {}, 98 headers: { 99 'Accept': 'application/json, */*;q=0.1' 100 }, 91 101 data: { 92 102 _wpnonce: 'definitely_not_a_real_nonce' 93 103 } 94 104 } ); 105 } ); 106 107 QUnit.test( 'does not add accept header if already present', function( assert ) { 108 var settingsOriginal = { 109 url: 'aaaa', 110 headers: { 111 'Accept': 'text/xml' 112 } 113 }; 114 115 var settings = wp.apiRequest.buildAjaxOptions( settingsOriginal ); 116 117 assert.strictEqual( settingsOriginal.headers.Accept, settings.headers.Accept ); 95 118 } ); 96 119 … … 101 124 } ), { 102 125 url: 'http://localhost/wp-json/wp/v2/posts', 103 headers: nonceHeader126 headers: expectedHeaders 104 127 } ); 105 128 } ); … … 111 134 } ), { 112 135 url: 'http://localhost/wp-json/wp/v2/posts', 113 headers: nonceHeader136 headers: expectedHeaders 114 137 } ); 115 138 } ); … … 121 144 } ), { 122 145 url: 'http://localhost/wp-json/wp/v2', 123 headers: nonceHeader146 headers: expectedHeaders 124 147 } ); 125 148 } ); … … 131 154 } ), { 132 155 url: 'http://localhost/wp-json/', 133 headers: nonceHeader156 headers: expectedHeaders 134 157 } ); 135 158 } ); … … 144 167 } ), { 145 168 url: 'http://localhost/index.php?rest_route=/wp/v2/posts&orderby=title', 146 headers: nonceHeader169 headers: expectedHeaders 147 170 } ); 148 171 } … … 158 181 } ), { 159 182 url: 'http://localhost/index.php?rest_route=/', 160 headers: nonceHeader183 headers: expectedHeaders 161 184 } ); 162 185 }
Note: See TracChangeset
for help on using the changeset viewer.