Opened 9 years ago
Closed 9 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)
Change History (7)
#2
@
9 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
@
9 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.
Hi @wdfee
I think rather than trying to filter there, we should look at the
bp_activity_get_userid_from_mentionname
orbp_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?