Controlling Default Email Preferences for Users on a BuddyPress based site
Do you want to control the default email preferences for Users on your BuddyPress based site. Well, if you have used BuddyPress, you already know that a user can control his/her email preferences by visiting Settings->Email ( before 1.9, It was settings->Notification) as shown below:-
Now, the problem arises when you want to set a default preference for user before they update it on their own. BuddyPress does not have a hook to control the default behaviour.
The way it can be controlled is by updatingย user metaย with appropriate settings when a user activates his/her account. Thanks to Ben (@somesu) I got the idea to provide the site admins the control to set the default preference.
Option 1: Use code to set the default preference.
Here is the code that you can put in your bp-custom.php to manage the preference
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | /** * Sets default notification preference for the user. * * @param int $user_id user id. */ function bpdev_set_email_notifications_preference( $user_id ) { // I am putting all the notifications to no by default // you can set the value to 'yes' if you want that notification to be enabled. $settings_keys = array( 'notification_activity_new_mention' => 'no', 'notification_activity_new_reply' => 'no', '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' => 'no', ); foreach ( $settings_keys as $setting => $preference ) { bp_update_user_meta( $user_id, $setting, $preference ); } } add_action( 'bp_core_activated_user', 'bpdev_set_email_notifications_preference' ); |
Option 2: ย BP Default Email Notification Settings Control plugin
If you are not comfortable with the code, I have put a plugin for our BuddyDev Members which gives admin the control to set the default preference for newly registered users.
Here is a screenshot to show the admin panel of the plugin:-
If you are a BuddyDev Premium member, you can download the plugin from here
Download & Installation:-
https://buddydev.com/plugins/bp-default-email-notification-settings-control/
I hope the code helps you ย ๐ Please do let me know your thoughts in comment.
If only this worked for existing users.
Hi Russ,
Thank you for the comment.
That is my plan for next plugin but the only issue is users won't be able to override those settings. Initially we don't know whether a user has updated his/her settings or not. If we can detect that it will be super easy to do that.
I recently sent you an email requesting some help with one of your plugins that you helped me out with earlier. Please reply as soon as possible, for this plugin malfunctioning issue is impairing key features my site at this moment.
Wow… Thanks @sbrajesh for this plugin…
Now i have set it up per code – my membership is at the moment expired – but i think it is a great plugin for all of us? ๐
Hi Ben,
Thank you. Glad you implemented it and hope it certainly helps ๐
About membership, Just sent you a Pm ๐
Hi @sbrajesh,
thanks for your reply… and yes, it helps… ๐
I have many ideas for plugins – but i don't have the skills to do that… xD
now, i'm waiting for your Pm… ๐
Thank you. It is in your inbox now ๐
Looking forward to work with you on some of your ideas ๐
Thank you, @sbrajesh… ๐
I will get in touch with you, via pm the next days. ๐