Skip to content

Instantly share code, notes, and snippets.

@artemsites
Last active April 15, 2024 10:06
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 artemsites/30a03ed3047e63ccb0db20fd781474e4 to your computer and use it in GitHub Desktop.
Save artemsites/30a03ed3047e63ccb0db20fd781474e4 to your computer and use it in GitHub Desktop.
<?php
/**
* !@note Проверка что запрос к api был с того же источника что и сам роут
*/
function validate_request_origin(/* WP_REST_Request $request */) {
$request_origin = isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : '';
$site_url = parse_url(get_site_url());
if (parse_url($request_origin, PHP_URL_HOST) === $site_url['host']) {
return true;
}
return new WP_Error('not_found', 'Not found', array('status' => 404));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment