Block RESTAPI access to your WordPress site

add_filter('rest_api_init', 'rest_only_for_authorized_users', 99);

function rest_only_for_authorized_users($wp_rest_server)
{
  if (!is_user_logged_in()) {
    wp_die('REST API is blocked', 'Access denied', 403);
  }
}

Leave a comment

Your email address will not be published. Required fields are marked *