Comment Author IP Logging
This snippet logs the IP address of comment authors, which can be useful for moderation and spam prevention.
PHP
function log_comment_author_ip($comment_id) {
$comment = get_comment($comment_id);
if (!$comment->user_id) {
$ip_address = $_SERVER['REMOTE_ADDR'];
add_comment_meta($comment_id, 'author_ip', $ip_address);
}
}
add_action('comment_post', 'log_comment_author_ip');
Snippet Feedback
Did this snippet work for you? Do you have any questions about this snippet? Leave some feedback below.
SHARED BY