0

I'm trying to post a comment via the WP REST API. Here is my request:

axios({
    method: 'post',
    url: `${WP_API_ENDPOINT}/comments`,
    headers: {'X-WP-Nonce': wpRestSettings.nonce},
    data: {
        "post": 8911,
        "author_name": "Mr. Author",
        "author_email": "email@example.com",
        "content": "A new comment."
    }
})

I've also tried adding the nonce in the data instead under the value _wpnonce per the spec.

I saw one answer suggest adding this filter: add_filter( 'filter_rest_allow_anonymous_comments', '__return_true' );

I keep getting the same 401 response. If I post using basic auth, it works, nonces aren't.

1 Answer 1

0

I solved it.

add_filter( 'filter_rest_allow_anonymous_comments', '__return_true' );

should be:

add_filter( 'rest_allow_anonymous_comments', '__return_true' );

I found it by looking for the filter itself and saw that it was different than in the original answer.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.