WordPress Snippets
<?php | |
/** | |
* Disables WordPress Rest API for external requests | |
*/ | |
function restrict_rest_api_to_localhost() { | |
$whitelist = array('127.0.0.1', "::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