it works only for the WooCommerce plugin, and cuts other third-party requests. You compare with the previous version of your plugin.
At the moment, when I send a request to my REST API, I get this {“code”:”woocommerce_rest_authentication_error”,”message”:”Consumer key is invalid.”,”data”:{“status”:401}}
that is old handler:
protected function is_request_to_rest_api() {
if ( empty( $_SERVER['REQUEST_URI'] ) ) {
return false;
}
$rest_prefix = trailingslashit( rest_get_url_prefix() );
// Check if our endpoint.
$woocommerce = ( false !== strpos( $_SERVER['REQUEST_URI'], $rest_prefix . 'wc/' ) ); // @codingStandardsIgnoreLine
// Allow third party plugins use our authentication methods.
$third_party = ( false !== strpos( $_SERVER['REQUEST_URI'], $rest_prefix . 'wc-' ) ); // @codingStandardsIgnoreLine
return apply_filters( 'woocommerce_rest_is_request_to_rest_api', $woocommerce || $third_party );
}
that is new version:
public function is_rest_api_request() {
if ( empty( $_SERVER['REQUEST_URI'] ) ) {
return false;
}
$rest_prefix = trailingslashit( rest_get_url_prefix() );
$is_rest_api_request = ( false !== strpos( $_SERVER['REQUEST_URI'], $rest_prefix ) ); // phpcs:disable WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
return apply_filters( 'woocommerce_is_rest_api_request', $is_rest_api_request );
}
In other words, you check for $rest_prefix which is equal to wp-json and all requests from third-party plug-ins go to ashes. Maybe I don’t understand something, but do you really think you can afford it?