Clear notifications template tag

  • Participant
    Graeme Bryson on #4272

    Hi Brajesh,

    Is there any way to output the ‘Clear Notifications’ function as a button on a page, such as above the notification list, instead of in a dropdown?

    Specifically, I’m looking to create a ‘Clear all notifications’ button above the list in ‘/members/user/notifications’ – is there any way to output the function here?

    Cheers, Graeme

  • Keymaster
    (BuddyDev Team)
    Posts: 24093
    Brajesh Singh on #4284

    Hi Graeme,
    Welcome to Buddydev forums 🙂

    Are you using BuddyPress clear notification plugin? If yes, you can create a function like this and use it anywhere

    function buddydev_clear_notification_button() {
    	if ( !  is_user_logged_in() ) {
    		return ;
    	$user_id = bp_loggedin_user_id();
    	$notifications = bp_notifications_get_notifications_for_user( $user_id );
    	if ( ! $notifications ) {
    		return ;
    	echo '<a id="clear-notifications" href="'.bp_core_get_user_domain( $user_id ).'?clear-all=true&_wpnonce=' . wp_create_nonce('clear-all-notifications-for-'. $user_id ).'"> [x] Clear All Notifications</a>';

    Here is an example to show how to inject it at the top in the notifications screen(It is not the right way, the notification template does not have a hook, so I suggest using the function in the template directly instead of hooking like below)

    function buddydev_inject_clear_button() {
    	if( !  bp_is_notifications_component() ) {
    		return ;
    add_action( 'bp_before_member_body', 'buddydev_inject_clear_button' );

    Hope that helps.
    Please do let me know how it goes?


You must be logged in to reply to this topic.

This topic is: not resolved