Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在我的WordPress站点中进行了审查之后,如何触发函数?_Php_Wordpress_Function_Triggers_Action - Fatal编程技术网

Php 在我的WordPress站点中进行了审查之后,如何触发函数?

Php 在我的WordPress站点中进行了审查之后,如何触发函数?,php,wordpress,function,triggers,action,Php,Wordpress,Function,Triggers,Action,我想为一个插件编写一些代码,在用户进行审查后,(wp_commentstable得到更新),它会触发一个函数,告诉它做些什么 我如何知道是否进行了新的审核,因为审核以注释的形式保存到数据库中,注释类型为“review”(审核) 谢谢大家! 创建新审阅时,您可以使用执行操作: /** * Performs an action after a review has been created. * * @param int $comment_ID * @param in

我想为一个插件编写一些代码,在用户进行审查后,(
wp_comments
table得到更新),它会触发一个函数,告诉它做些什么

我如何知道是否进行了新的审核,因为审核以注释的形式保存到数据库中,注释类型为“review”(审核)

谢谢大家!

创建新审阅时,您可以使用执行操作:

/**
 * 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
)
创建新审阅时,可以使用执行操作:

/**
 * 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
)

那要看情况。你用什么做评论?是Woocommerce吗?是的Woocommerce这要看情况而定。你用什么做评论?是Woocommerce吗?是的,Woocommerce感谢它是这样工作的,但我收到了2条警告。警告:非法字符串偏移量“comment\u type”和注意:未初始化字符串偏移量:0我没有看到任何PHP警告/错误消息以及我的答案中的代码,因此它一定是您这边的。如果您共享您的代码,我可能会帮助您调试它(但为此,您可能需要问一个新问题),但是我得到了两个警告。警告:非法字符串偏移量“comment_type”和注意:未初始化字符串偏移量:0我没有看到任何PHP警告/错误消息以及我的答案中的代码,因此它一定是您这边的。如果您共享您的代码,我可能会帮助您调试它(但为此,您可能需要问一个新问题)。