Disable rest api function
Omschrijving
/**
* Disables WordPress Rest API for external requests
* Change whitelist plugins when plugins need to use the REST API
*/
function restrict_rest_api_to_localhost() {
$whitelist = array(‘127.0.0.1’, “::1”);
$whitelistplugins = array(‘contact-form-7’, ‘redirection’);
$request = $_SERVER[‘REQUEST_URI’];
$die = true;
if ($request) {
foreach ($whitelistplugins as $plugin) {
if (!empty(strpos($request, $plugin))) {
$die = false;
}
}
}
if(!in_array($_SERVER[‘REMOTE_ADDR’], $whitelist) && $die){
die(‘REST API is disabled.’);
}
}
add_action( ‘rest_api_init’, ‘restrict_rest_api_to_localhost’, 1 );
Snippet
| Field | Value |
|---|---|
| Snippet Status | |
| Snippet Description | |
| Snippet Type Code | |
| Snippet URL | |
| Snippet Content | |
| Snippet Content CSS | |
| Snippet Content HTML | |
| Snippet Content JS | |
| Snippet Content PHP | |
| Particle Snippet in Software | |
| Particle Snippet in Boilerplate |
Relations
| Item | Type |
|---|
Pointing items
| Item | Type | Category | Tags |
|---|
| Categorie | Snippet |
| Tags | |
| URL | |
| Type | Snippet |
| Time | |
| Price |