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.

Did it work?

Save Snippet

Embed Snippet

To embed this snippet on your site, copy this html code and paste into your webpage. Learn more
By embedding snippets on your site, you are agreeing to our terms and conditions.

Embed Snippet

To embed this snippet on your site, copy this html code and paste into your webpage. Learn more
By embedding snippets on your site, you are agreeing to our terms and conditions.

Embed Snippet

To embed this snippet on your site, copy this html code and paste into your webpage. Learn more
By embedding snippets on your site, you are agreeing to our terms and conditions.