Changeset 3468 for trunk/bp-activity.php
- Timestamp:
- 11/21/2010 10:41:37 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/bp-activity.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-activity.php
r3434 r3468 501 501 } 502 502 add_action( 'wp', 'bp_activity_action_favorites_feed', 3 ); 503 504 /** 505 * bp_activity_find_mentions() 506 * 507 * Searches through the content of an activity item to locate usernames, designated by an @ sign 508 * 509 * @package BuddyPress Activity 510 * @since 1.3 511 * 512 * @param $content The content of the activity, usually found in $activity->content 513 * @return array $usernames Array of the found usernames that match existing users 514 */ 515 function bp_activity_find_mentions( $content ) { 516 $pattern = '/[@]+([A-Za-z0-9-_\.]+)/'; 517 preg_match_all( $pattern, $content, $usernames ); 518 519 // Make sure there's only one instance of each username 520 if ( !$usernames = array_unique( $usernames[1] ) ) 521 return false; 522 523 return $usernames; 524 } 525 526 /** 527 * bp_activity_reduce_mention_count() 528 * 529 * Reduces new mention count for mentioned users when activity items are deleted 530 * 531 * @package BuddyPress Activity 532 * @since 1.3 533 * 534 * @param $activity_id The unique id for the activity item 535 */ 536 function bp_activity_reduce_mention_count( $activity_id ) { 537 $activity = new BP_Activity_Activity( $activity_id ); 538 539 if ( $usernames = bp_activity_find_mentions( strip_tags( $activity->content ) ) ) { 540 include_once( ABSPATH . WPINC . '/registration.php' ); 541 542 foreach( (array)$usernames as $username ) { 543 if ( !$user_id = username_exists( $username ) ) 544 continue; 545 546 // Decrease the number of new @ mentions for the user 547 $new_mention_count = (int)get_user_meta( $user_id, 'bp_new_mention_count', true ); 548 update_user_meta( $user_id, 'bp_new_mention_count', $new_mention_count - 1 ); 549 } 550 } 551 } 552 add_action( 'bp_activity_action_delete_activity', 'bp_activity_reduce_mention_count' ); 503 553 504 554 /**
Note: See TracChangeset
for help on using the changeset viewer.