BuddyDev

Search

Replies

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on in reply to: [Resolved] Restrict activity commenting by role? #45098

    Hello Amanda,

    Thank you for the acknowledgement. I am glad that I could help you.

    Regards
    Ravi

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on in reply to: [Resolved] Restrict activity commenting by role? #45084

    You can place this code in the ‘bp-custom.php’ file.

    Please have a look at the resource URL: https://buddydev.com/docs/buddypress-guides/what-is-bp-custom-php/

    Regards
    Ravi

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on in reply to: [Resolved] Restrict activity commenting by role? #45083

    Hello Amanda,

    Try the following code:

    
    
    /**
     * 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 or no user found.
    	if ( is_super_admin( $user_id ) ) {
    		return false;
    	}
    
    	$user = get_user_by( 'id', $user_id );
    
    	// Roles those will be restricted.
    	$restricted_roles = array( 'contributor', 'subscriber' );
    
    	// Restrict only if the user has restricted roles.
    	if ( $user && array_intersect( $user->roles, $restricted_roles ) ) {
    		return true;
    	}
    
    	return false;
    }
    
    /**
     * 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' );
    
    

    Please give it a try.

    Regards
    Ravo

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on in reply to: [Resolved] Restrict activity commenting by role? #45066

    Hello Amanda,

    Please replace the function with the followingone :

    
    
    /**
     * 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 or no user found.
    	if ( is_super_admin( $user_id ) ) {
    		return false;
    	}
    
    	$user = get_user_by( 'id', $user_id );
    
    	// Roles those will be restricted.
    	$restricted_roles = array( 'contributor', 'subscriber' );
    
    	// Restrict only if the user has restricted roles.
    	if ( $user && array_intersect( $user->roles, $restricted_roles ) ) {
    		return true;
    	}
    
    	return false;
    }
    
    

    Regards
    Ravi

    • This reply was modified 2 years, 7 months ago by Ravi.
  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on in reply to: [Resolved] Restrict activity commenting by role? #45064

    Hello Amanda,

    Welcome to the BuddyDev forums. You can replace the following function

    
    
    bp_has_member_type( get_current_user_id(), 'student' );
    
    

    with

    
    
    // Replace the capability with role's capability you want to restrict
    current_user_can( 'edit_posts' );
    
    

    For role-based capability check the following URL.
    Reference URL: https://wordpress.org/support/article/roles-and-capabilities/

    Regards
    Ravi

    • This reply was modified 2 years, 8 months ago by Ravi.
  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on in reply to: BuddyPress Member Directory shotcode #45028

    Hello Amsi,

    Thank you for posting. Are you referring to the BuddyPress Member Types Pro plugin?. If yes, please let me know which theme and template pack you are using so that I can check.

    Regards
    Ravi

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on in reply to: Issue with notifications #44925

    Hello Laurent,

    Sorry for the inconvenience. Please let me know which template pack and theme you are using?.

    Regards
    Ravi

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on in reply to: [Resolved] blog page template as forum page. #44907

    Hello,

    Thank you for posting. Please check ‘content-single-forum.php’ bbPress uses to list topics on the single forum page. Please get in touch with your theme author to better assist you with this requirement.

    Regards
    Ravi

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on in reply to: Accept Terms of Service on registration #44906

    Hello Lisa,

    Thank you for posting. Branded Login plugin does not deal with the registration. BuddyPress does offer Policy acceptance with Nouveau template pack. Please let me know which template pack you are using. Please navigate to Dashboard > Settings > BuddyPress > Options > Main settings > Template pack.

    Regards
    Ravi

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115

    Hello Yuriix,

    Thank you for the acknowledgement. I am glad that I could help.

    Regards
    Ravi