是的,可以使用wp_insert_comment
钩要自动批准自定义帖子类型的评论,可以使用类似的方法:
//hook to do stuff with comments
add_action( \'wp_insert_comment\', \'approve_comment\', 99, 2 );
function approve_comment($comment_id, $comment_object) {
//get id of the post that was commented
$post_id = $comment_object->comment_post_ID;
//approve comment for "post" type
if( \'post\' == get_post_type( $post_id )) {
$retrieved_comment = get_comment( $comment_id, ARRAY_A );
//approve comment
$commentarr = $retrieved_comment;
$commentarr[\'comment_ID\'] = $comment_id;
$commentarr[\'comment_approved\'] = 1;
wp_update_comment( $commentarr );
}
}