| @@ -324,16 +324,19 @@ | ||
| 324 | 324 | if ( '' === $request_uri ) { |
| 325 | 325 | return false; |
| 326 | 326 | } |
| 327 | 327 | |
| 328 | - $rest_prefix = trailingslashit( rest_get_url_prefix() ); | |
| 329 | - $is_mcp_target = false; | |
| 330 | - foreach ( $this->get_target_routes() as $route ) { | |
| 331 | - $target_path = $rest_prefix . ltrim( $route, '/' ); | |
| 332 | - if ( false !== strpos( $request_uri, $target_path ) ) { | |
| 333 | - $is_mcp_target = true; | |
| 334 | - break; | |
| 335 | - } | |
| 328 | + $request_path = wp_parse_url( $request_uri, PHP_URL_PATH ); | |
| 329 | + if ( ! is_string( $request_path ) ) { | |
| 330 | + return false; | |
| 331 | + } | |
| 332 | + | |
| 333 | + $rest_prefix = '/' . trailingslashit( rest_get_url_prefix() ); | |
| 334 | + $prefix_position = strpos( $request_path, $rest_prefix ); | |
| 335 | + $is_mcp_target = false; | |
| 336 | + if ( false !== $prefix_position ) { | |
| 337 | + $route = '/' . ltrim( substr( $request_path, $prefix_position + strlen( $rest_prefix ) ), '/' ); | |
| 338 | + $is_mcp_target = $this->route_matches_mcp_target( $route ); | |
| 336 | 339 | } |
| 337 | 340 | |
| 338 | 341 | return (bool) apply_filters( 'learn-press/mcp/api-keys/is-target-rest-request', $is_mcp_target, $request_uri, self::MCP_ROUTE ); |
| 339 | 342 | } |