The generic method to send a notification to a user is via the function notify_user().
It is normally used when we want to notify only a single user. Notification like
this might for example inform that someone has liked or commented the user’s post.

In this example a user ($user) is triggering an action to rate a post created
by another user ($owner). After saving the rating (ElggAnnotation$rating)
to database, we could use the following code to send a notification about the new
rating to the owner.

// Subject of the notification$subject=elgg_echo('ratings:notification:subject',array(),$owner->language);// Summary of the notification$summary=elgg_echo('ratings:notification:summary',array($user->name),$owner->language);// Body of the notification message$body=elgg_echo('ratings:notification:body',array($user->name,$owner->name,$rating->getValue()// A value between 1-5),$owner->language);$params=array('object'=>$rating,'action'=>'create','summary'=>$summary);// Send the notificationnotify_user($owner->guid,$user->guid,$subject,$body,$params);

Note

The language used by the recipient isn’t necessarily the same as the language of the person
who triggers the notification. Therefore you must always remember to pass the recipient’s
language as the third parameter to elgg_echo().

Note

The 'summary' parameter is meant for notification plugins that only want to display
a short message instead of both the subject and the body. Therefore the summary should
be terse but still contain all necessary information.

On large sites there may be many users who have subscribed to receive notifications
about a particular event. Sending notifications immediately when a user triggers
such an event might remarkably slow down page loading speed. This is why sending
of such notifications shoud be left for Elgg’s notification queue.

New notification events can be registered with the elgg_register_notification_event()
function. Notifications about registered events will be sent automatically to all
subscribed users.

This is the workflow of the notifications system:

Someone does an action that triggers an event within Elgg

The action can be create, update or delete

The target of the action can be any instance of the ElggEntity class (e.g. a Blog post)

The notifications system saves this event into a notifications queue in the database

When the pluging hook handler for the one-minute interval gets triggered, the event is taken from the queue and it gets processed

Subscriptions are fetched for the user who triggered the event

By default this includes all the users who have enabled any notification method
for the user at www.site.com/notifications/personal/<username>

Plugins are allowed to alter the subscriptions using the [get,subscriptions] hook

Plugins are allowed to terminate notifications queue processing with the [send:before,notifications] hook

Plugins are allowed to alter the notification parameters with the [prepare,notification] hook

Plugins are allowed to alter the notification subject/message/summary with the [prepare,notification:<action>:<type>:<subtype>] hook