admin管理员组文章数量:1129103
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 protected]",
"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.
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 protected]",
"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.
Share Improve this question edited Apr 13, 2017 at 12:37 CommunityBot 1 asked Feb 12, 2017 at 19:43 jackreichertjackreichert 4134 silver badges10 bronze badges1 Answer
Reset to default 0I 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.
本文标签: Trouble Commenting via the WP REST API using nonces
版权声明:本文标题:Trouble Commenting via the WP REST API using nonces 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736727647a1949813.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论