Skip to:
Content

BuddyPress.org

Opened 4 years ago

Closed 4 years ago

#6682 closed enhancement (fixed)

filter for @mentioned user_ids

Reported by: wdfee Owned by: imath
Milestone: 2.5 Priority: normal
Severity: normal Version: 2.3.3
Component: Activity Keywords: has-patch commit
Cc:

Description

There is no hook to filter mentioned users. I'd need this in a multi network installation to restrict linked names (and sent emails) to members of the current site / network only. Another use could be to restrict mentioned users to friends only or to group members only (if user was mentioned inside a group).
I'd suggest to add a filter hook to bp-activity-functions.php inside function bp_activity_find_mentions(), before sql query is started, line 98-99:

// Make sure there's only one instance of each username
$usernames = apply_filters( 'bp_activity_mentions_usernames_filter', array_unique( $usernames[1] ) );

Maybe related ticket #5954.

Attachments (1)

6682.diff (596 bytes) - added by henry.wright 4 years ago.

Download all attachments as: .zip

Change History (7)

#1 @DJPaul
4 years ago

Hi @wdfee

I think rather than trying to filter there, we should look at the bp_activity_get_userid_from_mentionname or bp_core_get_userid_from_nicename functions because that's where the user lookup happens.

In a multi-network, how do you find out which network(s) a user belongs to? Is there an attribute on the WP_User property?

#2 @wdfee
4 years ago

Hi @DJPaul
in our case the networks don't have subblogs, so we can use is_user_member_of_blog(), my filter function's like this:

function my_activity_mentions_usernames_filter($usernames) {
	foreach( $usernames as $u => $username):
		$mentioned_user = get_user_by( 'login', $username );
		if( empty($mentioned_user) || !is_user_member_of_blog($mentioned_user->ID) ):
			unset($usernames[$u]);
		endif;
	endforeach;
	return $usernames;
}

In bbPress btw there's an equivalent filter offered a little bit later in bbp_find_mentions() includes/extend/buddypress/functions.php 346.

#3 @DJPaul
4 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 2.5

We can absolutely add a filter. I'm not sure this is the best way to do what you're trying to do -- it probably means we need to make some other part of BuddyPress better -- I did spend some time looking when your ticket came in, but I didn't have enough time to dive deep.

We've missed the 2.4 boat for this change, so we'll get it done for 2.5.

#4 @henry.wright
4 years ago

  • Keywords has-patch added; needs-patch removed

Hi guys, I'm thinking the return value of bp_activity_find_mentions() might be a good place to filter? Patch incoming...

@henry.wright
4 years ago

#5 @imath
4 years ago

  • Keywords commit added

Ok i'm going to commit this.

#6 @imath
4 years ago

  • Owner set to imath
  • Resolution set to fixed
  • Status changed from new to closed

In 10571:

Add a new filter to edit the users to mention

In case an activity contains users to mention, allow the list of found users to be edited.

Props henry.wright, wdfee

Fixes #6682

Note: See TracTickets for help on using tickets.