What are the difference between add_filter
, apply_filters
, add_action
and do_action
?
I can see that do_action
puts a tag in the code which can then be used by add_action
. However, I can't see how add_filter
and apply_filters
correlate with this. One would think that there would be a do_filter
which would add a tag to the code, much like do_action
; but neither of these seem to do this. And neither of them have a simple form like do_action( $tag )
, but instead require callback functions as paramete开发者_JS百科rs.
Filters in wordpress are used to modify text. So, for instance:
Stripping SQL statements from a block of text before putting it in the database to avoid injection attacks. That would be a filter.
Actions are functions that are called when wordpress does something. For instance, (from docs), emailing someone when a post is written.
http://codex.wordpress.org/Function_Reference/add_action
http://codex.wordpress.org/Function_Reference/add_filter
精彩评论