wordpress - 401(rest_comment_login_required)在使用基本身份验证的 WordPress 4.7.0 上发表评论时

标签 wordpress authentication

我正在尝试使用基本身份验证向 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/

相关文章:

WordPress 删除空的 span 标签

php - CakePHP 根据用户名在登录时重定向

typescript - 如何从 NestJS 中的 GraphQL 解析器内部设置 session key ?

php - React前端服务器和PHP/Symfony后端服务器之间共享 session

javascript - 如何使用 Javascript 提交表单 OnKeyPress?

php - 如何覆盖 Laravel 5.6 的默认登录机制?

plugins - 某些推文的 WordPress 插件

php - Wordpress 元查询搜索

mysql - SQL 和 WPDB 的困难,特别是在 WHERE 子句中

mysql - SQL语法错误导致数据库错误