diff --git a/src/wp-includes/js/wp-api.js b/src/wp-includes/js/wp-api.js index fc9750fa70..9ac12fe889 100644 --- a/src/wp-includes/js/wp-api.js +++ b/src/wp-includes/js/wp-api.js @@ -848,7 +848,7 @@ model.unset( 'slug' ); } - if ( _.isFunction( model.nonce ) && ! _.isUndefined( model.nonce() ) && ! _.isNull( model.nonce() ) ) { + if ( _.isFunction( model.nonce ) && ! _.isEmpty( model.nonce() ) ) { beforeSend = options.beforeSend; // @todo enable option for jsonp endpoints @@ -992,7 +992,7 @@ options = options || {}; - if ( _.isFunction( model.nonce ) && ! _.isUndefined( model.nonce() ) && ! _.isNull( model.nonce() ) ) { + if ( _.isFunction( model.nonce ) && ! _.isEmpty( model.nonce() ) ) { beforeSend = options.beforeSend; // Include the nonce with requests. @@ -1490,6 +1490,7 @@ * Initialize the wp-api, optionally passing the API root. * * @param {object} [args] + * @param {string} [args.nonce] The nonce. Optional, defaults to wpApiSettings.nonce. * @param {string} [args.apiRoot] The api root. Optional, defaults to wpApiSettings.root. * @param {string} [args.versionString] The version string. Optional, defaults to wpApiSettings.root. * @param {object} [args.schema] The schema. Optional, will be fetched from API if not provided. @@ -1498,7 +1499,7 @@ var endpoint, attributes = {}, deferred, promise; args = args || {}; - attributes.nonce = args.nonce || wpApiSettings.nonce || ''; + attributes.nonce = _.isString( args.nonce ) ? args.nonce : ( wpApiSettings.nonce || '' ); attributes.apiRoot = args.apiRoot || wpApiSettings.root || '/wp-json'; attributes.versionString = args.versionString || wpApiSettings.versionString || 'wp/v2/'; attributes.schema = args.schema || null;