Plugin system
2 posts by 2 authors in: Forums > CMS Builder
Last Post: October 23, 2009 (RSS)
I'm trying to write a plugin to keep a log of user logins. I've found the hooks that you've added for admin_prelogin and admin_postlogin, but wondered if you could please explain to me what the difference is between a hook and a filter.
In most of the supplied plugins, you make use of filters by using addFilter() and only in schemaDumper is addAction() used which refers to a hook. But why do you call some areas filters and some hooks?
Thanks, Paul.
In most of the supplied plugins, you make use of filters by using addFilter() and only in schemaDumper is addAction() used which refers to a hook. But why do you call some areas filters and some hooks?
Thanks, Paul.
Re: [pothompson] Plugin system
By Dave - October 23, 2009
Hi Paul,
They are very similar. The only difference is hooks called with applyFilters() expect something to be return()'ed. So we pass content to the hook as the first argument and then expect it back. Where as actions just run code and ignore the return() value.
Filters let you modify or add content to some existing content, and actions let you run some arbitrary code. For your purposes addAction() would work fine.
Also, in schemaDumper.php, this line should actually be:
addAction('plugin_actions', 'schemaDumper_addPluginAction');
Since the code that calls it is: doAction() and not doFilter(). (I've updated that in the code).
Hope that all makes sense. Let me know if you have any other questions about any of that.
They are very similar. The only difference is hooks called with applyFilters() expect something to be return()'ed. So we pass content to the hook as the first argument and then expect it back. Where as actions just run code and ignore the return() value.
Filters let you modify or add content to some existing content, and actions let you run some arbitrary code. For your purposes addAction() would work fine.
Also, in schemaDumper.php, this line should actually be:
addAction('plugin_actions', 'schemaDumper_addPluginAction');
Since the code that calls it is: doAction() and not doFilter(). (I've updated that in the code).
Hope that all makes sense. Let me know if you have any other questions about any of that.
Dave Edis - Senior Developer
interactivetools.com
interactivetools.com