Simply check if the comment has a parent before decrementing points. Reading the Codex entry for the get_comment()
function, you’ll note that in the manner you use the function you will be returned an object containing keys that correspond to the column names of the wp_comments
table. Viewing the wp_comments
scehma, note that there is a column called comment_parent
that contains the the post ID of the comment’s parent, or defaults to 0
if the comment has no parent. Therefore, you can achieve the desired effect via the following:
function deleteAPointFromUser( $comment_id ) {
$comment = get_comment( $comment_id );
// Only decrement user 'points' if the comment being deleted has no parent comment.
if( $comment->comment_parent == 0 ) {
$authorid = $comment->user_id;
$currentPointNumber = get_user_meta( $authorid, 'points', true );
update_user_meta( $authorid, 'points', $currentPointNumber - 1 );
}
}
add_action( 'trash_comment', 'deleteAPointFromUser' );