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.
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_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_errorsallows us to change the error messages while logging in to WordPress.
comment_post_redirectmakes it possible for us to redirect visitors to an internal page (or an allowed external web page) after they post a comment.
allowed_redirect_hostslets us define "safe" external hosts for the
body_classgives us the opportunity to set custom class names for the
localemakes WordPress change its language.
sanitize_usercleans up the usernames and lets us change the cleaning up sequence.
the_contentfilters the post contents amd allows us to intervene before the contents are displayed.
the_password_formcreates the password forms for password protected posts and lets us change the form.
the_termsfilters the output of the
the_terms()function and again, lets us intervene.
wp_mail_fromallows us to change the "From" name of the emails WordPress sends.
50 Examples for WordPress Filters – Part Three
gettextfilters the translatable strings so we can tamper with the behaviour or change the strings.
sanitize_titlecleans up the post titles in order to save them as "slugs" and allows us to alter the process.
no_texturize_shortcodesgives us the chance to add our shortcodes to the "do not texturize" list.
pre_comment_approvedfilters the process before a comment is approved (or not) and lets us step in.
enable_post_by_email_configurationlets us enable or disable the "post by email" feature of WordPress core.
wp_titlefilters the page titles, normally shown in the
<title>tags and on our tab handles in our browsers.
preprocess_commenthandles the processes before any comment data is saved to the database.
login_redirectmakes it possible for us to set a "safe" redirect after a user logs in.
plugin_action_links_$pluginallows us display links under our plugin names in the Plugins page.
the_editor_contentgives 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_stylelets us enable or disable the default CSS rules for the
wp_get_attachment_urlfilters the output of attachment URLs and allows us to step in.
wp_mail_content_typeallows us to change the content type of emails that WordPress sends (which is
pre_comment_user_ipmakes it possible for us to tamper with the IP address of commenters before the addresses are saved to the database.
wp_revisions_to_keeplets us change the revisions limit for posts – a single post, post types or whatever you can imagine!
img_caption_shortcodefilters the core
[caption]shortcode for images and lets us rewrite the output completely, if necessary.
post_class()function and makes it possible to set custom class names for posts.
attachment_fields_to_editallows us to add or remove input fields for attachments.
excerpt_lengthlets us change how many words will be displayed for automatic excerpts.
bulk_actions-$screenidfilters 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_searchfilters the searching process and allows us to intervene.
wp_editor_set_qualitysets the compression quality for resized attachment images and lets us change that setting.
widget_textfilters the default Text widget and allows us to tamper with the output.
the_content_feedmakes it possible for us to change the feed items' content.
mce_buttonslets us add or remove buttons for the first line of our Visual Editors.
list_terms_exclusionsgives us the opportunity to define exceptions in terms lists.
image_size_names_chooseallows us to add custom image size names for the "Sizes" dropdown shown when an image is added in the Visual Editor.
excerpt_morelets us change the default
[...]text to something else for automatic excerpts.
manage_posts_columnsmakes it easier for us to edit the columns of post lists in admin pages.
user_contactmethodsmakes it possible for us to add or remove profile input fields.
50 Examples for WordPress Filters – Part Six
wp_enqueue_script()function and lets us step in with the function's output.
admin_post_thumbnail_htmlallows us to add HTML after the "Set featured image" link on the "New Post" page.
comment_flood_filtergives us the opportunity to tamper with the flood checking process.
dashboard_glance_itemslets us change the "At a Glance" section in the admin dashboard.
login_messagegives us the possibility to change the default login messages.
bulk_post_updated_messagesfilters the output of the informational messages when a post is updated.
widget_categories_argsmakes it possible for us to play with the arguments of the default Categories widget.
registration_redirectallows us to set a "safe" redirect upon a successful registration.
comment_form_default_fieldslets us play with the default comment form fields.
upload_mimesmakes it easier for us to change the allowed list of file types that can be uploaded to the Media Library.
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!