elgg 3 how to make default site notification on

Hi All

How can we notifications of user for site active by default?

  • You can add this code in elgg-plugin.php of your custom plugin:

    return [
    
        'user_settings' => [
    
              'notification:method:email' => true, //Email notification
    
              'notification:method:site' => true,  //Site notification
    
        ],
    
    ];
  • Ok.. thanks, as such i am not a tech so i will try making a custom plugin,

     

    on the other hand, cant i simply add these codes on any existing path of .php file?

     

    Thanks again

    Cheers!

  • Hi Again

    if i add your given code into /mod/notifications/start.php will that work?

  • It will not work when adding this code in start.php. It MUST be added in elgg-plugin.php because only then you can add this kind of definition. There would be other ways to make it work but they are more complicated.

    In Elgg 3 a plugin does not need a start.php. So, it's really very simply to create a new plugin that only contains the files elgg-plugin.php and manifest.xml. With the code provided by RvR the file elgg-plugin.php would only contain

    <?php
    
    return [
        'user_settings' => [
            'notification:method:email' => true, //Email notification
            'notification:method:site' => true,  //Site notification
        ],
    ];


    and the manifest.xml could be taken from another plugin with only the name and id tags changed, e.g.

    <?xml version="1.0" encoding="UTF-8"?>
    <plugin_manifest xmlns="http://www.elgg.org/plugin_manifest/1.8">
        <name>Notification Default Settings</name>
        <id>notifications_defaults</id>
        <author>Your name</author>
        <version>1.0</version>
        <category>enhancement</category>
        <description>Set default values of site and email notification user settings to on.</description>
        <copyright>(c) Your name</copyright>
        <license>GNU General Public License version 2</license>
        <requires>
            <type>elgg_release</type>
            <version>3.0</version>
        </requires>
    </plugin_manifest>

    assuming the plugin folder name as "notifications_defaults".

    The only thing this plugin would do is setting the default values of site and email notifications to "true", i.e. they are enabled for a user who newly creates an account or has never changed his user's notification settings. If you want the defaults to be different you only have to change the corresponding value for on-site and email notifications in elgg-plugin.php from "true" to "false".

     

  • Hi

    Thanks @iionly and @RvR -- i tried following your inputs, but its xml giving error, please find below screenshot, any help will be really appreciated!

    i created folder named "notifications_defaults" in mod

    then created elgg-plugin.php with mentioned codes

    further manifest.xml and copied your codes and saved

    and created start.php replacing with notifications_defaults with help of this tutorial

     

     

  • Firstly, the start.php file is no longer necessary in all cases for Elgg 3. In this case here you don't need it. It should work without the file being present.

    Secondly, I see no obvious error with the manifest.xml file. The name and file permissions seem alright. Maybe it's a matter of text encoding within the file. Are you sure that you have only the following within the file

    <?xml version="1.0" encoding="UTF-8"?>
    <plugin_manifest xmlns="http://www.elgg.org/plugin_manifest/1.8">
        <name>Notification Default Settings</name>
        <id>notifications_defaults</id>
        <author>Your name</author>
        <version>1.0</version>
        <category>enhancement</category>
        <description>Set default values of site and email notification user settings to on.</description>
        <copyright>(c) Your name</copyright>
        <license>GNU General Public License version 2</license>
        <requires>
            <type>elgg_release</type>
            <version>3.0</version>
        </requires>
    </plugin_manifest>

    with no empty line in the beginning?

    Which text encoding have you saved the file with? If your editor has the option to save in different encodings you should use "UTF without Byte Order Marks". Especially "without Byte Order Marks" (BOMs) is important as there are likely errors if Byte Order Marks are included in the file (these are invisible characters at the beginning of the file).

  • Use this plugin.

    Also, updated My plugin for Elgg 3.

    Enjoy!