#13: author_rewrite_rules

The author_rewrite_rules filter makes it possible to modify WordPress’ default rewrite rules for handling author pages.

It is evaluated in WP_Rewrite::rewrite_rules() in the wp-includes/rewrite.php file.

The author_rewrite_rules filter’s single argument takes the form of an array and contains the key/value rewrite pairs for author pages.

Side note: Altering the default author rewrite rules may cause 404’s with pages that were linked prior to the change. IF you’re going to modify the default rules, it is usually best to retain the original rules and set up redirects to the new permastructs. One method is to append a custom query var — such as ‘redirect’ value of ‘true’ — to the original rule(s), then adding a handler to redirect to the new permastruct if the custom query var is present. This way, you get new custom author rewrites and the old ones still work.

Example:

Let’s say you have a site that makes it a point to refer to credited authors as “contributors”. The following will alter your author rewrite rules to point to yoursite.com/contributor/name for author archives.

View the code example on Gist.

**Bonus: Example functions for adding a ‘redirect’ query var and parsing redirects for the old author permastruct.

View the bonus code example on Gist.

#3: wpmu_signup_user_notification

The wpmu_signup_user_notification filter is used in a boolean — or true/false — capacity to determine whether a confirmation email should be sent for new user signups in Multisite. It defaults to true.

It is evaluated in its namesake function, wpmu_signup_user_notification(), located in wp-includes/ms-functions.php.

The filter accepts four arguments:

  1. string $user The user’s login name
  2. string $user_email The user’s email
  3. string $key The activation key from wp_signup_user()
  4. array $meta By default, an empty array

If $user is not empty, the filter returns a value of true. Core uses the filter in just this capacity to disable sending a signup email when the ‘Skip Confirmation Email’ checkbox is selected on the Users > Add New screen.

Example:

Let’s say we only want to disable the user confirmation email for users who don’t have a Gmail address. We’ll test the user email for signs of Gmail and return false if we find it.

#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.