Limit activity in groups to admin/mods only
-
Hello everyone! 🙂
I have a few groups where I would like for only admin/mods to be able to post new activity into groups. Users should be able to join the groups, but I don’t like them to be able to post in certain groups. I tried the following code I found, but didn’t work:
add_action( 'wp_footer', 'restrict_activity_to_admin' ); function restrict_activity_to_admin() { global $bp; if( $bp->groups->current_group->id == 46 ){ if( ! is_super_admin() ) { ?> <style> .bpfb_form_container{display: none;} </style> <script type="text/javascript"> jQuery(function() { $('.bpfb_form_container').remove(); }); </script> <?php } } }
Anyone got any ideas on how to fix this? 🙂
Thank you!
Viewing 3 replies - 1 through 3 (of 3 total)
-
Found plugin that does the job:
Unfortunately this plugin breaks the “groups” settings from backend and comes up with a critical error, so if anyone has a solution, please let me know. 🙂
Found the solution with the following code:
Restrict in single group
function restrict_activity_posting_for_specific_group( $can_post, $user_id, $group_id ) { // The ID of the group you want to restrict posting in (replace with the actual group ID) $restricted_group_id = 123; // Example group ID // Only apply the restriction to the specific group if ( $group_id == $restricted_group_id ) { // Check if the user is an admin or moderator if ( !bp_group_is_admin( $user_id, $group_id ) && !bp_group_is_mod( $user_id, $group_id ) ) { return false; // Don't allow posting } } // If not the restricted group, or the user is admin/mod, allow posting return $can_post; } add_filter( 'bp_activity_can_post', 'restrict_activity_posting_for_specific_group', 10, 3 );
Restrict in multiple groups
function restrict_activity_posting_for_specific_groups( $can_post, $user_id, $group_id ) { // The IDs of the groups you want to restrict posting in (replace with actual group IDs) $restricted_group_ids = array( 123, 456, 789 ); // Example group IDs // Check if the group ID is in the restricted group IDs array if ( in_array( $group_id, $restricted_group_ids ) ) { // Only apply the restriction if the user is not an admin or moderator if ( !bp_group_is_admin( $user_id, $group_id ) && !bp_group_is_mod( $user_id, $group_id ) ) { return false; // Don't allow posting } } // If not in the restricted groups or the user is an admin/mod, allow posting return $can_post; } add_filter( 'bp_activity_can_post', 'restrict_activity_posting_for_specific_groups', 10, 3 );
Viewing 3 replies - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.