custom plugin events #4828
-
Is there a way to create custom event triggers? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 10 replies
-
You can check e_event.php in some plugins. If not core ones, lonalore plugins are good examples too. |
Beta Was this translation helpful? Give feedback.
-
I just needed this, so while I am on it. Plugin with the event:
trigger in survey.php (in the same plugin)
and using this event with other plugin
it works. |
Beta Was this translation helpful? Give feedback.
-
Yes. Simply call the event anywhere in your code by using
You do not necessarily need to add your custom plugin event to YOUR OPTIONALLY: For example: function config()
{
$event = array();
$event[] = array(
'name' => "myplugin_customevent", // "myplugin" is the plugin folder name. "customevent" should be a unique event name.
'function' => "customfunction",
);
return $event;
}
function customfunction($data)
{
echo "Do something!";
} Notes:
|
Beta Was this translation helpful? Give feedback.
Yes. Simply call the event anywhere in your code by using
e107::getEvent()->trigger('myplugin_customevent', $data)
.myplugin
is your plugin folder namecustomevent
is a unique event nameYou do not necessarily need to add your custom plugin event to YOUR
e_event
addon. If you trigger it somewhere in your code, other plugins can "listen" to your custom event by defining it in THEIRe_event
addon.OPTIONALLY:
If you want to LISTEN to your OWN custom event and run a function when it is triggered, then also add the custom event your
e_event.php
addon, within theconfig()
method. Also add the method that you want to run on that event.For example: