WordPress filters does the magic of data manipulation. Once you understand the power of filters in wordpress you can do lot of magic. This is very much helpful for developers who write plugins for wordpress. It is not necessary that you can use only wordpress default filters. If you want you can create your own filters.
What does this filter do? Filters basically passes a value to series of functions and returns the value. To understand the full concept of filters in wordpress you need know two functions basically
- add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1)
- apply_filters($tag, $string)
add_filter – Adds a function to a filter. The added function will be executed while a filter is applied.
- Param tag – This is a normal string text using this you can group number functions for a particular filter
- Param function_to_add – This is the function to be called when a filter is being executed
- Param priority – If you want to change the sequence of execution or the order of execution you can do by changing this param
- Param accepted_args – This mention no of arguments for the filter function.
apply_filters – Executes a filters and it returns a value.
- Param tag – This is a normal string text using this you can group number functions for a particular filterParam
- Param string – A values that is passed for the function.
$name = 'IMTHiaz rAFIQ';
$name = apply_filters('format_name',$name);
That would print name as Imthiaz Rafiq. Here I have used a simple example. WordPress uses this for everything. So if you want to control any data in wordpress you can do it with the help of filters ;-).
Check this site out for all filters and actions in wordpress.. 🙂
Untill Next time ….!!!