Skip to content

Instantly share code, notes, and snippets.



Created Mar 18, 2019
What would you like to do?
WordPress Snippets
* Disables WordPress Rest API for external requests
function restrict_rest_api_to_localhost() {
$whitelist = array('', "::1");
if(!in_array($_SERVER['REMOTE_ADDR'], $whitelist)){
die('REST API is disabled.');
add_action( 'rest_api_init', 'restrict_rest_api_to_localhost', 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment