猿问

在WordPress网站中进行审核后,如何触发功能?

我想为插件编写一些代码,该插件在用户进行检查后(wp_comments表已更新)会触发一个告诉它执行某项操作的函数。

我怎么知道是否进行了新的评论,因为评论是使用comment_type='review'作为评论保存到数据库的?


aluckdog
浏览 164回答 1
1回答

芜湖不芜

创建新评论时,可以使用comment_post操作挂钩执行操作:/** * Performs an action after a review has been created. * * @param   int         $comment_ID * @param   int|string  $comment_approved (1 if approved, 0 if not, 'spam' if spam) * @param   array       $commentdata */function show_message_function( $comment_ID, $comment_approved, $commentdata ) {    if ( 'review' == $commentdata['comment_type'] ) {        // A new review has been created, do something here.    }}add_action( 'comment_post', 'show_message_function', 10, 3 );该$commentdata阵列会是这个样子:Array(    [comment_post_ID] => 16    [comment_author] => John Doe    [comment_author_email] => me@example.com    [comment_author_url] =>     [comment_content] => My awesome review!    [comment_type] => review    [comment_parent] => 0    [user_ID] => 1    [user_id] => 1    [comment_author_IP] => ::1    [comment_agent] => Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0    [comment_date] => 2019-04-13 14:11:45    [comment_date_gmt] => 2019-04-13 14:11:45    [filtered] => 1    [comment_approved] => 1)
随时随地看视频慕课网APP
我要回答