Events and filters
events() is the event bus of the framework (yf_core_events). Code fires an event and every listener of it
runs; a filter passes a value through its listeners, each returns the new value. A plugin reacts to the framework, and to other
plugins, through them instead of overriding a class. The boot phases, rendering, forms, the database installer, accounts, comments,
uploads and payments fire events; the catalogue below lists them with their payload.
Listen and fire
events()->listen('user.login', function ($e) {
// $e: ['user_id' => 42, 'group_id' => 2, 'ip' => '192.0.2.7']
}, $priority = 0);
events()->fire('shop.order_paid', [['order_id' => $id]]); // the listeners' answers, as an array
events()->until('price.quote', [$product]); // the first answer that is not null
events()->listening('user.login'); // something would run: build a costly payload only then
The second argument of fire() is the list of arguments each listener gets; the events of the framework pass one array
([['user_id' => ...]]), so a new key never breaks a listener. A higher priority runs first, equal priorities in the
order they were registered. A name with * listens to every event it matches (user.*). A listener stops the
event by returning false or by calling events()->stop() (its own answer is kept). An event nobody listens to
costs one array lookup: nothing is sorted, cached or allocated.
Filters
events()->listen_filter('user.display_name', function ($name, $user) {
return $name . ' (' . $user['login'] . ')';
}, 10);
$name = events()->filter('user.display_name', $user['name'], $user); // the value itself when no filter exists
Each filter gets the value and the extra arguments of filter() and returns the new value. Priorities and *
names work as for events; events()->stop() in a filter makes the value it returns the result. Filters and events are
apart: fire() never calls a filter. has_filters(), get_filters() and forget_filter()
complete the API.
Subscribers
A class can list what it handles; events()->subscribe($object) (or a class name for _class()) registers
its methods:
class social_events
{
public function subscribed_events()
{
return [
'user.registered' => 'on_registered',
'user.login' => ['on_login', 10], // with a priority
'comment.added' => [['on_comment', 5], 'count_comment'], // several methods
];
}
public function subscribed_filters()
{
return ['user.display_name' => 'display_name'];
}
}
Listeners in plugin.json (loaded on demand)
The files events/<name>.listener.php of a plugin (or share/events/) are loaded on every request, as
before; a listener file with the same name in the project replaces the plugin's. A plugin can instead declare its listeners in
plugin.json: the class is loaded only when the event fires, so a plugin with many listeners costs nothing on pages that do
not fire them.
"provides": {
"listeners": {
"user.registered": "social_events::on_registered",
"user.login": ["social_events::on_login", {"handler": "social_presence::on_login", "priority": 10}],
"comment.*": "social_feed::on_comment"
},
"filters": {"user.display_name": "social_events::display_name"},
"events": {"social.friend_added": "user_id, friend_id"}
}
The class must be the plugin's own (<plugin> or <plugin>_*, loaded with _class()), the
priority an integer. Every plugin's listeners of an event run. A refused entry is reported by the doctor (plugin manifests check) and
ignored. events documents the events the plugin fires: they appear in the catalogue and in events:list.
Profile tabs and actions, privacy
Plugins add to the stock pages through filters instead of overriding their classes; firing them with no listener changes nothing on the page.
// buttons under the name on the user profile (./?object=user_profile&id=...)
events()->listen_filter('user_profile.actions', function ($actions, $owner_id, $viewer_id, $user) {
$actions['message'] = ['label' => 'Message', 'url' => './?object=chat&action=start&user_id=' . (int) $owner_id, 'title' => ''];
return $actions;
});
// sections after the stock ones of the profile
events()->listen_filter('user_profile.tabs', function ($tabs, $owner_id, $viewer_id, $user) {
$tabs['wall'] = ['title' => 'Wall', 'html' => '<div>' . _prepare_html($text) . '</div>'];
return $tabs;
});
Both get the items (name => item), the profile owner's id, the viewer's id (0: a guest) and the owner's user row. An action's
label and title are text, translated and escaped by core; its url must be a link of this site
(./ or one /), anything else is dropped. A tab's title is text, its html is printed as it is:
the listener escapes what it puts there. A site with its own user_profile/main.stpl adds {profile_actions}
and {profile_tabs} where it wants them (the stock template has them after the name and after the last section).
The profile used to probe a friends module for its Friends and Friend Of sections.
$PROJECT_CONF['user_profile']['FRIENDS_PROBE'] = false (default true, false in 4.0) drops the probe and
those sections: a relations plugin shows its own through user_profile.tabs.
_class('user_privacy')->can_contact($from_id, $to_id); // filter user.can_contact ($allowed, $from_id, $to_id)
_class('user_privacy')->can_view($viewer_id, $owner_id, 'friends'); // filter user.can_view ($allowed, $viewer_id, $owner_id, $what)
Core keeps no relations or privacy settings: both answers start true and the plugins that keep them narrow them (the social
plugin answers false across a block, chat asks user.can_contact before a message). A filter should only narrow:
return $allowed && .... $what is a name the caller picks (profile, friends,
social.wall).
$PROJECT_CONF['user_profile']['PRIVACY_CHECK'] = true (default false: every active
profile shows, as before) makes the profile ask can_view($viewer_id, $owner_id, 'profile'); on false it shows
"You are not allowed to view this profile" instead of the page. The owner always sees their own profile.
User menu
The user layouts (bs3, bs5, tailwind) print the links of the filter user_menu.items after the welcome link of a logged-in
user, before Logout ({execute(graphics,show_user_menu)}; a site with its own layout adds that tag).
events()->listen_filter('user_menu.items', function ($items, $user_id, $user) {
$items['messages'] = ['label' => 'Messages', 'url' => './?object=chat', 'title' => ''];
return $items;
});
The items are those of user_profile.actions: label and title are text (translated and escaped by
core), url a link of this site (./ or one /), anything else is dropped. Guests and the admin side
get no user menu; with no item the layout is as it was.
Content render
The filter content.render ($html, $context) gets user and page text as it is about to be shown: the text of each
comment of the comment lists (context type comment, id, object_name, object_id,
user_id) and the text of a static page (type static_page, id, name). Use it
for mentions, emoji, link previews.
events()->listen_filter('content.render', function ($html, $ctx) {
return $ctx['type'] === 'comment' ? $html . ' <span class="badge">' . _prepare_html($label) . '</span>' : $html;
});
$html is already escaped HTML (a comment: escaped text or BB code output; a page: the page HTML the admin wrote). A
listener keeps it safe: it never un-escapes it, escapes everything it adds (_prepare_html(), which also escapes
template braces) and returns a string; any other answer keeps the text. With no listener the text is as before.
Template slots
{slot(name)} in a yf template (both the interpreting and the compiled mode; {{ slot('name') }} in
twig) prints what the listeners of tpl.slot.<name> return, joined with new lines, so several plugins add to one place of a
page; with no listener it prints nothing. A name is lower case letters, digits, _ and dots; any other prints nothing and
warns once. PHP code calls tpl()->slot('name', $context).
events()->listen('tpl.slot.admin.user_view', function ($ctx) {
// $ctx: ['slot' => 'admin.user_view', 'user_id' => 12]; a template tag passes ['slot', 'tpl' => its name, 'vars' => its variables]
return '<div class="panel">' . _prepare_html(t('Orders')) . ': ' . (int) count_orders($ctx['user_id']) . '</div>';
});
A listener returns HTML: it escapes every value it prints (_prepare_html(), (int)). The output is never
parsed as template tags, and a template variable reaches the listener as data, never in the event name: slot names are written in the
template. Slots of the framework: admin.user_view under the user form of the admin (?object=manage_users&action=edit,
context user_id); user_profile.header (under the name and the profile actions) and user_profile.footer
(after the last section) of the user profile, a template tag whose vars hold owner_id and viewer_id.
WILDCARD_FIX
$PROJECT_CONF['core_events']['WILDCARD_FIX'] = true (default false, on in 4.0): listen() with an array of
names registers every one of them (without it the names after the first wildcard get no listener), forget('name.*') also
removes that wildcard listener, wildcard listeners run by their priority among the named ones (without it they always run after
them, priority ignored) and has_listeners() also sees a matching wildcard listener. listening() sees both
either way.
Catalogue
The events the framework fires are in plugins/sys/share/events_catalogue.php; events()->catalogue() adds the
provides.events of the plugins. The domain events (since 2026-12) each pass one array:
| Event | Payload | Fired by |
|---|---|---|
user.registered | user_id, login, email, active, source (register, admin, oauth) | registration form, admin add user, a new oauth account |
user.login | user_id, group_id, ip | a user login (form, remember-me, oauth), before the redirect |
user.login_failed | login, reason, ip, user_id | every failed user login, also when failures are not logged; never the password |
user.logout | user_id | a user logout, before the session is cleared |
user.updated | user_id, fields, source | admin edit user and the active switch |
user.deleted | user_id, login, email, source | admin delete user, after the row is deleted |
user.password_changed | user_id, source (reset) | the password reset page |
admin.login, admin.login_failed, admin.logout | as the user ones, with admin_id | admin login, every failed one, logout |
comment.added | comment_id, object_name, object_id, parent_id, user_id | the comments form, after the insert |
media.stored | path, name, size, type, url, user_id, admin_id, source (form2); media_id, context, owner_type, owner_id, kind, status, source (media) | the upload widget of form2, after a file is stored; the media service, after the master is written. Two payload shapes: a listener checks source (form2 or media) before it reads the other keys |
media.ready, media.failed, media.removed, media.erased, media.infected | media_id, context and variants / error / reason, by; user_id, count; signature | the media service: styles written (or a media job done), a failed store or job, remove(), erase_user(), clamd found something (the media stays quarantined) |
media.can_view, media.before_store, media.contexts (filters) | allowed, row, viewer user id / verdict {ok, error}, file info / contexts | the media service: every gate request, before a file is stored, the context list |
user_profile.tabs, user_profile.actions (filters) | items, owner_id, viewer_id, user row | the user profile page |
user.can_contact, user.can_view (filters) | allowed, from_id, to_id / allowed, viewer_id, owner_id, what | _class('user_privacy') |
user_menu.items (filter) | items, user_id, user row | the user menu of the user layouts |
content.render (filter) | html, context {type, id, ...} | comment text, static page text |
tpl.slot.<name> | slot and its context | {slot(name)}, tpl()->slot() |
payment.operation_status | operation_id, status_id, old_status_id | payment_api->operation_update() when the status changes |
vendor/bin/yf events:list prints every known event with its plugin, the number of listeners and filters
registered after boot, and the payload; --json gives the same as JSON.
Legacy method hooks
Some callers look for methods by name in module classes: _hook_title, _hook_meta, _hook_side_column,
_hook_widget_*, _hook_settings, _hook_sitemap / _site_map_items, _hook_wall_link,
_hook_debug, _nav_bar_items, _on_delete_account. They keep working as they are and will not be
removed without a major release, but no new ones are added: a new extension point is an event or a filter.