bp_activity_adjust_mention_count

Adjusts mention count for mentioned users in activity items.

Description

bp_activity_adjust_mention_count( (int) $activity_id = 0, (string) $action = 'add' ); 

This function is useful if you only have the activity ID handy and you haven't parsed an activity item for @mentions yet.

Currently, only used in .

Parameters (2)

0. $activity_id — Optional. (int)
The unique id for the activity item.
1. $action — Optional. (string) => 'add'
Can be delete or add.. Defaults to add..

Usage

  1. if ( !function_exists( 'bp_activity_adjust_mention_count' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-activity/bp-activity-functions.php'; 
  3.  
  4. // The unique id for the activity item. 
  5. $activity_id = -1; 
  6.  
  7. // Can be 'delete' or 'add'. Defaults to 'add'. 
  8. $action = 'add'; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bp_activity_adjust_mention_count($activity_id, $action); 
  12.  

Defined (1)

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

/bp-activity/bp-activity-functions.php  
  1. function bp_activity_adjust_mention_count( $activity_id = 0, $action = 'add' ) { 
  2.  
  3. // Bail if no activity ID passed. 
  4. if ( empty( $activity_id ) ) { 
  5. return false; 
  6.  
  7. // Get activity object. 
  8. $activity = new BP_Activity_Activity( $activity_id ); 
  9.  
  10. // Try to find mentions. 
  11. $usernames = bp_activity_find_mentions( strip_tags( $activity->content ) ); 
  12.  
  13. // Still empty? Stop now. 
  14. if ( empty( $usernames ) ) { 
  15. return false; 
  16.  
  17. // Increment mention count foreach mentioned user. 
  18. foreach( (array) array_keys( $usernames ) as $user_id ) { 
  19. bp_activity_update_mention_count_for_user( $user_id, $activity_id, $action );