bp_activity_adjust_mention_count( int $activity_id, string $action = 'add' )
Adjusts mention count for mentioned users in activity items.
Description
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 bp_activity_delete().
Parameters
- $activity_id
-
(Required) The unique id for the activity item.
- $action
-
(Optional) Can be 'delete' or 'add'. Defaults to 'add'.
Default value: 'add'
Return
(bool)
Source
File: bp-activity/bp-activity-functions.php
function bp_activity_adjust_mention_count( $activity_id = 0, $action = 'add' ) {
// Bail if no activity ID passed.
if ( empty( $activity_id ) ) {
return false;
}
// Get activity object.
$activity = new BP_Activity_Activity( $activity_id );
// Try to find mentions.
$usernames = bp_activity_find_mentions( strip_tags( $activity->content ) );
// Still empty? Stop now.
if ( empty( $usernames ) ) {
return false;
}
// Increment mention count foreach mentioned user.
foreach( (array) array_keys( $usernames ) as $user_id ) {
bp_activity_update_mention_count_for_user( $user_id, $activity_id, $action );
}
}
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.