Buddypress Activity Privacy Code Help
-
I am trying to filter out all activity except activity from me, my friends and my groups. Below is the code I am using. It’s stolen from and is slightly modified. I removed the follower function.
The issue I am having is that it shows all group activities instead of just the activity from the groups I am a member of. Sadly I am not skilled at php so I don’t know how to change it.
Would anyone be able to adjust this so that it only shows activity from groups I am a member of?
//Friends only filter begins function my_denied_activity_nonfriends( $a, $activities ) { global $bp; foreach ( $activities->activities as $key => $activity ) { /* if member of a group - we want the activity even if nonfriend */ if ( $activity->user_id != $bp->loggedin_user->id && $activity->component != 'groups' && !my_is_friend_check($activity->user_id) && !my_is_atme_check($activity->content) ) { unset( $activities->activities[$key] ); $activities->activity_count = $activities->activity_count-1; $activities->total_activity_count = $activities->total_activity_count-1; $activities->pag_num = $activities->pag_num -1; } } /* Renumber the array keys to account for missing items */ $activities_new = array_values( $activities->activities ); $activities->activities = $activities_new; return $activities; } add_action( 'bp_has_activities', 'my_denied_activity_nonfriends', 10, 2 ); function my_is_atme_check( $content ) { global $bp; if ( !is_user_logged_in() ) return false; if (!$content) return false; $pattern = '/[@]+([A-Za-z0-9-_]+)/'; preg_match_all( $pattern, $content, $usernames ); /* Make sure there's only one instance of each username */ if ( !$usernames = array_unique( $usernames[1] ) ) return false; if ( in_array( bp_core_get_username( $bp->loggedin_user->id ), $usernames ) ) return true; return false; } function my_is_friend_check( $friend_id = false) { global $bp; if ( !is_user_logged_in() ) return false; if ( !$friend_id ) { $potential_friend_id = $bp->displayed_user->id; } else { $potential_friend_id = $friend_id; } if ( $bp->loggedin_user->id == $potential_friend_id ) return true; if ( friends_check_friendship_status($bp->loggedin_user->id, $potential_friend_id) == 'is_friend' ) return true; return false; }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Buddypress Activity Privacy Code Help’ is closed to new replies.