BuddyDev

Search

Limit activity in groups to admin/mods only

  • Participant
    Level: Enlightened
    Posts: 68
    Katrine Spencer on #53496

    Hello

    Do you guys have any plugins that would allow for some extra group permissions?
    I have a group where I would like only admin/mods to be able to post activity (not the members of the group).

    Hope it makes sense. 🙂

    Thank you!

  • Keymaster
    (BuddyDev Team)
    Posts: 24697
    Brajesh Singh on #53503

    Hi Katrine,
    Thank you for the question.

    Here is some code that does the opposite(keeps on for groups but disables on sitewide activity stream etc).
    https://buddydev.com/support/forums/topic/hiding-whats-new-form-in-member-activity-but-not-in-groups/page/2/#post-44896

    I hope you are able to customize it. If not, Please let me know and I will share an updated copy for your use case.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 68
    Katrine Spencer on #53536

    Hello Brajesh

    I did manage to get it to work with the following code (if anyone else in here needs it in the future):

    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 );`

  • Keymaster
    (BuddyDev Team)
    Posts: 24697
    Brajesh Singh on #53550

    Hi Katrine,
    Thank you for sharing.
    I am glad you managed to find the solution.

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: not resolved