diff --git src/wp-includes/js/wp-api.js src/wp-includes/js/wp-api.js
index 0f5135f3c9..a8903eba0b 100644
|
|
|
816 | 816 | // Initialize the model. |
817 | 817 | initialize: function() { |
818 | 818 | |
| 819 | // Limit recursion in sync. |
| 820 | this.maxRecursion = 1; |
| 821 | |
819 | 822 | /** |
820 | 823 | * Types that don't support trashing require passing ?force=true to delete. |
821 | 824 | * |
… |
… |
|
864 | 867 | }; |
865 | 868 | |
866 | 869 | // Update the nonce when a new nonce is returned with the response. |
867 | | options.complete = function( xhr ) { |
| 870 | options.complete = _.bind( function( xhr ) { |
868 | 871 | var returnedNonce = xhr.getResponseHeader( 'X-WP-Nonce' ); |
869 | 872 | |
870 | 873 | if ( returnedNonce && _.isFunction( model.nonce ) && model.nonce() !== returnedNonce ) { |
871 | 874 | model.endpointModel.set( 'nonce', returnedNonce ); |
| 875 | if ( 'rest_cookie_invalid_nonce' === xhr.responseJSON.code && this.maxRecursion-- > 0 ) { |
| 876 | this.sync( method, model, options ); |
| 877 | } else { |
| 878 | this.maxRecursion = 1; |
| 879 | } |
872 | 880 | } |
873 | | }; |
| 881 | }, this ); |
| 882 | |
| 883 | |
874 | 884 | } |
875 | 885 | |
876 | 886 | // Add '?force=true' to use delete method when required. |
diff --git src/wp-includes/rest-api.php src/wp-includes/rest-api.php
index 82d856a063..016ac07f1b 100644
|
|
function rest_cookie_check_errors( $result ) { |
780 | 780 | // Check the nonce. |
781 | 781 | $result = wp_verify_nonce( $nonce, 'wp_rest' ); |
782 | 782 | |
| 783 | if ( is_user_logged_in() ) { |
| 784 | |
| 785 | // Send a refreshed nonce in header. |
| 786 | rest_get_server()->send_header( 'X-WP-Nonce', wp_create_nonce( 'wp_rest' ) ); |
| 787 | } |
| 788 | |
783 | 789 | if ( ! $result ) { |
784 | 790 | return new WP_Error( 'rest_cookie_invalid_nonce', __( 'Cookie nonce is invalid' ), array( 'status' => 403 ) ); |
785 | 791 | } |
786 | 792 | |
787 | | // Send a refreshed nonce in header. |
788 | | rest_get_server()->send_header( 'X-WP-Nonce', wp_create_nonce( 'wp_rest' ) ); |
789 | 793 | |
790 | 794 | return true; |
791 | 795 | } |