Skip to:
Content
Pages
Categories
Search
Top
Bottom

turn off email notifictions in functions.php


  • 5high
    Participant

    @5high

    Hi,

    I’ve found some info about turning off email notifications by default for new users (here: https://buddypress.org/support/topic/how-to-disable-email-notification-to-all-newly-registered-users/) and would like to check 4 things.

    The 2 code options referenced there are these, added to the child theme functions.php:
    1.

    function bp_set_notification_default( $user_id ) {
        $keys = array( 'notification_activity_new_mention', 'notification_activity_new_reply', 'notification_friends_friendship_accepted', 'notification_friends_friendship_request', 'notification_groups_admin_promotion', 'notification_groups_group_updated', 'notification_groups_invite', 'notification_groups_membership_request', 'notification_messages_new_message', 'notification_messages_new_notice' );
    
        foreach ( $keys as $key ) {
            update_user_meta( $user_id, $key, 'no' );
        }
    }
    add_action( 'bp_core_signup_user', 'bp_set_notification_default', 100, 1 );

    2.

    add_action('bp_core_signup_user','bp_set_notification_default',100,1);
      function bp_set_notification_default($user_id) {
        $keys = array('notification_activity_new_mention','notification_activity_new_reply','notification_friends_friendship_accepted','notification_friends_friendship_request','notification_groups_admin_promotion','notification_groups_group_updated','notification_groups_invite','notification_groups_membership_request','notification_messages_new_message','notification_messages_new_notice');
        foreach($keys as $key) {
          update_user_meta($user_id,$key,'no');
        }
    }

    So my questions are:

    1. which code should be used?
    2. Is this code still OK since the recent BP updates?
    3. Does it turn off email notifications to admin for new user signups too?
    4. If so, how can I keep just that functionality on?

    Many thanks.

Viewing 9 replies - 1 through 9 (of 9 total)

  • 5high
    Participant

    @5high

    Update:

    well i’ve just tested option #1 and it didn’t work – my test new user had all email notifications still set to ON as the default.

    and # 2 code didn’t work either – all set to ON.

    Maybe @henrywright or @nd1 could throw some light on this if possible, as their thread is now closed??

    Or any other ideas would be much appreciated – thanks heaps.


    5high
    Participant

    @5high

    Does anyone know how to do this? @nd1 can you share your solution?
    Cheers.


    5high
    Participant

    @5high

    Ok I’ve searched the BP codex, all the BP forum again and the i/net and basically got nowhere. I’ve tried a few more times and new (test) members are still having email notification ON by default, so it’s definitely not working.

    I’ve tracked down 2 files that seem to be involved in this and they are:-
    buddypress/bp-notifications/bp-notifications-functions.php
    buddypress/bp-activity/bp-activity-notifications.php

    Please can someone help me here? From searching it’s obviously a common request – but no answer anywhere!

    Waiting hopefully…


    danbp
    Participant

    @danbp

    hi @5high,

    users default email settings concern

    • activity
    • messages
    • friends
    • groups

    Each has is own screen template.

    ie. activity is in /bp-activity/bp-activity-screen.php

    In each xxx-screen.php there is a function containing the variables and the html for the checkboxes.

    Respective functions are:

    • bp_activity_screen_notification_settings()
    • messages_screen_notification_settings
    • friends_screen_notification_settings()
    • groups_screen_notification_settings()

    You copy those 4 functions into your child-theme functions.php
    and rename each to my_something.

    ie. my_bp_activity_screen_notification_settings()

    At the end of each function you’ll see the action hook, which you rename accordingly
    ie.
    add_action( 'bp_notification_settings', 'bp_activity_screen_notification_settings', 1 );
    wil be changed to
    add_action( 'bp_notification_settings', 'my_bp_activity_screen_notification_settings', 1 );

    Before this line, you add the remove_action action. ie.

    // removing the original action
    remove_action( 'bp_notification_settings', 'bp_activity_screen_notification_settings', 1 );
    
    // add our custom action
    add_action( 'bp_notification_settings', 'my_bp_activity_screen_notification_settings', 1 );

    Now we have to modify in each function the default Yes to No.

    At the begin of each, you’ll see some conditionnals begining by if(someting….)

    ie. activity-screen you have:

    • $mention = 'yes';
    • $reply = 'yes';

    Simply change that to no, save, and you’re done.

    Hope this helps ! 😉


    shanebp
    Moderator

    @shanebp


    danbp
    Participant

    @danbp

    hi @shanebp

    thxs for that, much simplier solution…

    Except when OP goes to settings, all is marked YES by default. Mine shows NO. So i think it doesn’t “work” as expected. Did you tested ?

    Anyway, in both case, it’s firstly a visual effect until new registered user save his settings.


    shanebp
    Moderator

    @shanebp

    @danbp

    I’ve used it and got the expected results.

    Tested with new user and bulk changing.

    Note: using the activation hook may not work depending on how registration is handled.
    Changing the hook being used from bp_core_activated_user to user_register should cover all situations.


    5high
    Participant

    @5high

    Thanks so much @danbp for the in depth tutorial – it does mean that I will start to learn a bit more about how it all works! And to @shanebp for the link and the advice… I will reread it and work through it all over the next few days, test and get back with the working formula (I hope), ready for others to use.
    Cheers.


    5high
    Participant

    @5high

    Brilliant! It worked a treat, and I used the ‘user_register’ as suggested. So for anyone else looking for this solution, this is the code i used to turn some on and some off by default on new user registration:

    add_action( 'user_register', 'bpdev_set_email_notifications_preference');
    function bpdev_set_email_notifications_preference( $user_id ) {
    //I am putting some notifications to no by default and the common ones to yes to enable it.
    //ref. https://bp-tricks.com/snippets/changing-default-buddypress-notifications-settings and BP forum
    $settings_keys = array(
    'notification_activity_new_mention' => 'yes',
    'notification_activity_new_reply' => 'yes',
    'notification_friends_friendship_request' => 'no',
    'notification_friends_friendship_accepted' => 'no',
    'notification_groups_invite' => 'no',
    'notification_groups_group_updated' => 'no',
    'notification_groups_admin_promotion' => 'no',
    'notification_groups_membership_request' => 'no',
    'notification_messages_new_message' => 'yes',
    );
    foreach( $settings_keys as $setting => $preference ) {
    bp_update_user_meta( $user_id, $setting, $preference );
    }
    }

    and this went in my child theme functions.php file.
    Hooray! Thanks so much again – it will make a big different to our users experience.
    Cheers 🙂

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘turn off email notifictions in functions.php’ is closed to new replies.
Skip to toolbar