#14: the_editor_content

The the_editor_content filter makes it possible for you to pre-fill the content editor in the post editing screen.

It is evaluated in the _WP_Editors::editor() method in wp-includes/class-wp-editor.php. The _WP_Editors class is instantiated via wp_editor() located in wp-includes/general-template.php.

the_editor_content‘s single argument is the editor content string, empty by default.

Note: to avoid a situation where your content ends up duplicating every time you update the post, you should check if the editor content is empty before returning the filtered version of it. We’ll cover this in the example.

Example:

Let’s say you run a site that documents a lot of very similar things, like say, filters. It can be kind of a drag to write out and/or copy/paste the same template into the editor over and over, so the following will show you how to inject a post template into the editor prior to the first save.

View the code example on Gist.

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

Week 1 Recap: Filters 1-12

Just in case you missed any of the filters posted this week, I decided to do a short recap. This week we covered filters 1-12 from the master list. Next week we’ll be making up a few filters missed this weekend while I was off the radar.

#1: pre_comment_author_name

This filter allows you to modify a comment author’s name before the comment is created or updated. The example covered prepending text to comment author names for administrators.

#2: dashboard_primary_title

This filter allows you to modify the title of the ‘WordPress Blog’ dashboard widget when WordPress is initially installed. This type of filter only really has a one-time use since users can adjust the widget title and the filter no longer has any effect.

#3: wpmu_signup_user_notification

This filter is used to determine whether a confirmation email should be sent for new user signups in Multisite. The example covered disabling confirmation emails to anyone who had a Gmail email address.

#4: the_weekday_date

This filter makes it possible to change the displayed day of the week a post was published, when the function of the same name, the_weekday_date() is used inside the Loop. The example covered converting the word “Saturday” into pirate-speak.

#5: post_row_actions

This filter allows you to modify the row action links in the non-hierarchical post types list table, links like ‘Edit’, ‘Quick Edit’, ‘Trash’, and ‘Preview’. The example covered removing the ‘Quick Edit’ link for posts.

#6: wp_terms_checklist_args

This filter allows you to modify the arguments array in wp_terms_checklist(), the function that displays hierarchical taxonomies in a tiered, checklist form. The example covered how to keep the selected terms from appearing at the top of the checklist.

#7: post_comments_feed_link

This filter allows you to modify the comments feed URL for the current page or post. The example covered changing the URL scheme — such as changing from http to https — of the comments feed link.

#8: get_the_generator_{$type}

This filter allows you to modify the generator meta tag provided by WordPress in certain contexts. The example covered how to convert the WordPress version number into the name of the jazz musician for its corresponding release. In other words, fun with filters!

#9: teeny_mce_buttons

This filter allows you to add or remove buttons from the teeny mce buttons row used in Press This. The example covered registering a new button for the teeny mce bar.

#10: posts_join_paged

This filter allows you to add SQL join(s) to the posts query in paginated contexts. There is no example for this one yet. Have an idea? Submit an example.

#11: http_response

This filter makes it possible to manipulate the response array returned by a wp_remote_request() call. The example covered returning canned body content for requests with status codes other than 200, 301, or 302.

#12: protected_title_format

This filter allows you to modify the text that gets prepended to a post title if it is password protected. The example covered converting the default ‘Protected: [Post Title]’ prefix text to ‘Members Only: [Post Title]’.