FacetWP – Pass authentication into REST API requests

<?php

/*
  Please note that caching may interfere with the NONCE,
  causing ajax requests to fail. Please DISABLE CACHING for facet pages,
  or set the cache expiration to < 12 hours!
*/

add_action( 'wp_footer', function() {
?>
<script>
(function($) {
  $(function() {
    wp.hooks.addFilter('facetwp/ajax_settings', function(settings) {
      settings.headers = {
        'X-WP-Nonce': FWP_JSON.nonce
      };
      return settings;
    });
  });
})(jQuery);
</script>
<?php
}, 100 );