Skip to:
Content
Pages
Categories
Search
Top
Bottom

allow the duplicate notications


  • ganesh641
    Participant

    @ganesh641

    I am using bp_core_add_notification () to add the notification in buddypress Version 2.2.1

    bp-notifications-functions.php

    file has the following code to add the notification.

    
    function bp_notifications_add_notification( $args = array() ) {
    
    	$r = wp_parse_args( $args, array(
    		'user_id'           => 0,
    		'item_id'           => 0,
    		'secondary_item_id' => 0,
    		'component_name'    => '',
    		'component_action'  => '',
    		'date_notified'     => bp_core_current_time(),
    		'is_new'            => 1,
    		'allow_duplicate'   => false,
    	) );
    
    	// Check for existing duplicate notifications
    	if ( ! $r['allow_duplicate'] ) {
    		// date_notified, allow_duplicate don't count toward
    		// duplicate status
    		$existing = BP_Notifications_Notification::get( array(
    			'user_id'           => $r['user_id'],
    			'item_id'           => $r['item_id'],
    			'secondary_item_id' => $r['secondary_item_id'],
    			'component_name'    => $r['component_name'],
    			'component_action'  => $r['component_action'],
    			'is_new'            => $r['is_new'],
    		) );
    
    		if ( ! empty( $existing ) ) {
    			return false;
    		}
    	}
    
    	// Setup the new notification
    	$notification                    = new BP_Notifications_Notification;
    	$notification->user_id           = $r['user_id'];
    	$notification->item_id           = $r['item_id'];
    	$notification->secondary_item_id = $r['secondary_item_id'];
    	$notification->component_name    = $r['component_name'];
    	$notification->component_action  = $r['component_action'];
    	$notification->date_notified     = $r['date_notified'];
    	$notification->is_new            = $r['is_new'];
    
    	// Save the new notification
    	return $notification->save();
    }

    In the above code they check the duplicate notification
    I need to add the duplicate notification in the bp_notificaion table without affecting the core functionality. Any help should be appreciated

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

  • shanebp
    Moderator

    @shanebp

    It would be nice if there was an apply_filter hook before the check of the allow_duplicate field.

    If you are adding a custom notification, then sending in a true value is easy.
    But there is no feasible way for existing functions, afaik, to filter the calls to bp_notifications_add_notification.

    Adding the filter hook in bp_notifications_add_notification is simple.
    But will require submitting an enhancement ticket.


    ganesh641
    Participant

    @ganesh641

    Thanks you @shanebp.


    ganesh641
    Participant

    @ganesh641

    Thanks in advance… Any other Solution? to archive this

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘allow the duplicate notications’ is closed to new replies.
Skip to toolbar