Dynamic Hooks

I was wondering if there was a way to dynamically add/remove hooks.  What I mean by this is that I have a start.php that initializes the attachment to  hooks/events I will need to use later, but because of the type of plugin I am creating I need to be able to create hooks/events outside of my start.php file.  Right now I have a file called create.php (registered as an action) that will create an object, file, and group in Elgg.  At the end of the file I need to be able to register a hook with register_plugin_hook (or event with its corresponding function call). 

How can I do this?  I don't know enough about Elgg to do this.  If I am correct, start.php is called everytime the plugin is being used on a given page, correct?  If so, then I can't just call the register_plugin_hook in my create.php action file, right?  I thought then that I should just create a seperate file that I will open up and write the literal function calls to (just using php, no Elgg functions).  Then, I would just include or require that file in the start.php file. 

Do you think that would work??

Thank you in advance for any help from you guys!

  • Plugins hooks usually have a params array, which you can use to see if the hook needs to be fired if certain criteria is met. You can define your plugins hooks within other files, and just call them as necessary. I think reference.elgg.org is pretty straightforward with documenting this.

  • Thank you very much! I will take a look at the reference pages.

     

  • Marcus Povey created a very powerful, flexible and simple way of providing hooks for other code to attach to, in a loosely coupled way.

    I’ve been using event driven development in my PHP code for years, way back since the first days of Elgg. In Elgg, events and triggers proved to be one of the frameworks most powerful, and a major factor in its success, allowing plugin developers to easily change core functionality without changing a line of core code