Skip to:
Content
Pages
Categories
Search
Top
Bottom

Return value in bbp_format_buddypress_notifications()


  • LikeBtn
    Participant

    @likebtn

    Hi,

    bbp_format_buddypress_notifications() function in /wp-content/plugins/bbpress/includes/extend/buddypress/notifications.php must always return something at least empty string.

    We need to use “bp_notifications_get_notifications_for_user” filter to make our own custom notification for BuddyPress but bbp_format_buddypress_notifications() function returning nothing makes it impossible.

    Check this out: https://webdevstudios.com/2015/10/06/buddypress-adding-custom-notifications/#comment-84455

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

  • LikeBtn
    Participant

    @likebtn

    This seems to be a serious BuddyPress bug.
    Check this out: https://buddypress.trac.wordpress.org/ticket/6669#comment:8


    Pascal Casier
    Moderator

    @casiepa

    Hi,
    A trac ticket was already registered for that. The full fix should be included in the upcoming 2.6. If not the wordaround is also mentioned in the ticket.

    https://bbpress.trac.wordpress.org/ticket/2779

    Pascal.


    LikeBtn
    Participant

    @likebtn

    Here is the hack we are using to make our custom filter work:

    <?php
    
    function likebtn_notifications_get_notifications_for_user($action, $item_id, $secondary_item_id, $total_items, $format = 'string')
    {
        global $wp_filter;
    
    	$return = '';
    
        if (count($m) == 3) {
    		// Do something here
    
            // We modify global wp_filter to call our bbPress wrapper function
            if (isset($wp_filter['bp_notifications_get_notifications_for_user'][10]['bbp_format_buddypress_notifications'])) {
                $wp_filter['bp_notifications_get_notifications_for_user'][10]['bbp_format_buddypress_notifications']['function'] = 'likebtn_bbp_format_buddypress_notifications';
            }
    
        	return $return;
        }
    
        return $action;
    }
    // bbPres has a bug: 
    // https://bbpress.org/forums/topic/return-value-in-bbp_format_buddypress_notifications/
    // https://buddypress.trac.wordpress.org/ticket/6669
    // Filter must be called before corresponding bbPress filter
    add_filter('bp_notifications_get_notifications_for_user', 'likebtn_notifications_get_notifications_for_user', 5, 5);
    
    // Wrapper for bbp_format_buddypress_notifications function as it is not returning $action
    function likebtn_bbp_format_buddypress_notifications($action, $item_id, $secondary_item_id, $total_items, $format = 'string')
    {
        $result = bbp_format_buddypress_notifications($action, $item_id, $secondary_item_id, $total_items, $format);
        if (!$result) {
            $result = $action;
        }
        return $result;
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Skip to toolbar