/** * Format on screen notifications into something readable by users. * * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals() */ function bp_follow_format_notifications($action, $item_id, $secondary_item_id, $total_items, $format = 'string') { global $bp; do_action('bp_follow_format_notifications', $action, $item_id, $secondary_item_id, $total_items, $format); switch ($action) { case 'new_follow': $link = $text = false; if (1 == $total_items) { $text = sprintf(__('%s is now following you', 'bp-follow'), bp_core_get_user_displayname($item_id)); $link = bp_core_get_user_domain($item_id) . '?bpf_read'; } else { $text = sprintf(__('%d more users are now following you', 'bp-follow'), $total_items); if (bp_is_active('notifications')) { $link = bp_get_notifications_permalink(); } else { $link = bp_loggedin_user_domain() . $bp->follow->followers->slug . '/?new'; } } break; default: $link = apply_filters('bp_follow_extend_notification_link', false, $action, $item_id, $secondary_item_id, $total_items); $text = apply_filters('bp_follow_extend_notification_text', false, $action, $item_id, $secondary_item_id, $total_items); break; } if (!$link || !$text) { return false; } if ('string' == $format) { return apply_filters('bp_follow_new_followers_notification', '<a href="' . $link . '">' . $text . '</a>', $total_items, $link, $text, $item_id, $secondary_item_id); } else { $array = array('text' => $text, 'link' => $link); return apply_filters('bp_follow_new_followers_return_notification', $array, $item_id, $secondary_item_id, $total_items); } }
/** * Output the notifications permalink. * * @since BuddyPress (1.9.0) */ function bp_notifications_permalink() { echo bp_get_notifications_permalink(); }
/** * Format notifications related to activity. * * @since 1.5.0 * * @param string $action The type of activity item. Just 'new_at_mention' for now. * @param int $item_id The activity ID. * @param int $secondary_item_id In the case of at-mentions, this is the mentioner's ID. * @param int $total_items The total number of notifications to format. * @param string $format 'string' to get a BuddyBar-compatible notification, 'array' otherwise. * @param int $id Optional. The notification ID. * @return string $return Formatted @mention notification. */ 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_loggedin_user_domain() . bp_get_activity_slug() . '/mentions/'; $title = sprintf(__('@%s Mentions', 'buddypress'), bp_get_loggedin_user_username()); $amount = 'single'; if ((int) $total_items > 1) { $text = sprintf(__('You have %1$d new mentions', 'buddypress'), (int) $total_items); $amount = 'multiple'; } else { $text = sprintf(__('%1$s mentioned you', 'buddypress'), $user_fullname); } break; case 'update_reply': $link = bp_get_notifications_permalink(); $title = __('New Activity reply', 'buddypress'); $amount = 'single'; if ((int) $total_items > 1) { $link = add_query_arg('type', $action, $link); $text = sprintf(__('You have %1$d new replies', 'buddypress'), (int) $total_items); $amount = 'multiple'; } else { $link = add_query_arg('nid', (int) $id, bp_activity_get_permalink($activity_id)); $text = sprintf(__('%1$s commented on one of your updates', 'buddypress'), $user_fullname); } break; case 'comment_reply': $link = bp_get_notifications_permalink(); $title = __('New Activity comment reply', 'buddypress'); $amount = 'single'; if ((int) $total_items > 1) { $link = add_query_arg('type', $action, $link); $text = sprintf(__('You have %1$d new comment replies', 'buddypress'), (int) $total_items); $amount = 'multiple'; } else { $link = add_query_arg('nid', (int) $id, bp_activity_get_permalink($activity_id)); $text = sprintf(__('%1$s replied to one your activity comments', 'buddypress'), $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 1.5.0 * @since 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) . '" title="' . esc_attr($title) . '">' . 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 1.5.0 * @since 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 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; }
/** * Output the notifications permalink for a user. * * @since 1.9.0 * @since 2.6.0 Added $user_id as a parameter. * * @param int $user_id The user ID. */ function bp_notifications_permalink($user_id = 0) { echo bp_get_notifications_permalink($user_id); }