BuddyDev

Search

Buddypress Force follow 5 members after registration

  • Participant
    Level: Guru
    Posts: 885
    Tosin on #14404

    Hello Brajesh,

    Please how can I force newly registered members to follow a given number of users. It will work like your BuddyPress Force profile Photo plugin. I am using the buddypress follow plugin on gith hub.

    BuddyPress force follow function should force users on a BuddyPress site to follow at least 5 users before they can use any feature of the site, this will enable the new user to build his/her activity news feed(followings).

    It won’t restrict the site admins, only the normal members are restricted from using site features if they do not follow 5 users after registration.

    1. Force login redirect to buddypress members page to force users to follow at least 5 members.
    2. A message should appear on the members page telling the newly registered member to follow at least 5 members before they can start using the site.
    3. The BuddyPress Force Profile Photo should take effect after new user successfully follows 5 members, then they will need to upload their profile photo.
    4 Old members on the site should never have zero(0) following, if their following is less than 5 they should be forced to the members page to follow 5 members.
    5. there should not be redirect conflict between the BuddyPress Force profile Photo plugin and BuddyPress Force follow function.

    Thank you

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2908
    Ravi on #14411

    Hello Tosin,

    Thank you for posting. Please use the following code in your “bp-custom.php” file.

    
    function buddydev_check_or_redirect() {
    
    	if ( ! function_exists( 'bp_follow_get_the_following_count' ) || ! is_user_logged_in() || is_super_admin() ) {
    		return;
    	}
    
    	$fp_active = class_exists( 'BD_Force_User_Avatar_Helper') ;
    	$is_dir =  bp_is_members_directory();
    
    	// if we are on directory and force profile is not active
    	// return.
    	if (  $is_dir && ! $fp_active ) {
    		return ;
    	}
    
    	$follow_count = bp_follow_get_the_following_count( array( 'object_id' => get_current_user_id() ) );
    
    	if ( $follow_count >= 5 ) {
    		return;
    	}
    
    	if ( $is_dir && $fp_active ) {
    		remove_action( 'bp_template_redirect', array( BD_Force_User_Avatar_Helper::get_instance(), 'check_or_redirect' ), 1 );
    		return;
    	}
    
    	bp_core_add_message( __( 'Please follow atleast 5 people to continue.' ), 'error' );
    
    	bp_core_redirect( bp_get_members_directory_permalink() );
    }
    
    add_action( 'bp_template_redirect', 'buddydev_check_or_redirect', 0 );
    
    

    if No message is showing. Place the following code below above mentioned code

    
    
    function buddydev_show_notices() {
    	do_action( 'template_notices' );
    }
    
    add_action( 'bp_before_directory_members', 'buddydev_show_notices' );
    

    Please let me know if it works or not.

    Thank You
    Ravi

  • Participant
    Level: Guru
    Posts: 885
    Tosin on #14416

    Hello,

    Mr Brajesh your code worked sucessfully. Thank you very very much i’m really grateful. Infact you just made this Nigerian boy very happy God bless you.

    I was wondering if this code can be replicated for FRIENDSHIP connections if possible, please share this code in your blog for other users to benefit.

    This code will foster better connections on buddypress sites

    You are simply the best, God bless.

  • Keymaster
    (BuddyDev Team)
    Posts: 24149
    Brajesh Singh on #14430

    Hi Tosin,
    I am glad it worked. @ravisharma deserves the credit for the assistance. Thank you Ravi.

    This code can certainly be extrapolated for friendship but a Friendship is a bidirectional connection. What should we count? The friends and the friendship request sent by the logged in member?

    Regards
    Brajesh

  • Participant
    Level: Guru
    Posts: 885
    Tosin on #14434

    Hello Brajesh,

    I think we can count friendship request sent by the logged in user but the count should be limited to 3 friendship request and the error message can be (Connect with 3 new friends to continue)

    Regards
    Tosin

You must be logged in to reply to this topic.

This topic is: not resolved