SE4 Hook sample development

Following up on my previous post about SE4 hooks. On this post we create a simple hook. For example we want to create a reward system. We reward a user a point per log-in per day i.e. a user gets a point if he logs in in a particular day but the point is only rewarded once per day. We encapsulate this feature in a theoretical plugin called “point-module.”

socialengine4_hook

Letting SE4 Know

We need to let SE4 know that we plan on hooking to an event. In particular the event when the user successfully logged in. SE4 has an aptly named event “onUserLoginBefore” which is triggered when the user successfully logs in but before the lastlogin_date field is updated. On our module’s manifest–the file application/modules//settings/manifest.php we put

This lets SE4 know that we plan on handling the “onUserLoginBefore” event with an instance of the class Point_Plugin_Core.

The Handler

Next we create the handler for the event. In application/modules/Point/Plugin/Core.php:

Summary

This example illustrates that it’s pretty simple to implement a social engine hook. All you really have to know is which hook best serves the task you’re trying to accomplish. “What if none of the hooks apply to a customization I’m trying to accomplish?”, you ask. There are other ways which is a subject of another post.

Leave a Reply

Your email address will not be published. Required fields are marked *

*