/** * Call an event's callback with two optional byref parameters * @param string $event * @param string $step * @param boolean $pre 0|1 * @param mixed $data optional arguments for event handlers * @param mixed $options optional arguments for event handlers * @return array collection of return values from event handlers * @since 4.5.0 */ function callback_event_ref($event, $step = '', $pre = 0, &$data = null, &$options = null) { global $plugin_callback, $production_status; if (!is_array($plugin_callback)) { return array(); } $return_value = array(); foreach ($plugin_callback as $c) { if ($c['event'] == $event and (empty($c['step']) or $c['step'] == $step) and $c['pre'] == $pre) { if (is_callable($c['function'])) { // cannot call event handler via call_user_func() as this would dereference all arguments. // side effect: callback handler *must* be ordinary function, *must not* be class method in PHP <5.4 (@see https://bugs.php.net/bug.php?id=47160) $return_value[] = $c['function']($event, $step, $data, $options); } elseif ($production_status == 'debug') { trigger_error(gTxt('unknown_callback_function', array('{function}' => callback_tostring($c['function']))), E_USER_WARNING); } } } return $return_value; }
/** * Lists handlers attached to an event. * * @param string $event The callback event * @param string $step The callback step * @param bool $pre The position * @param bool $as_string Return callables in string representation * @return array|bool An array of handlers, or FALSE * @since 4.6.0 * @package Callback * @example * if ($handlers = callback_handlers('article_saved')) * { * print_r($handlers); * } */ function callback_handlers($event, $step = '', $pre = 0, $as_string = true) { global $plugin_callback; $out = array(); foreach ((array) $plugin_callback as $c) { if ($c['event'] == $event && (!$c['step'] || $c['step'] == $step) && $c['pre'] == $pre) { if ($as_string) { $out[] = callback_tostring($c['function']); } else { $out[] = $c['function']; } } } if ($out) { return $out; } return false; }