2

Wordpress REST API "rest_authentication_errors" doesn't work external queries?

I was using following experimental codes for experimental purposes.

add_filter('rest_authentication_errors', 'auth');
function auth() { return true; }

add_action( 'rest_api_init', 'cors', 15 );
function cors() {
    add_filter( 'rest_pre_serve_request', function( $value )
    {
        header( 'Access-Control-Allow-Origin: *' );
        return $value;
    });
}

Then I realized that if we made a request between two separate servers, the API's response failed. However, we have set all requests to be "correct" with the "rest_authentication_errors" filter and have accepted all connections from "*".

  • If we send a "POST" request from "a.com" to "b.com", it says "authorization failed".
  • But if we make a request from "a.com" to "a.com", the query works.
  • did you figure it out? – Jason Nov 19 at 17:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.