#1: pre_comment_author_name

The pre_comment_author_name filter allows you to modify a comment author’s name before the comment is created or updated.

It’s evaluated in:

The value of pre_comment_author_name is also filtered through:

Example:

Let’s say you want to prefix commenters’ names with the word ‘Admin’ if they are administrators on your site. The following example will turn ‘Some Name’ into ‘Admin: Some Name’.

We’ll use the manage_options capability to determine if the commenter is an admin, and if so, filter the name. If they don’t have the capability (aren’t an admin), we’ll return the name unfiltered.

What is this?

In the scheme of things, hooks and filters are some of the least documented parts of the WordPress code base. A few years ago, the WordPress docs team developed a roadmap for the future of WordPress documentation and as I was part of the team that developed it, I’m none too aware of where the dry patches are. So I decided to do this thing.

From Adam Brown’s hooks list, I pulled 2500+ filter and action hooks. That’s a lot of examples to write but maybe I can help some people discover new and interesting ways to extend WordPress.

These examples may not all be awesome, but that’s the beauty of crowd-sourced code reviews, we’ll get it as right as we can. And of course the bonus of all this, is that hopefully we can put some/many/all of these examples to use in the Code Reference, wherever filters may fall into the new roadmap.