REST API blocked for anyone not logged
-
Hello,
For security reasons I have blocked access to the REST API for all users who are not logged in.
This seems to be a problem for WP Statistics, even access to the REST API is not included in the requirements: https://wp-statistics.com/resources/wp-statistics-requirements/
I’ve tried whitelisting my server IP, but it doesn’t work. Does anyone know how to do this?
Below is the script used to block access to the REST API:
<?php
// disable REST API (wp-json) to external requests / 17.6.2024 ok for WP Statistics
add_action( 'rest_api_init', 'restrict_rest_api_to_localhost', 0 );
function restrict_rest_api_to_localhost() {
if(!is_admin()) {
$whitelist = [
'127.0.0.1',
"::1",
"192.1.1.1", // my server IP
];
$message = "REST API is disabled.";
if( ! in_array($_SERVER['REMOTE_ADDR'], $whitelist ) ) {
die( $message );
}
}
}
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.