Skip to content

Instantly share code, notes, and snippets.

@sicaboy
Created March 18, 2019 04:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sicaboy/fecae1619fe47b80997d44143097f178 to your computer and use it in GitHub Desktop.
Save sicaboy/fecae1619fe47b80997d44143097f178 to your computer and use it in GitHub Desktop.
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