Skip to content

Instantly share code, notes, and snippets.

@BenSibley
Last active July 17, 2023 15:39
Show Gist options
  • Save BenSibley/7dda6549734aeea97d9e46fca239b417 to your computer and use it in GitHub Desktop.
Save BenSibley/7dda6549734aeea97d9e46fca239b417 to your computer and use it in GitHub Desktop.
Block REST API except for Independent Analytics
function block_rest_api_except_ia( $access ) {
if (!is_user_logged_in() && $_SERVER['REQUEST_URI'] != '/wp-json/iawp/search') {
return new WP_Error( 'rest_disabled', __('The WordPress REST API has been disabled.'), array( 'status' => rest_authorization_required_code()));
}
return $access;
}
add_filter( 'rest_authentication_errors', 'block_rest_api_except_ia );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment