Last active
April 15, 2024 10:06
-
-
Save artemsites/30a03ed3047e63ccb0db20fd781474e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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