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 ='' ;

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' );

Build nginx from source

I use nginx as a webserver for my websites. When installed from aptitude, it comes with a lot of modules that I do not need, so I made a customized version of nginx, to make nginx the way I want it.

First, you have to download the latest version of nginx from the website. Version 1.7.10 is the latest version at this moment.

wget http://nginx.org/download/nginx-1.7.10.tar.gz

Then, you have to extract the files from the tar-archive

tar xzf nginx-1.7.10.tar.gz

Then, browse into the folder in which the files are extracted

cd nginx-1.7.10/

Execute the configure script

./configure \
--user=www-data \
--group=www-data \
--prefix=/etc/nginx \
--sbin-path=/usr/sbin \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-client-body-temp-path=/var/lib/nginx/body \
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
--http-log-path=/var/log/nginx/access.log \
--http-proxy-temp-path=/var/lib/nginx/proxy \
--http-scgi-temp-path=/var/lib/nginx/scgi \
--http-uwsgi-temp-path=/var/lib/nginx/uwsgi \
--lock-path=/var/lock/nginx.lock \
--pid-path=/var/run/nginx.pid \
--with-http_realip_module \
--with-ipv6 \
--with-cpu-opt=amd64 \
--with-http_ssl_module \
--with-http_spdy_module \
--without-select_module \
--without-http_browser_module \
--without-http_empty_gif_module \
--without-http_geo_module \
--without-http_map_module \
--without-http_limit_req_module \
--without-http_limit_conn_module \
--without-http_memcached_module \
--without-http_scgi_module \
--without-http_split_clients_module \
--without-http_ssi_module \
--without-http_userid_module \
--without-http_uwsgi_module \
--without-mail_pop3_module \
--without-mail_imap_module \
--without-mail_smtp_module \
--with-cc-opt=-O3

Then, stop nginx, make and install the custom compiled version of nginx, and start it.

service nginx stop && make && make install && service nginx start

To make sure it’s the new version, check the version number of the running version:

nginx -v

How to delete files with a certain extension from a folder and all of its subfolders

First, browse to the folder in which you want to delete files with a specific extension

cd /path/to/folder

Then delete the files with the extension .jpg

find . -type f -iname \*.jpg -delete
  • . tells to start searching in the current folder.
  • -type f tells find only to look for files.
  • -iname makes the search case insensitive.
  • -delete tells find to delete/remove all files found.

Change .jpg with the file extension you want to delete from a folder. I recommend running the command without -delete first to get a list of the files that will be removed when -delete is included in the command. This way a small typo won’t delete anything you didn’t intend to.

Source: http://askubuntu.com/a/104841