bp_activity_format_notifications( string $action, int $item_id, int $secondary_item_id, int $total_items, string $format = 'string', int $id )
Format notifications related to activity.
Description
Parameters
- $action
-
(Required) The type of activity item. Just 'new_at_mention' for now.
- $item_id
-
(Required) The activity ID.
- $secondary_item_id
-
(Required) In the case of at-mentions, this is the mentioner's ID.
- $total_items
-
(Required) The total number of notifications to format.
- $format
-
(Optional) 'string' to get a BuddyBar-compatible notification, 'array' otherwise.
Default value: 'string'
- $id
-
(Optional) The notification ID.
Return
(string) $return Formatted @mention notification.
Source
File: bp-activity/bp-activity-notifications.php
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | function bp_activity_format_notifications( $action , $item_id , $secondary_item_id , $total_items , $format = 'string' , $id = 0 ) { $action_filter = $action ; $return = false; $activity_id = $item_id ; $user_id = $secondary_item_id ; $user_fullname = bp_core_get_user_displayname( $user_id ); switch ( $action ) { case 'new_at_mention' : $action_filter = 'at_mentions' ; $link = bp_activity_get_permalink( $item_id ); $title = sprintf( __( '@%s Mentions' , 'buddyboss' ), bp_get_loggedin_user_username() ); $amount = 'single' ; if ( (int) $total_items > 1 ) { $text = sprintf( __( 'You have %1$d new mentions' , 'buddyboss' ), (int) $total_items ); $amount = 'multiple' ; } else { $text = sprintf( __( '%1$s mentioned you' , 'buddyboss' ), $user_fullname ); } break ; case 'update_reply' : $link = bp_get_notifications_permalink(); $title = __( 'New Activity reply' , 'buddyboss' ); $amount = 'single' ; if ( (int) $total_items > 1 ) { $link = add_query_arg( 'type' , $action , $link ); $text = sprintf( __( 'You have %1$d new replies' , 'buddyboss' ), (int) $total_items ); $amount = 'multiple' ; } else { $link = add_query_arg( 'rid' , (int) $id , bp_activity_get_permalink( $activity_id ) ); $text = sprintf( __( '%1$s commented on one of your updates' , 'buddyboss' ), $user_fullname ); } break ; case 'comment_reply' : $link = bp_get_notifications_permalink(); $title = __( 'New Activity comment reply' , 'buddyboss' ); $amount = 'single' ; if ( (int) $total_items > 1 ) { $link = add_query_arg( 'type' , $action , $link ); $text = sprintf( __( 'You have %1$d new comment replies' , 'buddyboss' ), (int) $total_items ); $amount = 'multiple' ; } else { $link = add_query_arg( 'crid' , (int) $id , bp_activity_get_permalink( $activity_id ) ); $text = sprintf( __( '%1$s replied to one of your activity comments' , 'buddyboss' ), $user_fullname ); } break ; } if ( 'string' == $format ) { /** * Filters the activity notification for the string format. * * This is a variable filter that is dependent on how many items * need notified about. The two possible hooks are bp_activity_single_at_mentions_notification * or bp_activity_multiple_at_mentions_notification. * * @since BuddyPress 1.5.0 * @since BuddyPress 2.6.0 use the $action_filter as a new dynamic portion of the filter name. * * @param string $string HTML anchor tag for the interaction. * @param string $link The permalink for the interaction. * @param int $total_items How many items being notified about. * @param int $activity_id ID of the activity item being formatted. * @param int $user_id ID of the user who inited the interaction. */ $return = apply_filters( 'bp_activity_' . $amount . '_' . $action_filter . '_notification' , '<a href="' . esc_url( $link ) . '">' . esc_html( $text ) . '</a>' , $link , (int) $total_items , $activity_id , $user_id ); } else { /** * Filters the activity notification for any non-string format. * * This is a variable filter that is dependent on how many items need notified about. * The two possible hooks are bp_activity_single_at_mentions_notification * or bp_activity_multiple_at_mentions_notification. * * @since BuddyPress 1.5.0 * @since BuddyPress 2.6.0 use the $action_filter as a new dynamic portion of the filter name. * * @param array $array Array holding the content and permalink for the interaction notification. * @param string $link The permalink for the interaction. * @param int $total_items How many items being notified about. * @param int $activity_id ID of the activity item being formatted. * @param int $user_id ID of the user who inited the interaction. */ $return = apply_filters( 'bp_activity_' . $amount . '_' . $action_filter . '_notification' , array ( 'text' => $text , 'link' => $link ), $link , (int) $total_items , $activity_id , $user_id ); } /** * Fires right before returning the formatted activity notifications. * * @since BuddyPress 1.2.0 * * @param string $action The type of activity item. * @param int $item_id The activity ID. * @param int $secondary_item_id The user ID who inited the interaction. * @param int $total_items Total amount of items to format. */ do_action( 'activity_format_notifications' , $action , $item_id , $secondary_item_id , $total_items ); return $return ; } |
Changelog
Version | Description |
---|---|
BuddyPress 1.5.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.