Last active
December 13, 2015 19:59
-
-
Save imath/4966936 to your computer and use it in GitHub Desktop.
BuddyPress trick to disallow group activity comments or comment replies to non members of the group
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/*** beginning of the code to paste in the functions.php of your theme ***/ | |
function imath_wants_you_to_be_in_group_to_comment_group_activities( $can_comment ) { | |
global $activities_template; | |
if( !is_super_admin() && $activities_template->activity->component == 'groups' && !groups_is_user_member( bp_loggedin_user_id(), $activities_template->activity->item_id ) ) | |
$can_comment = false; | |
return $can_comment; | |
} | |
add_filter( 'bp_activity_can_comment', 'imath_wants_you_to_be_in_group_to_comment_group_activities', 10, 1 ); | |
function imath_wants_you_to_be_in_group_to_reply_to_group_activity_comments( $can_reply, $comment ) { | |
// We need to get the first commented activity to see if it belongs to a group :( | |
$activities = bp_activity_get_specific( array( 'activity_ids' => $comment->item_id ) ); | |
$activity = $activities['activities'][0]; | |
if( !is_super_admin() && $activity->component == 'groups' && !groups_is_user_member( bp_loggedin_user_id(), $activity->item_id ) ) | |
$can_reply = false; | |
return $can_reply; | |
} | |
add_filter( 'bp_activity_can_comment_reply', 'imath_wants_you_to_be_in_group_to_reply_to_group_activity_comments', 10, 2 ); | |
/*** End of the code to paste ***/ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment