bp_activity_at_name_filter_updates( BP_Activity_Activity $activity )
Catch mentions in an activity item before it is saved into the database.
Description
If mentions are found, replace @mention text with user links and add our hook to send mention notifications after the activity item is saved.
Parameters
- $activity
-
(Required) Activity Object.
Source
File: bp-activity/bp-activity-filters.php
function bp_activity_at_name_filter_updates( $activity ) {
// Are mentions disabled?
if ( ! bp_activity_do_mentions() ) {
return;
}
// If activity was marked as spam, stop the rest of this function.
if ( ! empty( $activity->is_spam ) )
return;
// Try to find mentions.
$usernames = bp_activity_find_mentions( $activity->content );
// We have mentions!
if ( ! empty( $usernames ) ) {
// Replace @mention text with userlinks.
foreach( (array) $usernames as $user_id => $username ) {
$activity->content = preg_replace( '/(@' . $username . '\b)/', "<a class='bp-suggestions-mention' href='" . bp_core_get_user_domain( $user_id ) . "' rel='nofollow'>@$username</a>", $activity->content );
}
// Add our hook to send @mention emails after the activity item is saved.
add_action( 'bp_activity_after_save', 'bp_activity_at_name_send_emails' );
// Temporary variable to avoid having to run bp_activity_find_mentions() again.
buddypress()->activity->mentioned_users = $usernames;
}
}
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.