50 Filters of WordPress: Series Finale

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

  1. login_errors allows us to change the error messages while logging in to WordPress.
  2. 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.
  3. allowed_redirect_hosts lets us define "safe" external hosts for the wp_safe_redirect() function.
  4. body_class gives us the opportunity to set custom class names for the <body> tag.
  5. locale makes WordPress change its language.
  6. sanitize_user cleans up the usernames and lets us change the cleaning up sequence.
  7. the_content filters the post contents amd allows us to intervene before the contents are displayed.
  8. the_password_form creates the password forms for password protected posts and lets us change the form.
  9. the_terms filters the output of the the_terms() function and again, lets us intervene.
  10. wp_mail_from allows us to change the "From" name of the emails WordPress sends.

50 Examples for WordPress Filters – Part Three

  1. gettext filters the translatable strings so we can tamper with the behaviour or change the strings.
  2. sanitize_title cleans up the post titles in order to save them as "slugs" and allows us to alter the process.
  3. no_texturize_shortcodes gives us the chance to add our shortcodes to the "do not texturize" list.
  4. pre_comment_approved filters the process before a comment is approved (or not) and lets us step in.
  5. enable_post_by_email_configuration lets us enable or disable the "post by email" feature of WordPress core.
  6. wp_title filters the page titles, normally shown in the <title> tags and on our tab handles in our browsers.
  7. preprocess_comment handles the processes before any comment data is saved to the database.
  8. login_redirect makes it possible for us to set a "safe" redirect after a user logs in.
  9. plugin_action_links_$plugin allows us display links under our plugin names in the Plugins page.
  10. 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

  1. use_default_gallery_style lets us enable or disable the default CSS rules for the [gallery] shortcode.
  2. wp_get_attachment_url filters the output of attachment URLs and allows us to step in.
  3. wp_mail_content_type allows us to change the content type of emails that WordPress sends (which is text/plain by default).
  4. 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.
  5. wp_revisions_to_keep lets us change the revisions limit for posts – a single post, post types or whatever you can imagine!
  6. img_caption_shortcode filters the core [caption] shortcode for images and lets us rewrite the output completely, if necessary.
  7. post_class filters the post_class() function and makes it possible to set custom class names for posts.
  8. attachment_fields_to_edit allows us to add or remove input fields for attachments.
  9. excerpt_length lets us change how many words will be displayed for automatic excerpts.
  10. 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

  1. posts_search filters the searching process and allows us to intervene.
  2. wp_editor_set_quality sets the compression quality for resized attachment images and lets us change that setting.
  3. widget_text filters the default Text widget and allows us to tamper with the output.
  4. the_content_feed makes it possible for us to change the feed items' content.
  5. mce_buttons lets us add or remove buttons for the first line of our Visual Editors.
  6. list_terms_exclusions gives us the opportunity to define exceptions in terms lists.
  7. 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.
  8. excerpt_more lets us change the default [...] text to something else for automatic excerpts.
  9. manage_posts_columns makes it easier for us to edit the columns of post lists in admin pages.
  10. user_contactmethods makes it possible for us to add or remove profile input fields.

50 Examples for WordPress Filters – Part Six

  1. script_loader_src filters the wp_enqueue_script() function and lets us step in with the function's output.
  2. admin_post_thumbnail_html allows us to add HTML after the "Set featured image" link on the "New Post" page.
  3. comment_flood_filter gives us the opportunity to tamper with the flood checking process.
  4. dashboard_glance_items lets us change the "At a Glance" section in the admin dashboard.
  5. login_message gives us the possibility to change the default login messages.
  6. bulk_post_updated_messages filters the output of the informational messages when a post is updated.
  7. widget_categories_args makes it possible for us to play with the arguments of the default Categories widget.
  8. registration_redirect allows us to set a "safe" redirect upon a successful registration.
  9. comment_form_default_fields lets us play with the default comment form fields.
  10. 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:

  1. Share your thoughts on this series by commenting below,
  2. Suggest new filters and example ideas for an "addendum" part or two,
  3. Offer ways to improve my writing if you caught a mistake, incoherency or ambiguity in my posts,
  4. And share these tutorials anywhere for everyone to see and learn about WordPress filters!

Thanks for bearing with me till the end. Goodbye!

Tags:

Comments

Related Articles