bp_activity_format_notifications

Format notifications related to activity.

Description

(string) bp_activity_format_notifications( (string) $action, (int) $item_id, (int) $secondary_item_id, (number) $total_items, (string) $format = 'string', (int) $id = 0 ); 

Returns (string)

$return Formatted @mention notification.

Parameters (6)

0. $action (string)
The type of activity item. Just new_at_mention for now.
1. $item_id (int)
The activity ID.
2. $secondary_item_id (int)
In the case of at-mentions, this is the mentioner's ID.
3. $total_items (number)
The total number of notifications to format.
4. $format — Optional. (string) => 'string'
'string' to get a BuddyBar-compatible notification, array otherwise.
5. $id — Optional. (int)
The notification ID.

Usage

  1. if ( !function_exists( 'bp_activity_format_notifications' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-activity/bp-activity-notifications.php'; 
  3.  
  4. // The type of activity item. Just 'new_at_mention' for now. 
  5. $action = ''; 
  6.  
  7. // The activity ID. 
  8. $item_id = -1; 
  9.  
  10. // In the case of at-mentions, this is the mentioner's ID. 
  11. $secondary_item_id = -1; 
  12.  
  13. // The total number of notifications to format. 
  14. $total_items = null; 
  15.  
  16. // 'string' to get a BuddyBar-compatible notification, 'array' otherwise. 
  17. $format = 'string'; 
  18.  
  19. // Optional. The notification ID. 
  20. $id = -1; 
  21.  
  22. // NOTICE! Understand what this does before running. 
  23. $result = bp_activity_format_notifications($action, $item_id, $secondary_item_id, $total_items, $format, $id); 
  24.  

Defined (1)

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

/bp-activity/bp-activity-notifications.php  
  1. function bp_activity_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string', $id = 0 ) { 
  2. $action_filter = $action; 
  3. $return = false; 
  4. $activity_id = $item_id; 
  5. $user_id = $secondary_item_id; 
  6. $user_fullname = bp_core_get_user_displayname( $user_id ); 
  7.  
  8. switch ( $action ) { 
  9. case 'new_at_mention': 
  10. $action_filter = 'at_mentions'; 
  11. $link = bp_loggedin_user_domain() . bp_get_activity_slug() . '/mentions/'; 
  12. $title = sprintf( __( '@%s Mentions', buddypress ), bp_get_loggedin_user_username() ); 
  13. $amount = 'single'; 
  14.  
  15. if ( (int) $total_items > 1 ) { 
  16. $text = sprintf( __( 'You have %1$d new mentions', buddypress ), (int) $total_items ); 
  17. $amount = 'multiple'; 
  18. } else { 
  19. $text = sprintf( __( '%1$s mentioned you', buddypress ), $user_fullname ); 
  20. break; 
  21.  
  22. case 'update_reply': 
  23. $title = __( 'New Activity reply', buddypress ); 
  24. $amount = 'single'; 
  25.  
  26. if ( (int) $total_items > 1 ) { 
  27. $link = add_query_arg( 'type', $action, $link ); 
  28. $text = sprintf( __( 'You have %1$d new replies', buddypress ), (int) $total_items ); 
  29. $amount = 'multiple'; 
  30. } else { 
  31. $link = add_query_arg( 'nid', (int) $id, bp_activity_get_permalink( $activity_id ) ); 
  32. $text = sprintf( __( '%1$s commented on one of your updates', buddypress ), $user_fullname ); 
  33. break; 
  34.  
  35. case 'comment_reply': 
  36. $title = __( 'New Activity comment reply', buddypress ); 
  37. $amount = 'single'; 
  38.  
  39. if ( (int) $total_items > 1 ) { 
  40. $link = add_query_arg( 'type', $action, $link ); 
  41. $text = sprintf( __( 'You have %1$d new comment replies', buddypress ), (int) $total_items ); 
  42. $amount = 'multiple'; 
  43. } else { 
  44. $link = add_query_arg( 'nid', (int) $id, bp_activity_get_permalink( $activity_id ) ); 
  45. $text = sprintf( __( '%1$s replied to one your activity comments', buddypress ), $user_fullname ); 
  46. break; 
  47.  
  48. if ( 'string' == $format ) { 
  49.  
  50. /** 
  51. * Filters the activity notification for the string format. 
  52. * This is a variable filter that is dependent on how many items 
  53. * need notified about. The two possible hooks are bp_activity_single_at_mentions_notification 
  54. * or bp_activity_multiple_at_mentions_notification. 
  55. * @since 1.5.0 
  56. * @since 2.6.0 use the $action_filter as a new dynamic portion of the filter name. 
  57. * @param string $string HTML anchor tag for the interaction. 
  58. * @param string $link The permalink for the interaction. 
  59. * @param int $total_items How many items being notified about. 
  60. * @param int $activity_id ID of the activity item being formatted. 
  61. * @param int $user_id ID of the user who inited the interaction. 
  62. */ 
  63. $return = apply_filters( 'bp_activity_' . $amount . '_' . $action_filter . '_notification', '<a href="' . esc_url( $link ) . '" title="' . esc_attr( $title ) . '">' . esc_html( $text ) . '</a>', $link, (int) $total_items, $activity_id, $user_id ); 
  64. } else { 
  65.  
  66. /** 
  67. * Filters the activity notification for any non-string format. 
  68. * This is a variable filter that is dependent on how many items need notified about. 
  69. * The two possible hooks are bp_activity_single_at_mentions_notification 
  70. * or bp_activity_multiple_at_mentions_notification. 
  71. * @since 1.5.0 
  72. * @since 2.6.0 use the $action_filter as a new dynamic portion of the filter name. 
  73. * @param array $array Array holding the content and permalink for the interaction notification. 
  74. * @param string $link The permalink for the interaction. 
  75. * @param int $total_items How many items being notified about. 
  76. * @param int $activity_id ID of the activity item being formatted. 
  77. * @param int $user_id ID of the user who inited the interaction. 
  78. */ 
  79. 'text' => $text,  
  80. 'link' => $link 
  81. ), $link, (int) $total_items, $activity_id, $user_id ); 
  82.  
  83. /** 
  84. * Fires right before returning the formatted activity notifications. 
  85. * @since 1.2.0 
  86. * @param string $action The type of activity item. 
  87. * @param int $item_id The activity ID. 
  88. * @param int $secondary_item_id The user ID who inited the interaction. 
  89. * @param int $total_items Total amount of items to format. 
  90. */ 
  91. do_action( 'activity_format_notifications', $action, $item_id, $secondary_item_id, $total_items ); 
  92.  
  93. return $return;