Filters
Filters work through a pair of functions that work together just like hooks. They are:
apply_filters()add_filter()
The apply_filters() is the one that defines the filter within the WordPress code.
Line 243 of post-template.php in wp-includes has this line:
$content = apply_filters('the_content',content)
The first parameter is the name of the filter and the second is the value to be filtered. Can pass more then one argument.
ad_filter() is to modify the value of the function .
function modify_content($content){ return $content.'Copy right 2022';
}
add_filter('the_content','modify_content');
Why its called a filter – I modify the content and then pass it back.
Doesn’t have to be together.
Accepts two parameters – the name of the filter, the seonc dis the callback function.If two – have to specify it:
add_filter('body_class','modify_body_classes', 10, 2)
third parameter is priority. If forget # of parameters and it is greater then 1 – error! Use same values in add_filter() that are used in apply_filters()
Divides some in 2 groups – one that are read from the database first and then filtred out. or applied to info first and then snet to database. Content one is in th eefirst.
add_filter(‘contant-save-pre’,’my_santitize_content’) does the latter
