Created
March 18, 2019 04:24
-
-
Save sicaboy/fecae1619fe47b80997d44143097f178 to your computer and use it in GitHub Desktop.
WordPress Snippets
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
<?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