Restrict wordpress api
Omschrijving
// Disables WordPress Rest API for external requests
//————————————————–
function restrict_rest_api_to_localhost() {
$whitelist = array(‘127.0.0.1’, “::1”, “111.111.111.11”);
$whitelistplugins = array(‘contact-form-7’);
$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 | 1 |
| Particle Snippet in Boilerplate | 1 |
Relations
| Item | Type |
|---|
Pointing items
| Item | Type | Category | Tags |
|---|