comment_post钩子不触发?

时间:2019-08-08 21:00:56

标签: php wordpress

我正在使用Reviews扩展WP Job Manager,并且试图通过REST API远程发布评论。评论实际上是WP数据库中的评论。评论扩展程序允许您使用参数star-rating-X向评论添加星级,其中X是评分类别列表中的索引。

我无法弄清楚如何通过REST API进行身份验证,因此我尝试使用JSON REST API插件的submit_comment端点,但是看起来它没有通过任何自定义参数,因此扩展名挂钩仅接收作者,内容,post_id等,但不接收star-rating-0参数。

在插件中,看起来像在comment_post钩中进行了检查之后,在pre_comment_approved钩中获得了星级:

        add_filter( 'pre_comment_approved', array( $this, 'pre_save_review' ), 10, 2 );

        // Allow blank comment content (set in settings).
        add_action( 'init', array( $this, 'allow_blank_comment' ) );

        // Save review as comment meta.
        add_action( 'comment_post', array( $this, 'save_comment_review' ), 10, 3 );

我已经构建了一个自定义的REST API端点,该端点可以自己调用wp_insert_comment,但似乎并没有激活save_comment_review函数。它可以保存评论,但不包含星星或其他任何内容。

这是我的自定义终结点处理程序,以及我正在发送的请求。

example.com/wp-json/api/v2/reviews/
?post_id=15353
&content=Hippy
&username=testuser
&email=this1@that.butt
&rating=2

function create_review($param) {
  $req = array();
  $req['comment_post_ID'] = $param['post_id'];
  $req['comment_author'] = $param['username'];
  $req['comment_author_email'] = $param['email'];
  $req['comment_content'] = $param['content'];
  $req['star-rating-0'] = $param['rating'];
  return wp_insert_comment($req);
}

为什么没有触发save_comment_review函数?我在这里可以做什么?

0 个答案:

没有答案
相关问题