Action hook 'comment_post'

in WP Core File wp-includes/comment.php at line 2380

View Source

comment_post

Action Hook
Description
Fires immediately after a comment is inserted into the database.

Hook Information

File Location wp-includes/comment.php View on GitHub
Hook Type Action
Line Number 2380

Hook Parameters

Type Name Description
int $comment_id The comment ID.
int|string $comment_approved 1 if the comment is approved, 0 if not, 'spam' if spam.
array $commentdata Comment data.

Usage Examples

Basic Usage
<?php
// Hook into comment_post
add_action('comment_post', 'my_custom_function', 10, 3);

function my_custom_function($comment_id, $comment_approved, $commentdata) {
    // Your custom code here
}

Source Code Context

wp-includes/comment.php:2380 - How this hook is used in WordPress core
<?php
2375  	 *
2376  	 * @param int        $comment_id       The comment ID.
2377  	 * @param int|string $comment_approved 1 if the comment is approved, 0 if not, 'spam' if spam.
2378  	 * @param array      $commentdata      Comment data.
2379  	 */
2380  	do_action( 'comment_post', $comment_id, $commentdata['comment_approved'], $commentdata );
2381  
2382  	return $comment_id;
2383  }
2384  
2385  /**

PHP Documentation

<?php
/**
	 * Fires immediately after a comment is inserted into the database.
	 *
	 * @since 1.2.0
	 * @since 4.5.0 The `$commentdata` parameter was added.
	 *
	 * @param int        $comment_id       The comment ID.
	 * @param int|string $comment_approved 1 if the comment is approved, 0 if not, 'spam' if spam.
	 * @param array      $commentdata      Comment data.
	 */
Quick Info
  • Hook Type: Action
  • Parameters: 3
  • File: wp-includes/comment.php
Related Hooks

Related hooks will be displayed here in future updates.