Skip to end of metadata
Go to start of metadata

notify($package, $name, $message, ['error']);

 

Creates an information or error notification that can be displayed in a plugin. This can be used in automated scripts like daemons or cronjobs to notify the user about good or bad news about the status of your plugin.This function is exported, therefore you do not need to prefix the function call with LBLog::.


The $package is the owner of the notification. To show the notification bullet on the plugins page, this needs to be $lbpplugindir.

Inside the package, you can group your notifications by $name. For example, your plugin uses a cronjob and a daemon. Use "cronjob" and "daemon" as names to differentiate these notifications.

The $message is the text that is saved and displayed in the notification.

notify always saves the time you have called notify, so you don't need to place a timestamp in the message.

Parameter

ParameterRequiredBeschreibung
$packagexThis is, where the message belongs to. In a plugin, always use the variable $lbpplugindir.
$namexThe notification group, this notification belongs to.
$messagexThe message to be sent.
['error']

If you omit this parameter, an informational notification is created.

If the parameter is <> undef, an error is created.

Case sensitivity

The content of package and name is case-sensitive. If you set the NAME => "Daemon", you have to query "Daemon" in get_notifications and get_notifications_html.

Usage

require_once "loxberry_log.php";

# Define global $lbpplugindir if you are in a sub, or use the constant LBPPLUGINDIR.
# global $lbpplugindir;

# Create an informational notification for the group "daemon".
notify( $lbpplugindir, "daemon", "The daemon has finished successfully");


# Create an error notification for the group "daemon" (using the constant LBPPLUGINDIR)
notify( LBPPLUGINDIR, "daemon", "The daemon has finished successfully", 1);
notify( LBPPLUGINDIR, "daemon", "The daemon has finished successfully", "error");
# Both calls create an error notification (4th parameter is not undef).


Infos

Please see the Notification tips and tricks


  • No labels