1

Returned error is:

Fatal error: Uncaught Error: Undefined constant "initCors" in functions.php (in second to last line marked below).

I do not get this error in my local environment, but when I push to our WP Engine host, I get the error. The function initCors is defined in the first line, I do not understand why this is happening. I have used this same function on other websites.

function initCors ( $value ) {
    header( 'Access-Control-Allow-Origin: ' . esc_url_raw( site_url() ) );
    header( 'Access-Control-Allow-Methods: GET' );
    header( 'Access-Control-Allow-Credentials: true' );
    return $value;
}
add_action( 'rest_api_init', function() {
    remove_filter( 'rest_pre_serve_request', 'rest_send_cors_headers' );
    add_filter( 'rest_pre_serve_request', initCors); //ERROR IN THIS LINE
}, 15 );

1 Answer 1

2

Try replacing your code with this one.

add_filter( 'rest_pre_serve_request', 'initCors');
Sign up to request clarification or add additional context in comments.

1 Comment

That was all it took, thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.