bbp_format_buddypress_notifications

Format the BuddyBar/Toolbar notifications.

Description

bbp_format_buddypress_notifications( (string) $action, (int) $item_id, (int) $secondary_item_id, (number) $total_items, (string) $format = 'string' ); 

Parameters (5)

0. $action (string)
The kind of notification being rendered
1. $item_id (int)
The primary item id
2. $secondary_item_id (int)
The secondary item id.
3. $total_items (number)
The total number of messaging-related notifications waiting for the user
4. $format — Optional. (string) => 'string'
'string' for BuddyBar-compatible notifications; array for WP Toolbar

Usage

  1. if ( !function_exists( 'bbp_format_buddypress_notifications' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/extend/buddypress/notifications.php'; 
  3.  
  4. // The kind of notification being rendered 
  5. $action = ''; 
  6.  
  7. // The primary item id 
  8. $item_id = -1; 
  9.  
  10. // The secondary item id. 
  11. $secondary_item_id = -1; 
  12.  
  13. // The total number of messaging-related notifications waiting for the user 
  14. $total_items = null; 
  15.  
  16. // 'string' for BuddyBar-compatible notifications; 'array' for WP Toolbar 
  17. $format = 'string'; 
  18.  
  19. // NOTICE! Understand what this does before running. 
  20. $result = bbp_format_buddypress_notifications($action, $item_id, $secondary_item_id, $total_items, $format); 
  21.  

Defined (1)

The function is defined in the following location(s).

/includes/extend/buddypress/notifications.php  
  1. function bbp_format_buddypress_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) { 
  2.  
  3. // New reply notifications 
  4. if ( 'bbp_new_reply' === $action ) { 
  5. $topic_id = bbp_get_reply_topic_id( $item_id ); 
  6. $topic_title = bbp_get_topic_title( $topic_id ); 
  7. $topic_link = wp_nonce_url( add_query_arg( array( 'action' => 'bbp_mark_read', 'topic_id' => $topic_id ), bbp_get_reply_url( $item_id ) ), 'bbp_mark_topic_' . $topic_id ); 
  8. $title_attr = __( 'Topic Replies', bbpress ); 
  9.  
  10. if ( (int) $total_items > 1 ) { 
  11. $text = sprintf( __( 'You have %d new replies', bbpress ), (int) $total_items ); 
  12. $filter = 'bbp_multiple_new_subscription_notification'; 
  13. } else { 
  14. if ( !empty( $secondary_item_id ) ) { 
  15. $text = sprintf( __( 'You have %d new reply to %2$s from %3$s', bbpress ), (int) $total_items, $topic_title, bp_core_get_user_displayname( $secondary_item_id ) ); 
  16. } else { 
  17. $text = sprintf( __( 'You have %d new reply to %s', bbpress ), (int) $total_items, $topic_title ); 
  18. $filter = 'bbp_single_new_subscription_notification'; 
  19.  
  20. // WordPress Toolbar 
  21. if ( 'string' === $format ) { 
  22. $return = apply_filters( $filter, '<a href="' . esc_url( $topic_link ) . '" title="' . esc_attr( $title_attr ) . '">' . esc_html( $text ) . '</a>', (int) $total_items, $text, $topic_link ); 
  23.  
  24. // Deprecated BuddyBar 
  25. } else { 
  26. $return = apply_filters( $filter, array( 
  27. 'text' => $text,  
  28. 'link' => $topic_link 
  29. ), $topic_link, (int) $total_items, $text, $topic_title ); 
  30.  
  31. do_action( 'bbp_format_buddypress_notifications', $action, $item_id, $secondary_item_id, $total_items ); 
  32.  
  33. return $return;