Are there best practices for maintaining user posting points when deleting posts in a PHP forum?

When deleting posts in a PHP forum, it is important to maintain user posting points to ensure accuracy in tracking their contributions. One way to achieve this is by updating the user's points when a post is deleted. This can be done by subtracting the points associated with the deleted post from the user's total points.

// Assuming $postPoints is the number of points associated with the deleted post
// Assuming $userId is the ID of the user who posted the deleted post

// Get the current total points of the user
$currentPoints = getUserPoints($userId);

// Subtract the points associated with the deleted post
$newPoints = $currentPoints - $postPoints;

// Update the user's total points in the database
updateUserPoints($userId, $newPoints);