aboutsummaryrefslogtreecommitdiff
path: root/documentation/examples/hooks/basic.php
blob: 71076ee96b586ece678c124b567d27c19f6db0b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php

elgg_register_plugin_hook_handler('get_items', 'example', 'example_plugin_hook');
elgg_register_plugin_hook_handler('get_items', 'example', 'example_plugin_hook_2');

$params = array('username' => 'Joe');
$items = elgg_trigger_plugin_hook('get_items', 'example', $params, $default);

var_dump($items);

function example_plugin_hook($hook, $type, $value, $params) {
	if (is_array($value)) {
		$value[] = "Hook Value 1";
		$value[] = "Hook Value 2";
	}

	return $value;
}

function example_plugin_hook_2($hook, $type, $value, $params) {
	$username = isset($params['username']) ? $params['username'] : NULL;
	if (is_array($value)) {
		switch($username) {
			case 'Joe':
				$value[] = "Joe's item";
				break;
			case 'John':
				$value[] = "Joe's item";
				break;
		}
	}

	return $value;
}