How to Create Custom Notifications in BuddyBoss Platform

In BuddyBoss, notifications are a great way to keep users engaged with the platform. Whether it’s a new message, a comment on a post, or a mention, notifications keep users informed about important activities. But what if you want to create custom notifications tailored specifically for your site? In this blog post, we will explore how to create custom notifications using BuddyBoss’s Modern Notifications API. We’ll dive into a simple example that registers a custom notification type, sets up email schemas, and formats the notification content for both frontend and backend.


What is BuddyBoss Modern Notifications API?

BuddyBoss’s Modern Notifications API is an advanced way to manage and display notifications across your platform. With this API, you can create custom notifications, register them for different actions (like posts or messages), and define how and when they should be delivered—whether as push notifications, emails, or in the notification center.


Setting Up a Custom Notification Class

In order to create a custom notification in BuddyBoss, we first need to define a custom class that extends BP_Core_Notification_Abstract. This abstract class is essential because it contains various methods that handle the registration and management of notifications.

Let’s break down the code and understand how it works.


1. Define the Custom Notification Class

The first step is to define a class that extends BP_Core_Notification_Abstract. In our case, we’ve named it BP_Custom_Notification. This class will be responsible for handling custom notifications.

We also define a static instance of the class to implement the singleton pattern.

This ensures only one instance of the class is created, which is a good practice for performance and memory management.


2. Initialize Methods with the load() Function

Once the class is defined, we need to initialize everything within the load() method. This includes registering the notification group, custom notification types, and email schemas.

This method sets up a notification group called “custom” that handles both the frontend and backend notifications.


3. Register Custom Notification

We can then create the custom notification using register_notification_type(), where we define its type, label, and admin label.

This registers a notification type with the key notification_custom, which can be used later in the notification setup.


4. Define Email Schema

For emails, BuddyBoss allows us to register custom email templates using register_email_type(). This can be done with placeholders for the email subject, content, and unsubscribe text.

This schema ensures that when a user receives a notification, they are given an option to unsubscribe if they no longer wish to receive such notifications.


5. Register Push Notifications

Next, we can register the notification for different delivery channels (like push notifications) and set how the content will be displayed.

This line binds the custom notification action to the notification_custom type, ensuring the notification is triggered when that specific action happens.


6. Filter Custom Notifications

We also register a notification filter. Filters allow users to choose how they want to receive certain notifications. You can modify the filter’s label and the notification types it applies to.

This filter helps users fine-tune their notification preferences on your site.


7. Formatting Notification Content

Finally, we format the notification content. The format_notification() method is responsible for customizing the text, links, and handling different types of notifications (like web or app push notifications).

This function changes the notification’s content based on the screen type, ensuring that push notifications have specific text content for mobile and web users.


Conclusion

Creating custom notifications in BuddyBoss is a powerful way to tailor the user experience and ensure that users receive the information they need in a timely manner. By utilizing the Modern Notifications API, you can register custom notification types, design email templates, and manage notification delivery across different platforms. With this, you can fully customize how your site communicates with users, providing them with a more personalized and engaging experience.

We hope this guide has helped you understand how to create custom notifications in BuddyBoss. Happy coding!

Crazy about CRO?

Join & get tip & tricks for eCommerce CRO

We don’t spam! Read more in our privacy policy

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *