Can you please point me to some good mods that make use of integration hooks? I am a bit confused on how to use them through modifications.xml and would like to study the source to learn more ... Thanks.
Just in case you didn't read it yet:
http://wiki.simplemachines.org/smf/Add_a_custom_action_using_integration_hooks
:)
Thanks, I had read that. But I am a bit confused on how modifications.xml and Integration hooks gel together. They seem like two separate ways of doing things ...
That's because they are. modifications.xml (or whatever you want to call it, I've been known to have mods with multiple such files to group changes together) is about raw code editing, integration hooks is about not doing code editing at all.
Some mods find they need to do raw code editing because the choices available in terms of hooks may not be enough.
modifications.xml = code edits
iinstall.php = usually database edits which includes settings and hooks
Some mods boast of only using hooks.
So, for example, if I wanted to make a mod that added headers or footers to every post made in the forum the two ways to go about it would be -
Raw editing: Find out the "post message" function and modify it (i.e. change the core function) OR
Using hooks: Check for "post message" hook and attach it with your own custom post message function
Is that right?
Sort of. Not every function has a hook - fairly sure there isn't a hook in 2.0 for 'post message' for example. (There is one on creation of a new topic, and one for topic display that can be coerced into doing other things, but it's pretty limited.)
Ah, ok. One other doubt - after you have added your own custom function to a hook, does the original core function still execute later? Taking the same example I posted - if I add a custom_post_message function to "post message" hook, will the original "post message" core function be called again later (after the custom_post_message function is executed)?
The hook is little more than 'when you get to this point, call me' notification. The original code will continue to run exactly as it would otherwise, a hook is merely *additional* code to be run at the selected points.
So is there an option to decide whether the custom function runs before or after the core function (in case we are calling a hook that deals with a core function)?
No.
Hooks run when they run. There is a shortage of hooks anyway, if you don't have a hook for the specific task at hand, you'll have to just make an edit anyway. The available hooks are documented in the wiki (http://wiki.simplemachines.org/smf/Integration_hooks).
Thanks for all the clarifications. Much appreciated.