friends_format_notifications( string $action, int $item_id, int $secondary_item_id, int $total_items, string $format = 'string' )
Notification formatting callback for bp-friends notifications.
Description
Parameters
- $action
-
(Required) The kind of notification being rendered.
- $item_id
-
(Required) The primary item ID.
- $secondary_item_id
-
(Required) The secondary item ID.
- $total_items
-
(Required) The total number of messaging-related notifications waiting for the user.
- $format
-
(Optional) 'string' for BuddyBar-compatible notifications; 'array' for WP Toolbar. Default: 'string'.
Default value: 'string'
Return
(array|string)
Source
File: bp-friends/bp-friends-notifications.php
function friends_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) { switch ( $action ) { case 'friendship_accepted': $link = trailingslashit( bp_loggedin_user_domain() . bp_get_friends_slug() . '/my-friends' ); // $action and $amount are used to generate dynamic filter names. $action = 'accepted'; // Set up the string and the filter. if ( (int) $total_items > 1 ) { $text = sprintf( __( '%d members accepted your connection requests', 'buddyboss' ), (int) $total_items ); $amount = 'multiple'; } else { $text = sprintf( __( '%s accepted your request to connect', 'buddyboss' ), bp_core_get_user_displayname( $item_id ) ); $amount = 'single'; } break; case 'friendship_request': $link = bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/?new'; $action = 'request'; // Set up the string and the filter. if ( (int) $total_items > 1 ) { $text = sprintf( __( 'You have %d pending requests to connect', 'buddyboss' ), (int) $total_items ); $amount = 'multiple'; } else { $text = sprintf( __( '%s sent you an invitation to connect', 'buddyboss' ), bp_core_get_user_displayname( $item_id ) ); $amount = 'single'; } break; } // Return either an HTML link or an array, depending on the requested format. if ( 'string' == $format ) { /** * Filters the format of friendship notifications based on type and amount * of notifications pending. * * This is a variable filter that has four possible versions. * The four possible versions are: * - bp_friends_single_friendship_accepted_notification * - bp_friends_multiple_friendship_accepted_notification * - bp_friends_single_friendship_request_notification * - bp_friends_multiple_friendship_request_notification * * @since BuddyPress 1.0.0 * * @param string|array $value Depending on format, an HTML link to new requests profile * tab or array with link and text. * @param int $total_items The total number of messaging-related notifications * waiting for the user. * @param int $item_id The primary item ID. */ $return = apply_filters( 'bp_friends_' . $amount . '_friendship_' . $action . '_notification', '<a href="' . esc_url( $link ) . '">' . esc_html( $text ) . '</a>', (int) $total_items, $item_id ); } else { /** This filter is documented in bp-friends/bp-friends-notifications.php */ $return = apply_filters( 'bp_friends_' . $amount . '_friendship_' . $action . '_notification', array( 'link' => $link, 'text' => $text ), (int) $total_items, $item_id ); } /** * Fires at the end of the bp-friends notification format callback. * * @since BuddyPress 1.0.0 * * @param string $action The kind of notification being rendered. * @param int $item_id The primary item ID. * @param int $secondary_item_id The secondary item ID. * @param int $total_items The total number of messaging-related notifications * waiting for the user. * @param array|string $return Notification text string or array of link and text. */ do_action( 'friends_format_notifications', $action, $item_id, $secondary_item_id, $total_items, $return ); return $return; }
Changelog
Version | Description |
---|---|
BuddyPress 1.0.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.