M van de K

Mijn blog over van alles

Keep WordPress comment_agent and comment_user_IP empty with hooks — 17/12/2016

Keep WordPress comment_agent and comment_user_IP empty with hooks

WordPress saves all kinds of information when someone leaves a comment on your blog/website. Two pieces of information I don’t need from someone who comments on an article are the IP-address of the author and the User Agent of the browser they used to place the comment.

pre_comment_* hooks

WordPress has pre_comment_* hooks which can be used to alter data before it’s put into the database.

I used the following two hooks:

pre_comment_user_ip

This hook filters the comment author’s IP before it is set, so this can be used to alter the IP-address before it’s saved in the database.

// Don't log IP addresses of comment authors.
add_filter( 'pre_comment_user_ip', '__return_zero' );

The filter uses the function __return_zero, which does exactly as it says: the comment_user_ip is set to 0.

Clean up already saved IP-addresses

To clean up the already saved IP-addresses, you execute the following SQL-query (after you made sure you have made a full backup of the database) via phpMyAdmin to your WordPress database:

update wp_comments set comment_author_IP ='' ;

pre_comment_user_agent

This hook filters the comment author’s browser user agent before it is set, so this can be used to alter the User Agent before it’s saved in the database.

// Don't log User Agents of comment authors.
add_filter( 'pre_comment_user_agent', '__return_empty_string' );

The filter uses the function __return_empty_string, which returns an empty string before the data is saved into the database, thus keeping the database clean from unneeded information.

Clean up already saved User Agents

To clean up the already saved User Agents, you execute the following SQL-query (after you made sure you have made a full backup of the database) via phpMyAdmin to your WordPress database:

update wp_comments set comment_agent ='' ;
How to make OCSP stapling on nginx work — 27/04/2016
Using multiple IPv6 addresses on a single interface — 23/04/2016
Disable WordPress Twemoji and Emoji scripts — 13/03/2015

Disable WordPress Twemoji and Emoji scripts

Add the following two lines in your functions.php file.

function remove_emoji_scripts() {
// Dequeue the Emoji script
wp_dequeue_script( 'emoji' );
// Dequeue the Twemoji script
wp_dequeue_script( 'twemoji' );
}
add_action( 'wp_enqueue_scripts', 'remove_emoji_scripts' );
Best configuration of Server Side TLS — 28/02/2015