Skip to content

Instantly share code, notes, and snippets.

@obiPlabon
Last active September 22, 2024 07:09
Show Gist options
  • Save obiPlabon/2abc92cba9afbce1a0876936bbfc185e to your computer and use it in GitHub Desktop.
Save obiPlabon/2abc92cba9afbce1a0876936bbfc185e to your computer and use it in GitHub Desktop.
Disable like and comment button from BuddyBoss and BuddyPress group
<?php
function disable_likes_comments_for_group( $group_id ) {
add_filter( 'bp_activity_can_comment', static function( $enabled ) use( $group_id ) {
if ( bp_is_group() && bp_get_current_group_id() === $group_id ) {
return false;
}
return $enabled;
} );
add_filter( 'bp_is_activity_like_active', static function( $is_active ) use( $group_id ) {
if ( bp_is_group() && bp_get_current_group_id() === $group_id ) {
return false;
}
return $is_active;
} );
add_filter( 'bp_activity_can_favorite', static function( $can_favorite ) use( $group_id ) {
if ( bp_is_group() && bp_get_current_group_id() === $group_id ) {
return false;
}
return $can_favorite;
} );
add_action( 'bp_after_activity_entry_comments', static function() use( $group_id ) {
if ( bp_is_group() && bp_get_current_group_id() === $group_id ) {
if ( bp_activity_get_comment_count() || ( is_user_logged_in() && ( bp_activity_can_comment() || bp_is_single_activity() ) ) ) { ?>
<div class="activity-comments">
<?php bp_activity_comments(); ?>
</div>
<?php
}
}
});
add_filter( 'bp_nouveau_get_activity_comment_buttons', static function( $buttons ) use( $group_id ) {
if ( bp_is_group() && bp_get_current_group_id() === $group_id ) {
unset( $buttons['activity_comment_reply'] );
}
return $buttons;
} );
}
<?php
/**
* Disable like and comment from any given group.
* @param int $group_id
*
* @return bool
*/
function disable_likes_comments_for_group( $group_id ) {
add_filter( 'bb_is_activity_comments_enabled', static function( $enabled ) use( $group_id ) {
if ( bp_is_group() && bp_get_current_group_id() === $group_id ) {
return false;
}
return $enabled;
} );
add_filter( 'bp_is_activity_like_active', static function( $is_active ) use( $group_id ) {
if ( bp_is_group() && bp_get_current_group_id() === $group_id ) {
return false;
}
return $is_active;
} );
add_filter( 'bp_activity_can_favorite', static function( $can_favorite ) use( $group_id ) {
if ( bp_is_group() && bp_get_current_group_id() === $group_id ) {
return false;
}
return $can_favorite;
} );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment