WordPress REST API匿名评论
2021-02-25
REST API默认关闭匿名评论:
$allow_anonymous = apply_filters( 'rest_allow_anonymous_comments', false, $request );
if ( ! $allow_anonymous ) {
return new WP_Error(
'rest_comment_login_required',
__( 'Sorry, you must be logged in to comment.' ),
array( 'status' => 401 )
);
}
打开匿名评论,可在主题functions.php添加钩子:
/**
* rest-api 匿名评论
*/
function filter_rest_allow_anonymous_comments() {
// 最好限制入口,减少垃圾评论,如:
// return $_POST['skey'] == 'skjfakj1j102';
return true;
}
add_filter('rest_allow_anonymous_comments','filter_rest_allow_anonymous_comments');