我正在尝试使用基本身份验证向 WordPress (4.7.0) 发表评论,如 documentation 中所述在WP REST API: Setting Up and Using Basic Authentication .
但是,我不断收到 401 错误。
{"code":"rest_comment_login_required","message":"Sorry, you must be logged in to comment.","data":{"status":401}}
我激活了基本身份验证插件,然后应该将此调用转换为经过身份验证的调用,对吗?
最佳答案
您需要在主题的 functions.php 文件中添加过滤器:
add_filter( 'rest_allow_anonymous_comments', function ( $allow_anonymous, $request ) {
// ... custom logic here ...
return true; // or false to prohibit anonymous comments via post
}, 10, 2 );
文档:https://developer.wordpress.org/reference/hooks/rest_allow_anonymous_comments/
关于wordpress - 401(rest_comment_login_required)在使用基本身份验证的 WordPress 4.7.0 上发表评论时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44499359/