Last active
July 17, 2023 15:39
-
-
Save BenSibley/7dda6549734aeea97d9e46fca239b417 to your computer and use it in GitHub Desktop.
Block REST API except for Independent Analytics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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