查看函数wp_delete_comment()
. 它会在删除注释之前触发操作:
/**
* Fires immediately before a comment is deleted from the database.
*
* @since 1.2.0
*
* @param int $comment_id The comment ID.
*/
do_action( \'delete_comment\', $comment_id );
…和删除后的一个:
/**
* Fires immediately after a comment is deleted from the database.
*
* @since 2.9.0
*
* @param int $comment_id The comment ID.
*/
do_action( \'deleted_comment\', $comment_id );
因此,您可以将回调绑定到:
add_action( \'deleted_comment\', function( $comment_id ) {
delete_comment_meta( $comment_id, \'your_meta_key\' );
} );