Skip to:
Content
Pages
Categories
Search
Top
Bottom

Get Notification Format Empty


  • Andrew Tibbetts
    Participant

    @andrewgtibbetts

    I am trying to add a new notification for all members of a group when a new user joins a group. I have registered a new dummy component, can successfully get the notification into the db, but returning the notification for formatting / display comes up empty. Here’s my code:

    
    add_filter( 'bp_notifications_get_registered_components', 'custom_bp_notifications_get_registered_components' );
    function custom_bp_notifications_get_registered_components( $component_names = array() ) {
     
    	if ( ! is_array( $component_names ) ) {
    
    		$component_names = array();
    	}
     
    	array_push( $component_names, 'custom' );
     
    	return $component_names;
    }
    
    add_action( 'groups_join_group', 'custom_groups_join_group', 10, 2 );
    function custom_groups_join_group( $group_id, $user_id ) {
    	
    	if ( bp_is_active( 'notifications' ) ) {
    		
    		if ( bp_group_has_members( 'group_id='.$group_id.'&per_page=10000000' ) ) {
    			
    			while ( bp_group_members() ) {
    				
    				bp_group_the_member();
    				
    				if ( bp_get_group_member_id() != $user_id ) {
    
    					bp_notifications_add_notification(array(
    						'user_id' 		=> bp_get_group_member_id(),
    						'item_id' 		=> $group_id,
    						'secondary_item_id' 	=> $user_id,
    						'component_name' 	=> 'custom',
    						'component_action' 	=> 'custom_group_join',
    						'date_notified' 	=> bp_core_current_time(),
    						'is_new' 		=> 1,
    					));
    				}
    			}
    		}
    	}
    }
    
    add_filter( 'bp_notifications_get_notifications_for_user', 'custom_bp_notifications_get_notifications_for_user', 10, 5 );
    function custom_bp_notifications_get_notifications_for_user( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
    
    	if ( $action === 'custom_group_join' ) {
    
    		$group_id = $item_id;
    		$joining_user_id = $secondary_item_id;
    
    		$group = groups_get_group( array( 'group_id' => $group_id ) );
    		$group_link = bp_get_group_permalink( $group );
    
    		$user_fullname = bp_core_get_user_displayname( $joining_user_id );
    		$user_link = bp_core_get_user_domain( $joining_user_id );
    
    		$text = $user_fullname . ' joined the group ' . $group->name;
    		$notification_link = $group_link . 'admin/membership-requests/?n=1';
    		
    		if ( 'string' === $format ) {
    
    			$return = apply_filters(
    				'bp_groups_' . $action . '_notification', '<a href="' . $user_link . '" title="' . $user_fullname . '">' . $user_fullname . '</a> joined the group <a href="' . $group_link . '" title="' . $group->name . '">' . $group->name . '</a>', $group_link, $user_fullname, $group->name, $text, $notification_link );
    		}
    		else {
    
    			$return = apply_filters( 'bp_groups_' . $action . '_notification', array(
    				'link' => $notification_link,
    				'text' => $text
    			), $group_link, $user_fullname, $group->name, $text, $notification_link );
    		}
    	
    		return $return;
    	}
    }
    
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar