Skip to content

v4.3.0: CORS overrides globally or with filter

Latest

Choose a tag to compare

@craigrileyuk craigrileyuk released this 28 Mar 14:55
4c7eac3
  • Feature: CORS configuration can now be passed to the RestApi constructor which will activate for your endpoints.
new RestApi([
    'namespace' => 'EvoMark\\OurProject\\RestApi\\',
    'version' => 1,
    'directory' => $environment->rootPath . 'src/RestApi',
    'base_url' => 'evomark',
    'cors' => [
        'allow_origin' => '*',
        'allow_headers' => ['X-My-Custom-Header'],
        'expose_headers' => ['Something'],
        'allow_methods' => ['GET', 'OPTIONS'],
        'allow_credentials' => false
    ]
]);

The following filters are also available: evo_wp_rest_allow_origin, evo_wp_rest_allow_methods and evo_wp_rest_allow_credentials. All receive the response, request and server as additional arguments.