Another day, another new series: WordPress Development. This series will focus on – you guessed it – developing plugins for the popular blogging platform – WordPress. This week, we’ll talk about the theory behind developing for WordPress.
WordPress contains a very useful Plugin API (Application Programming Interface), where you can change, add and even remove almost anything, anywhere within WordPress (within reason, of course). As WordPress is written in PHP, plugins must also be written in PHP. The API works by “hooking” into filters and actions which are placed all through WordPress at key places.
Differences Between a Filter and an Action
In WordPress, a filter is something that you would hook into if you want to filter data, being passed through a certain point, before it reaches its final destination. A filter will always give you data. An example of this would be if you wanted to remove cuss words from comments before they’re display, you would use a filter.
An action would be used when you want to simply output something to the user at certain places or points of time. An action will never give you data. An example of this would be if you wanted to add a CSS stylesheet (on-the-fly) to the Plugin user’s theme’s header.php.
Whether you’re using a filter or an action, you always return your data for it to get back into the “data stream”.
There are literally hundreds (if not thousands) of filters and actions contained within WordPress, the majority of which can be found on the WordPress Codex. The Filters reference is here and the actions reference is here.
The entire WordPress Plugin API is simply made up of filters and actions. There’s nothing else to it, it’s just all up to you to make good use of those filters and actions.