Changeset 42851
- Timestamp:
- 03/18/2018 05:03:20 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/js/wp-api.js
r42403 r42851 991 991 self = this; 992 992 993 options = options || {}; 994 beforeSend = options.beforeSend; 995 996 // If we have a localized nonce, pass that along with each sync. 997 if ( 'undefined' !== typeof wpApiSettings.nonce ) { 993 options = options || {}; 994 995 if ( _.isFunction( model.nonce ) && ! _.isUndefined( model.nonce() ) && ! _.isNull( model.nonce() ) ) { 996 beforeSend = options.beforeSend; 997 998 // Include the nonce with requests. 998 999 options.beforeSend = function( xhr ) { 999 xhr.setRequestHeader( 'X-WP-Nonce', wpApiSettings.nonce);1000 xhr.setRequestHeader( 'X-WP-Nonce', model.nonce() ); 1000 1001 1001 1002 if ( beforeSend ) { 1002 1003 return beforeSend.apply( self, arguments ); 1004 } 1005 }; 1006 1007 // Update the nonce when a new nonce is returned with the response. 1008 options.complete = function( xhr ) { 1009 var returnedNonce = xhr.getResponseHeader( 'X-WP-Nonce' ); 1010 1011 if ( returnedNonce && _.isFunction( model.nonce ) && model.nonce() !== returnedNonce ) { 1012 model.endpointModel.set( 'nonce', returnedNonce ); 1003 1013 } 1004 1014 }; … … 1406 1416 }, 1407 1417 1418 // Track nonces at the Endpoint level. 1419 nonce: function() { 1420 return routeModel.get( 'nonce' ); 1421 }, 1422 1423 endpointModel: routeModel, 1424 1408 1425 // Include a reference to the original class name. 1409 1426 name: collectionClassName, … … 1432 1449 return new loadingObjects.models[ modelClassName ]( attrs, options ); 1433 1450 }, 1451 1452 // Track nonces at the Endpoint level. 1453 nonce: function() { 1454 return routeModel.get( 'nonce' ); 1455 }, 1456 1457 endpointModel: routeModel, 1434 1458 1435 1459 // Include a reference to the original class name.
Note: See TracChangeset
for help on using the changeset viewer.