• Resolved djmiller78

    (@djmiller78)


    0

    I had a working post route with nonce header in wordpress using npm. Now it only works if I comment out the nonce header. With nonce header, console returns message “(routename) not defined”. Route is recognized with nonce and WP_REST_SERVER::READABLE method, but not with POST method.

    JS side:

        var updateLikes = new XMLHttpRequest(); 
    
        updateLikes.setRequestHeader('X-WP-Nonce', SB.nonce);
    

    php side:

        add_action('rest_api_init', 'sbLikeRoutes');
    
        function sbLikeRoutes(){
           register_rest_route('SB/v1', 'manageLike' , array(
           // 'methods' => WP_REST_SERVER::READABLE,
           'methods' => 'POST',
           'callback' => 'SBPostLike'
         ));
        }
  • The topic ‘Nonce header stopped working wordpress post rest api’ is closed to new replies.