BuddyDev

Search

[Resolved] disable the comment action until the users are become friends

Tagged: 

  • Participant
    Level: Enlightened
    Posts: 27
    John Elmer on #41140

    Hi Guys!

    Is possible to disable the comment action until the users are become friends?

    THANK YOU!!!

  • Participant
    Level: Enlightened
    Posts: 27
    John Elmer on #41142

    Hi Guys!

    Is possible to disable the comment action until the users are become friends? I am using rtmedia.

    THANK YOU!!!

  • Keymaster
    (BuddyDev Team)
    Posts: 24577
    Brajesh Singh on #41152

    Hi John,
    Thank you for the question.

    Here is a sample code to do that.

    
    
    add_filter( 'bp_activity_can_comment', function ( $can, $activity_type ) {
    
    	// already protected, return.
    	if ( ! $can ) {
    		return $can;
    	}
    
    	$logged_user_id   = get_current_user_id();
    	$activity_user_id = bp_get_activity_user_id();
    
    	// if not user's own activity, or not super admin
    	// and the current user is not friends with the activity user, disable comment.
    	if ( $logged_user_id != $activity_user_id &&
    	     ! is_super_admin() && function_exists( 'friends_check_friendship' ) &&
    	     ! friends_check_friendship( $logged_user_id, $activity_user_id )
    	) {
    		$can = false;
    	}
    
    	return $can;
    }, 20, 2 );
    
    

    Please note that it will do it for all activities(including user’s activity on the group).
    Also, It will not hide the comment reply button.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 27
    John Elmer on #41156

    Wow Brajesh! You are a rock!

    I know you because of your picture from bbpress forum and I am feeling so lucky to have you here!

    THANK YOU SO MUCH!

    YOU ARE SUPER SUPER SUPER HELPFULL!

  • Keymaster
    (BuddyDev Team)
    Posts: 24577
    Brajesh Singh on #41161

    Hi John,
    Thank you.

    It’s a pleasure. Thank you for the kind words.

    Regards
    Brajesh

The topic ‘ [Resolved] disable the comment action until the users are become friends’ is closed to new replies.

This topic is: resolved