如何在我的wordpress网站上进行审核后触发功能?

问题描述 投票:0回答:1

我想为插件编写一些代码,在用户进行审核后(wp_comments表更新),它会触发一个告诉它做某事的函数。我如何知道是否进行了新的审核,因为评论作为带有comment_type“评论”的评论保存在数据库中?

谢谢!

php wordpress function triggers action
1个回答
1
投票

您可以使用comment_post action hook在创建新评论时执行操作:

/**
 * 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] => [email protected]
    [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
)
© www.soinside.com 2019 - 2024. All rights reserved.