Elgg\Database\AdminNotices::add PHP Method

add() public method

Useful to alert the admin to take a certain action. The id is a unique ID that can be cleared once the admin completes the action. eg: add_admin_notice('twitter_services_no_api', 'Before your users can use Twitter services on this site, you must set up the Twitter API key in the Twitter Services Settings');
public add ( string $id, string $message ) : boolean
$id string A unique ID that your plugin can remember
$message string Body of the message
return boolean
    function add($id, $message)
    {
        if (!$id || !$message) {
            return false;
        }
        if (elgg_admin_notice_exists($id)) {
            return false;
        }
        // need to handle when no one is logged in
        $old_ia = elgg_set_ignore_access(true);
        $admin_notice = new \ElggObject();
        $admin_notice->subtype = 'admin_notice';
        // admins can see ACCESS_PRIVATE but no one else can.
        $admin_notice->access_id = ACCESS_PRIVATE;
        $admin_notice->admin_notice_id = $id;
        $admin_notice->description = $message;
        $result = $admin_notice->save();
        elgg_set_ignore_access($old_ia);
        return (bool) $result;
    }