add_action('wp_head', function () {
	?>
	<script>
	(function () {
	  // Block only Mixpanel Feature Flags request
	  var blockRe = /^https:\/\/api-eu\.mixpanel\.com\/flags\//;

	  // Patch fetch
	  if (window.fetch) {
		var _fetch = window.fetch;
		window.fetch = function (input, init) {
		  try {
			var url = (typeof input === 'string') ? input : (input && input.url);
			if (url && blockRe.test(url)) {
			  // Return a fast empty JSON response, so scripts don't wait / error
			  return Promise.resolve(new Response("{}", {
				status: 200,
				headers: { "Content-Type": "application/json" }
			  }));
			}
		  } catch (e) {}
		  return _fetch.apply(this, arguments);
		};
	  }

	  // Patch XHR too (for cases where Mixpanel uses XHR)
	  var _open = XMLHttpRequest.prototype.open;
	  var _send = XMLHttpRequest.prototype.send;

	  XMLHttpRequest.prototype.open = function (method, url) {
		this.__mp_blocked = (typeof url === 'string' && blockRe.test(url));
		return _open.apply(this, arguments);
	  };

	  XMLHttpRequest.prototype.send = function () {
		if (this.__mp_blocked) {
		  try {
			this.readyState = 4;
			this.status = 200;
			this.responseText = "{}";
			if (typeof this.onreadystatechange === "function") this.onreadystatechange();
			if (typeof this.onload === "function") this.onload();
		  } catch (e) {}
		  return;
		}
		return _send.apply(this, arguments);
	  };
	})();
	</script>
	<?php
}, 1);
