Notifications

Hi

I am struggling with the docs to be able to send generic notifications.

I just want to know how to send a generic notification like "Today is the site's anniversary!" to a given user that we know his id(guid).

 

Thanks in advance

Higros

  • Thank you Ismayil, could you kindly post an example to send a simple notification like the one I posted? Better than the one at the elgg master docs if possible?

     

    thanks so much

  • tried this, not working

     

        $settings = get_user_notification_settings($params['user']->guid);
        set_user_notification_setting($params['user']->guid, 'notifier', 'on');
        notify_user($params['user']->guid, $params['user']->guid, elgg_echo("the subject"), elgg_echo("danger"));
        set_user_notification_setting($params['user']->guid, $settings, 'on');

     

  • There should be no need to alter notification settings.

    If you want to send an email notifications to a user regardless if the user has enabled email notifications in the user settings, try

    notify_user(
        $params['user']->guid,
        $params['user']->guid,
        "the subject",
        "danger",
        array(),
        "email"
    );

    For email and site notifications it should work with

    notify_user(
        $params['user']->guid,
        $params['user']->guid,
        "the subject",
        "danger",
        array(),
        array("site", "email")
    );

    and if you want to send a notification only by methods enabled by the user in the settings it would be

    notify_user(
        $params['user']->guid,
        $params['user']->guid,
        "the subject",
        "danger",
    );

    Subject and message body parameters are strings. Use elgg_echo() only if you have defined the referred language strings in the language file of your plugin. And in this case it's the language strings key (= the string on the left of => you need to use in elgg_echo()).

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking