Tagged: replies
I saw a thread where someone created the following code to restrict certain member types from commenting and I was wondering how could I adjust it to restrict a certain member type from comment replying? I don’t mind if they post or if they comment…but I don’t want comment replies for specific membertypes. Also below is the code of the comment restriction. Also not sure where to post this code snippet.
/**
* Check weather user is restricted from commenting.
*
* @param int $user_id User id.
*
* @return bool
*/
function buddydev_is_restricted_commenter( $user_id ) {
// Never restrict super admin from commenting.
if ( is_super_admin( $user_id ) ) {
return false;
}return bp_has_member_type( get_current_user_id(), ‘student’ );
}/**
* Check user can comment or not.
*
* @param bool $can Bool.
*
* @return bool
*/
function buddydev_user_can_comment( $can ) {
$activity = new BP_Activity_Activity( bp_get_activity_id() );$user_id = get_current_user_id();
// Do not restrict for its own activity.
if ( $activity->user_id == $user_id ) {
return $can;
}if ( buddydev_is_restricted_commenter( $user_id ) ) {
$can = false;
}return $can;
}
add_filter( ‘bp_activity_can_comment’, ‘buddydev_user_can_comment’ );
add_filter( ‘bp_activity_can_comment_reply’, ‘buddydev_user_can_comment’ );Hello Brian,
Welcome to the BuddyDev Forums. As per my understanding, You want to restrict a member type from replying to activity comments. If yes, use the following code:
/** * Restrict member type for replying * * @param bool $can Bool. * * @return bool */ function buddydev_user_can_reply_on_comment( $can ) { // Replace 'student' with your member type. $is_restricted = bp_has_member_type( get_current_user_id(), 'student' ); if ( $is_restricted ) { $can = false; } return $can; } add_filter( 'bp_activity_can_comment_reply', 'buddydev_user_can_reply_on_comment' );
Please let me know if it helps or not.
Use can put this code inside ‘bp-custom.php’ file. Please have a look here: https://buddydev.com/docs/buddypress-guides/what-is-bp-custom-php/
Regards
Ravi- This reply was modified 2 years, 10 months ago by Ravi.
Hi there,
Thank you so much for the quick response! I tried the solution and it appears not to be working, but guessing it is because of Buddyboss rather than it wouldn’t work in a vaccum. So not sure what to do nextHello Brian,
Thank you for the acknowledgement. Are you able to locate the reply button in the activity stream?. My code works with the reply button and does not hide the comment button.
Please share the screenshot of the buttons you are referring to so that I can have a clear view.
Regards
RaviHi there,
Everything works, I guess I just didn’t add the profile type to each user, that was the confusion.
The topic ‘ [Resolved] How Do I Restrict Certain Member Types from Comment Replying’ is closed to new replies.