WC_WCCOM_Site::is_request_to_wccom_site_rest_api
Check if this is a request to WCCOM Site REST API.
Before WordPress parses the request only the URL path is checked. Requests carrying rest_route return false until then, and authentication_fallback() authenticates them once the route is resolved.
Method of the class: WC_WCCOM_Site{}
No Hooks.
Returns
bool.
Usage
$result = WC_WCCOM_Site::is_request_to_wccom_site_rest_api();
Changelog
| Since 3.7.0 | Introduced. |
WC_WCCOM_Site::is_request_to_wccom_site_rest_api() WC WCCOM Site::is request to wccom site rest api code WC 11.3.0
protected static function is_request_to_wccom_site_rest_api() {
global $wp;
// Once WordPress is dispatching REST, the route it resolved is the one that counts.
if ( wp_is_rest_endpoint() ) {
$route = $wp instanceof WP ? ( $wp->query_vars['rest_route'] ?? null ) : null;
return is_string( $route ) && str_starts_with( ltrim( $route, '/' ), 'wccom-site/' );
}
// Before that, a rest_route in the query or body can override the path, so leave those requests to authentication_fallback().
if ( isset( $_REQUEST['rest_route'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
return false;
}
$path = wp_parse_url( wp_unslash( $_SERVER['REQUEST_URI'] ?? '' ), PHP_URL_PATH ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Only compared against the REST prefix.
return is_string( $path ) && str_contains( $path, trailingslashit( rest_get_url_prefix() ) . 'wccom-site/' );
}