Changeset 3468
- Timestamp:
- 11/21/2010 10:41:37 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
bp-activity.php (modified) (1 diff)
-
bp-activity/bp-activity-filters.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 /** -
trunk/bp-activity/bp-activity-filters.php
r3340 r3468 103 103 } 104 104 105 /** 106 * bp_activity_at_name_filter() 107 * 108 * Finds and links @-mentioned users in activity updates 109 * 110 * @package BuddyPress Activity 111 * 112 * @param string $content The activity content 113 */ 105 114 function bp_activity_at_name_filter( $content ) { 106 115 include_once( ABSPATH . WPINC . '/registration.php' ); 107 116 108 $pattern = '/[@]+([A-Za-z0-9-_\.]+)/'; 109 preg_match_all( $pattern, $content, $usernames ); 110 111 // Make sure there's only one instance of each username 112 if ( !$usernames = array_unique( $usernames[1] ) ) 113 return $content; 117 $usernames = bp_activity_find_mentions( $content ); 114 118 115 119 foreach( (array)$usernames as $username ) {
Note: See TracChangeset
for help on using the changeset viewer.