BuddyDev

Search

[Resolved] Buddypress Anonymous Activity

  • Participant
    Level: Initiated
    Posts: 14
    Nicola Fern on #23145

    Hi Brajesh

    Is there any update on this? I’m hoping to go live with my site next week.

    Thanks
    Nicola

  • Keymaster
    (BuddyDev Team)
    Posts: 24212
    Brajesh Singh on #23149

    Hi Nic,
    We have got this working. We will release it over the weekend and you may utilize this.

    Regards
    Brajesh

  • Keymaster
    (BuddyDev Team)
    Posts: 24212
    Brajesh Singh on #23201

    HI Nic,
    Please upgrade to 1.0.9 and then, you can add the following code to your bp-custom.php

    
    /**
     * Disable UI.
     */
    add_filter(
    	'bp_anonymous_is_valid_screen',
    	function ( $valid ) {
    		return false;// don't show ui.
    	}
    );
    
    /**
     * Custom enable for certain groups.
     *
     * @param bool   $is is enabled.
     * @param string $context current context.
     * @param int    $context_id context id.
     */
    function bpanonymous_custom_enable( $is, $context, $context_id ) {
    	if ( 'group' !== $context ) {
    		return $is;
    	}
    
    	$allowed_groups = array( 1,2,3,4 );// please change with the group ids.
    
    	return in_array( $context_id, $allowed_groups );
    }
    
    add_filter( 'bp_anonymous_activity_is_anonymous_comment', 'bpanonymous_custom_enable', 10, 3 );
    add_filter( 'bp_anonymous_activity_is_maybe_anonymous_comment', 'bpanonymous_custom_enable', 10, 3 );
    add_filter( 'bp_anonymous_activity_is_anonymous_post', 'bpanonymous_custom_enable', 10, 3 );
    
    

    Please make sure to change this

    
    	$allowed_groups = array( 1,2,3,4 );// please change with the group ids.
    
    

    With correct group ids.

    Any update/comment on these groups will be anonymous.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 14
    Nicola Fern on #24359

    Hi

    Sorry to bug you on this again 🙂 Could you tell me how to tweak the code again so that it’s only on the specific group but the UI is shown so that anonymity is optional? Feedback from users suggests this would be preferred.

    Thanks!
    Nic

  • Keymaster
    (BuddyDev Team)
    Posts: 24212
    Brajesh Singh on #24361

    Hi Nic,
    No problem.

    Our team will assist you on Monday/Tuesday with the customization.

    Regards
    Brajesh

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2935
    Ravi on #24385

    Hello Nic,

    To show the ui as optional. Please modify the above code

    Replace the following code

    
    /**
     * Disable UI.
     */
    add_filter(
    	'bp_anonymous_is_valid_screen',
    	function ( $valid ) {
    		return false;// don't show ui.
    	}
    );
    
    

    with

    
    /**
     * Disable UI.
     */
    add_filter(
    	'bp_anonymous_is_valid_screen',
    	function ( $valid ) {
    
    		if ( ! bp_is_group() ) {
    			return $valid;
    		}
    
    		// Do not show ui on anonymous groups.
    		$anonymous_groups = array( 43, 42 );// please change with the group ids.
    
    		return ! in_array( bp_get_current_group_id(), $anonymous_groups );
    	}
    );
    
    

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 14
    Nicola Fern on #24448

    Hi Ravi

    I tested this and unfortunately it doesn’t seem to work. I notice your comment in the code says “// Do not show ui on anonymous groups.”

    However I /do/ want to show it on the anonymous groups, but only those I have specified to be anonymous. At the moment, this code removes the UI from the anonymous groups and shows it on the groups where anonymity is not enabled.

    Thanks
    Nicola

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2935
    Ravi on #24920

    Hello Nicola,

    Sorry for the delayed reply please change the following line

    
    return ! in_array( bp_get_current_group_id(), $anonymous_groups );
    
    

    with

    
    return in_array( bp_get_current_group_id(), $anonymous_groups );
    

    it will show ui on selected groups. Let me know if works or not

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 14
    Nicola Fern on #25058

    Hi Ravi

    Unfortunately this didn’t seem to work – it removed the UI everywhere, and made the specified group anonymous only again

    Thanks
    Nicola

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2935
    Ravi on #25060

    Hello Nicola,

    Please post whole code here. You are using sothat I can check and provide you the solution.

    Regards
    Ravi

You must be logged in to reply to this topic.

This topic is: resolved