diff options
Diffstat (limited to 'documentation/examples/events/all.php')
-rw-r--r-- | documentation/examples/events/all.php | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/documentation/examples/events/all.php b/documentation/examples/events/all.php new file mode 100644 index 000000000..0ad02c1d4 --- /dev/null +++ b/documentation/examples/events/all.php @@ -0,0 +1,30 @@ +<?php +/** + * If you register an 'all' string for the event name, the handler function will + * be called for all events with that name, regardless of event type. The same + * can be done for the event type argument. Registering 'all' for both + * argyuments results in a handler being called for every event. + */ + +elgg_register_event_handler('all', 'object', 'example_event_handler'); + +// This function will be called for any event of type 'object' +function example_event_handler($event, $type, $object) { + // check what sort of object is passed + if ($object instanceof ElggObject) { + $subtype = $object->getSubtype(); + + switch ($subtype) { + case 'blog': + case 'thewire': + case 'pages': + // prevent these object subtypes from being saved or changed + return false; + default: + return true; + } + + } + + return true; +} |