An event is a notification about occurence that has happened in a plugin or ImpressPages core. Catch core events to do actions when something happens or throw events within your plugin to enable other plugins to react on event inside your plugin.

Every event should have it's unique name. To organize your events easier, it is recommended to use your plugin's name followed by underscore character as event name prefix (e.g. MyPlugin_myEvent).

Throwing an event

To throw an event, call ipEvent() function.

ipEvent('MyPlugin_somethingHappened', array('myEventData' => 'myEventValue'));

The sample code above notifies about the MyPlugin_somethingHappened event and passes array as event data. You can pass any data you you think is usefull for those who catch the event.

Catching an event

To catch an event, create a file named Event.php in your plugin's directory containing Event class. In this class, create a method with the event name.

namespace Plugin\MyPlugin;

class Event
    public static function MyPlugin_somethingHappened($data)
        // echo 'Something happened. Event data: '.$data['myEventData'];

The sample code above catches MyPlugin_somethingHappened event.

Setting event priority

You can set a priority of event listener by specifying underscore character following a numeric value in event's method name. Lower number means higher priority. The default event priority is set to 50.

public static function MyPlugin_somethingHappened_10($data)

See also

comments powered by Disqus