1 回答
TA贡献1796条经验 获得超7个赞
创建新评论时,可以使用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
)
- 1 回答
- 0 关注
- 159 浏览
添加回答
举报