Skip to:
Content

BuddyPress.org

Changeset 3468


Ignore:
Timestamp:
11/21/2010 10:41:37 PM (15 years ago)
Author:
boonebgorges
Message:

Decreases new mention count when activity items are deleted. Fixes #2082

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity.php

    r3434 r3468  
    501501}
    502502add_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 */
     515function 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 */
     536function 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}
     552add_action( 'bp_activity_action_delete_activity', 'bp_activity_reduce_mention_count' );
    503553
    504554/**
  • trunk/bp-activity/bp-activity-filters.php

    r3340 r3468  
    103103}
    104104
     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 */
    105114function bp_activity_at_name_filter( $content ) {
    106115    include_once( ABSPATH . WPINC . '/registration.php' );
    107116
    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 );
    114118
    115119    foreach( (array)$usernames as $username ) {
Note: See TracChangeset for help on using the changeset viewer.