Replies
Thanks, that worked perfectly!
Is there also a way to restrict posting at the top of the activity page in the same way?screenshot here: https://ibb.co/zrsvwK3
Thanks again!
Disregard the above post! I forgot to delete the previous code from my functions.php so that is what caused the critical error. I removed from functions.php and reinserted the new code to bp-custom.php and tested again. It’s now working! subscribers cannot comment unless it is their own post!
Thank you so much Ravi!Hi, I inserted this code in my bp-custom.php folder and it, unfortunately, caused a critical error on my entire site. I removed the code, and my site is restored. I am not sure what is causing the error. I input the code you posted above and did not change it in any way. Any ideas? I can try the code that allows commenting based on capabilities as well if this code does not work. Members have more capabilities than subscribers.
Thanks again!Hi, thanks for the response!
I was a bit confused on the 2 responses you gave. I put the following code in functions and it’s not working. Is it incorrect? Am I supposed to place it elsewhere?/**
* 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 // Replace the capability with role’s capability you want to restrict
current_user_can( ‘publish_posts’ );
}/**
* 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’ );Thanks again!
- This reply was modified 2 years, 5 months ago by Amanda.