bp_activity_at_name_filter_updates

Catch mentions in an activity item before it is saved into the database.

Description

bp_activity_at_name_filter_updates( (BP_Activity_Activity) $activity ); 

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 (1)

0. $activity (BP_Activity_Activity)
Activity Object.

Usage

  1. if ( !function_exists( 'bp_activity_at_name_filter_updates' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-activity/bp-activity-filters.php'; 
  3.  
  4. // Activity Object. 
  5. $activity = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_activity_at_name_filter_updates($activity); 
  9.  

Defined (1)

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

/bp-activity/bp-activity-filters.php  
  1. function bp_activity_at_name_filter_updates( $activity ) { 
  2. // Are mentions disabled? 
  3. if ( ! bp_activity_do_mentions() ) { 
  4. return; 
  5.  
  6. // If activity was marked as spam, stop the rest of this function. 
  7. if ( ! empty( $activity->is_spam ) ) 
  8. return; 
  9.  
  10. // Try to find mentions. 
  11. $usernames = bp_activity_find_mentions( $activity->content ); 
  12.  
  13. // We have mentions! 
  14. if ( ! empty( $usernames ) ) { 
  15. // Replace @mention text with userlinks. 
  16. foreach( (array) $usernames as $user_id => $username ) { 
  17. $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 ); 
  18.  
  19. // Add our hook to send @mention emails after the activity item is saved. 
  20.  
  21. // Temporary variable to avoid having to run bp_activity_find_mentions() again. 
  22. buddypress)->activity->mentioned_users = $usernames;