trash_comment
Action HookDescription
Fires immediately before a comment is sent to the Trash.Hook Information
File Location |
wp-includes/comment.php
View on GitHub
|
Hook Type | Action |
Line Number | 1594 |
Hook Parameters
Type | Name | Description |
---|---|---|
string
|
$comment_id
|
The comment ID as a numeric string. |
WP_Comment
|
$comment
|
The comment to be trashed. |
Usage Examples
Basic Usage
<?php
// Hook into trash_comment
add_action('trash_comment', 'my_custom_function', 10, 2);
function my_custom_function($comment_id, $comment) {
// Your custom code here
}
Source Code Context
wp-includes/comment.php:1594
- How this hook is used in WordPress core
<?php
1589 * @since 4.9.0 Added the `$comment` parameter.
1590 *
1591 * @param string $comment_id The comment ID as a numeric string.
1592 * @param WP_Comment $comment The comment to be trashed.
1593 */
1594 do_action( 'trash_comment', $comment->comment_ID, $comment );
1595
1596 if ( wp_set_comment_status( $comment, 'trash' ) ) {
1597 delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_status' );
1598 delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_time' );
1599 add_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', $comment->comment_approved );
PHP Documentation
<?php
/**
* Fires immediately before a comment is sent to the Trash.
*
* @since 2.9.0
* @since 4.9.0 Added the `$comment` parameter.
*
* @param string $comment_id The comment ID as a numeric string.
* @param WP_Comment $comment The comment to be trashed.
*/
Quick Info
- Hook Type: Action
- Parameters: 2
- File: wp-includes/comment.php
Related Hooks
Related hooks will be displayed here in future updates.