Welcome to the series finale of "50 Filters of WordPress"! In this last part, we're going to review what we learned and summarize all the 50 filters with 10 words (give or take) each.
Let's begin!
First Part An Introduction to WordPress Filters
In the first part of the series, we entered the magical world of WordPress filters and got to know what they are, how they work, when we should use them and how we should use them. We learned:
What a WordPress filter is: A filter is a function that sits between the database and the browser, doing stuff to your data before WordPress outputs it. WordPress has—literally—hundreds of filters inside its core and you can create your own filters in the things you develop (like plugins). That's what we learned.
How to create a filtering function and hook it to a filter: It's simple in essence, really: We create a function that plays with the data and we hook it to the corresponding filter hook by using the add_filter()
function. (I might have over-simplified it – it's actually a bit more complicated than that.) Be sure to check out the first part of this series, if you haven't already. It's important.
How to remove a function (or functions) from a filter: We learned two functions in WordPress to remove functions from filters: remove_filter()
and remove_all_filters()
. (You can probably guess which one removes one function and which one removes all functions hooked to a filter.) We learned how to use these functions.
How to create our own filters: WordPress has hundreds of awesome filters in its core, but what if we need our plugin to be as flexible and expandable as the core? Well, we create our own filter hooks by using the apply_filters()
function. Be sure to check that out, too, if you're a plugin developer.
Next Five Parts 50 Great Examples for 50 Great Filters
After entering the world of WordPress filters, the best thing to do would have been getting to know about each and every filter hook in WordPress' core. While that would be the most amazing tutorial series in the history of WordPress tutorials, it would take an incredible amount of time and effort because there are a little over a thousand filters in the core as of WordPress v3.9.1.
That doesn't mean we should sit and learn nothing, though. I chose 50 WordPress filters, introduced them with little paragraphs and done examples with each one. Here's what we learned with brief explanations:
50 Examples for WordPress Filters – Part Two
-
login_errors
allows us to change the error messages while logging in to WordPress. -
comment_post_redirect
makes it possible for us to redirect visitors to an internal page (or an allowed external web page) after they post a comment. -
allowed_redirect_hosts
lets us define "safe" external hosts for thewp_safe_redirect()
function. -
body_class
gives us the opportunity to set custom class names for the<body>
tag. -
locale
makes WordPress change its language. -
sanitize_user
cleans up the usernames and lets us change the cleaning up sequence. -
the_content
filters the post contents amd allows us to intervene before the contents are displayed. -
the_password_form
creates the password forms for password protected posts and lets us change the form. -
the_terms
filters the output of thethe_terms()
function and again, lets us intervene. -
wp_mail_from
allows us to change the "From" name of the emails WordPress sends.
50 Examples for WordPress Filters – Part Three
-
gettext
filters the translatable strings so we can tamper with the behaviour or change the strings. -
sanitize_title
cleans up the post titles in order to save them as "slugs" and allows us to alter the process. -
no_texturize_shortcodes
gives us the chance to add our shortcodes to the "do not texturize" list. -
pre_comment_approved
filters the process before a comment is approved (or not) and lets us step in. -
enable_post_by_email_configuration
lets us enable or disable the "post by email" feature of WordPress core. -
wp_title
filters the page titles, normally shown in the<title>
tags and on our tab handles in our browsers. -
preprocess_comment
handles the processes before any comment data is saved to the database. -
login_redirect
makes it possible for us to set a "safe" redirect after a user logs in. -
plugin_action_links_$plugin
allows us display links under our plugin names in the Plugins page. -
the_editor_content
gives us the opportunity to pre-fill the content of the post editor which is empty by default.
50 Examples for WordPress Filters – Part Four
-
use_default_gallery_style
lets us enable or disable the default CSS rules for the[gallery]
shortcode. -
wp_get_attachment_url
filters the output of attachment URLs and allows us to step in. -
wp_mail_content_type
allows us to change the content type of emails that WordPress sends (which istext/plain
by default). -
pre_comment_user_ip
makes it possible for us to tamper with the IP address of commenters before the addresses are saved to the database. -
wp_revisions_to_keep
lets us change the revisions limit for posts – a single post, post types or whatever you can imagine! -
img_caption_shortcode
filters the core[caption]
shortcode for images and lets us rewrite the output completely, if necessary. -
post_class
filters thepost_class()
function and makes it possible to set custom class names for posts. -
attachment_fields_to_edit
allows us to add or remove input fields for attachments. -
excerpt_length
lets us change how many words will be displayed for automatic excerpts. -
bulk_actions-$screenid
filters the bulk actions for the item lists in admin pages and lets us add or remove actions.
50 Examples for WordPress Filters – Part Five
-
posts_search
filters the searching process and allows us to intervene. -
wp_editor_set_quality
sets the compression quality for resized attachment images and lets us change that setting. -
widget_text
filters the default Text widget and allows us to tamper with the output. -
the_content_feed
makes it possible for us to change the feed items' content. -
mce_buttons
lets us add or remove buttons for the first line of our Visual Editors. -
list_terms_exclusions
gives us the opportunity to define exceptions in terms lists. -
image_size_names_choose
allows us to add custom image size names for the "Sizes" dropdown shown when an image is added in the Visual Editor. -
excerpt_more
lets us change the default[...]
text to something else for automatic excerpts. -
manage_posts_columns
makes it easier for us to edit the columns of post lists in admin pages. -
user_contactmethods
makes it possible for us to add or remove profile input fields.
50 Examples for WordPress Filters – Part Six
-
script_loader_src
filters thewp_enqueue_script()
function and lets us step in with the function's output. -
admin_post_thumbnail_html
allows us to add HTML after the "Set featured image" link on the "New Post" page. -
comment_flood_filter
gives us the opportunity to tamper with the flood checking process. -
dashboard_glance_items
lets us change the "At a Glance" section in the admin dashboard. -
login_message
gives us the possibility to change the default login messages. -
bulk_post_updated_messages
filters the output of the informational messages when a post is updated. -
widget_categories_args
makes it possible for us to play with the arguments of the default Categories widget. -
registration_redirect
allows us to set a "safe" redirect upon a successful registration. -
comment_form_default_fields
lets us play with the default comment form fields. -
upload_mimes
makes it easier for us to change the allowed list of file types that can be uploaded to the Media Library.
The End
So that's the end of it. We're done with the series of WordPress filters – but we're not done with WordPress hooks yet: Stay tuned for another seven-part tutorial on WordPress actions!
Despite the fact that it was the most exhausting series of tutorials, I enjoyed writing every word and every bit of code for I knew it would be a small—but extremely useful—resource on this topic. I learned a lot while writing; I just hope you did as well.
All kinds of contribution will be appreciated, by the way. You can:
- Share your thoughts on this series by commenting below,
- Suggest new filters and example ideas for an "addendum" part or two,
- Offer ways to improve my writing if you caught a mistake, incoherency or ambiguity in my posts,
- And share these tutorials anywhere for everyone to see and learn about WordPress filters!
Thanks for bearing with me till the end. Goodbye!
Comments