bp_notifications_get_notifications_for_user filter failing
-
I’ve been using bp_notifications_add_notification to add a notification with “component_action”=”activity_liked” for component_name activity. I can see that it is being saved in the database, but when I try to display an entry for it in the notifications view it seems that my callback function never runs. Every example I’ve found online has mirrored my function but it never seems to be called. Do I need to register the component_action or something?
I’ve looked in the buddypress core files and they all seem to pass 8 parameters instead of 5 during apply_filters_ref_array, which I also tried but still my callback wouldn’t run. I’ve tried it every way with no other plugins but buddypress activated and still it fails.
I’m truly lost on how to get this working.
function custom_format_buddypress_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) { // New custom notifications if ( $action == 'activity_liked') { $custom_title = 'activity liked'; $custom_link = '/activity/' . $item_id . '/'; $custom_text = bp_core_get_user_displayname( $secondary_item_id ) . ' liked your activity'; // WordPress Toolbar if ( 'string' === $format ) { $return = apply_filters( 'custom_filter', '<a href="' . esc_url( $custom_link ) . '" title="' . esc_attr( $custom_title ) . '">' . esc_html( $custom_text ) . '</a>', $custom_text, $custom_link ); // Deprecated BuddyBar } else { $return = apply_filters( 'custom_filter', array( 'text' => $custom_text, 'link' => $custom_link ), $custom_link, (int) $total_items, $custom_text, $custom_title ); } } else { $return = $action; } return $return; } add_filter( 'bp_notifications_get_notifications_for_user', 'custom_format_buddypress_notifications', 10, 5 );
- You must be logged in to reply to this topic.