Have a Question?
To get WordPress comment information
Use the ‘comment_post”hook in your plugin, an example:
add_action( 'comment_post', 'my_comment_post_callback', 10, 2 );
function my_comment_post_callback( $comment_ID, $comment_approved ) {
// Do something with the comment data
}
To get the author name and metadata about a wordpress comments the ‘get_comment’ hook to get the author name and metadata about a WordPress comment and change it, here is an example:
add_filter( 'wp_get_current_commenter', 'my_commenter_name_callback' );
function my_commenter_name_callback( $commenter ) {
// Change the display name of the author
$commenter['comment_author'] = 'New Display Name';
return $commenter;
}
The following is a list of comment hooks available to WordPress plugins and themes, or additional hooks that will support working with comments.
- comment_form
- add_metabox
- update_comment_meta
- get_comment_meta
- wp_list_comments
- add_comment_meta
- get_comment_meta
- comment_text
- check_comment
- comment_post
- edit_comment
- transition_comment_status
- comment_form_before
- comment_form_top
- comment_from before_fields
- comment_form_after_fields
- comment_form+after
For additional visualization go to: https://wordpress.stackexchange.com/questions/39028/hook-filter-before-and-after-comments
Additional reference for all hooks: The WordPress Hooks Database.