Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: Return value in bbp_format_buddypress_notifications()

@likebtn

Participant

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;
}
Skip to toolbar