第三个参数,$commentdata
可用于获取发表评论的帖子的ID:
function wpse211367_comment( $comment_ID, $comment_approved, $commentdata ) {
// The id for the post that the comment is related to is available
// in the $commentdata array:
$comment_post_id = $commentdata[\'comment_post_ID\'];
}
add_action( \'comment_post\', \'wpse211367_comment\', 10, 3 );
The
$commentdata
阵列:
Array
(
[comment_post_ID] => 149
[comment_author] => dave
[comment_author_email] => [email protected]
[comment_author_url] =>
[comment_content] => All work and no play makes Dave a dull boy.
[comment_type] =>
[comment_parent] => 0
[user_ID] => 1
[user_id] => 1
[comment_author_IP] => ::1
[comment_agent] => Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36
[comment_date] => 2016-09-23 03:13:40
[comment_date_gmt] => 2016-09-23 03:13:40
[filtered] => 1
[comment_approved] => 1
)