This entry is part 4 of 14 in the Plugin Development 101 Series
- Introduction to WordPress Plugin Development 101
- Plugin Development 101 – What Makes a Plugin?
- Plugin Development 101 – General Best Practices
- Plugin Development 101 – An Intro to Filters
- Plugin Development 101 – Intro to Actions
- Plugin Development 101 – Registering a Custom Post Type
- Plugin Development 101 – Intro to Short Codes
- Plugin Development 101 – Intro to Loading Scripts and Styles
- Plugin Development 101 – Introduction to Adding Dashboard Menus
- Plugin Development 101 – Separating Your Plugin into Multiple Files
- Plugin Development 101 – Your First OOP Plugin
- Plugin Development 101 – Dissecting the Featured Comments Plugin
- Plugin Development 101 – Digging Into WordPress Core to Solve a Problem
- Plugin Development 101 – Introduction to extending classes
In this part of Plugin Development 101 we take a look at one of the most important tools plugin developers use every day: filters. The presence of filters throughout WordPress are one of the elements that make plugin development possible, so having a good understanding of what they are and how they work is extremely important.
I have to apologize ahead of time for the lesser-than-optimal audio quality on the video.
Filters are a mechanism in WordPress that allow data to be manipulated before it is used or displayed. For example, a filter would allow the content of a post or page to be modified before it is displayed to the reader, or for the variables passed to a posts query to be altered before the posts are retrieved from the database.
I will leave the extended explanation of filters to the video, but here are a few links that help to illustrate what a filter is and how to use them:
7 thoughts so far
Have your say
Good overview. Thanks for this!
Glad to hear it was useful!
Is this the correct way to set up a filter which adds a new class name to a div (stored in $classes):
$classes = has_filter(‘my_custom_class’) ? apply_filters( ‘my_custom_class’, ”) : ”;
I have it so that $classes = ” if no filter has been set. (I think)
P.S. maybe this isn’t the right post to talk about apply_filters on.
Maybe a tutorial on apply_filters and how passing extra variables works? I’m having trouble in my mind understanding which comes first: apply_filters or add_filter
I think it’s that apply_filters passes the variables to add_filter. Then add_filter does something with those variables and then passes them back.
If so, how does the add_filter pass back multiple variables – and how are those variables used? Are they passed as an array with something like:
Let’s leave that for a more advanced look at filters 😉
Thank you, I’m just starting out on WordPress plugin development and going through this tutorial series. If possible, could you publish a sort of graded list that would let a learner know how to progress from the beginner series to the more complex development tutorials… sort of learning path. I think it would really make it easier for us to progress along.
Thank you for the suggestion!
Comments are closed.
Leave a reply
Join the discussion