diff --git a/lib/compat/wordpress-6.8/ajax-actions.php b/lib/compat/wordpress-6.8/ajax-actions.php index 1cba32cbf7729..24388b7f3b911 100644 --- a/lib/compat/wordpress-6.8/ajax-actions.php +++ b/lib/compat/wordpress-6.8/ajax-actions.php @@ -9,15 +9,14 @@ * Handles renewing the REST API nonce via AJAX. * * @since 5.3.0 - * @since 6.8.0 Returns an error if a renewed nonce isn't valid. + * @since 6.8.0 Returns error when session token is missing. */ function gutenberg_ajax_rest_nonce() { - $nonce = wp_create_nonce( 'wp_rest' ); - $result = wp_verify_nonce( $nonce, 'wp_rest' ); - if ( ! $result ) { + $token = wp_get_session_token(); + if ( empty( $token ) ) { wp_send_json_error( null, rest_authorization_required_code() ); } - exit( $result ); + exit( wp_create_nonce( 'wp_rest' ) ); } add_action( 'wp_ajax_rest-nonce', 'gutenberg_ajax_rest_nonce', 0 );