BuddyDev

Search

[Resolved] BuddyPress Auto Friendship Pro + BuddyPress Featured Members (2)

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

    Hello Ravi,

    Sorry about revisiting this issue. The problem is I disabled activation using the BP Auto Activate Auto Login plugin so this bp_core_activated_user did not work.

    Can you help make the auto follow trigger only on first user login Thanks

     /**
     * BuddyPress Auto Friendship Pro + BuddyPress Featured Members autofollow.
     */
    add_action( 'bp_core_activated_user', function ( $user_id ) {
    
    	if ( ! function_exists( 'bp_follow_start_following' ) ) {
    		return;
    	}
    
    	$featured_user_ids = get_users(
    		array(
    			'meta_key' => '_is_featured',
    			'fields'   => 'ID',
    			'number'   => - 1,
    		)
    	);
    
    	if ( empty( $featured_user_ids ) ) {
    		return;
    	}
    
    	foreach ( $featured_user_ids as $featured_user_id ) {
    		bp_follow_start_following( $featured_user_id, $user_id, true );
    	}
    } ); 

    Thanks

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

    Just in case I have this code related to first login to prevent conflicts

     /**
     * Redirect on first login and second login
     */
    function redirect_user_on_first_login( $user_login, $user ) {
    
    	if ( ! function_exists( 'buddypress' ) ) {
    		return;
    	}
    	// check for user's last activity.
    	$last_activity = bp_get_user_last_activity( $user->ID );
    
    	if ( empty( $last_activity ) ) {
    		update_user_meta( $user->ID, '_user_first_login', 1 );
    		// Redirect you custom page.
    		bp_core_redirect( bp_get_root_domain() . '/complete-profile/' );
    	} elseif ( get_user_meta( $user->ID, '_user_first_login', true ) ) {
    		delete_user_meta( $user->ID, '_user_first_login' );
    		// Try second login here.
    		bp_core_redirect( bp_get_root_domain() . '/create-content/' );
    	}
    }
    add_action( 'wp_login', 'redirect_user_on_first_login', 0, 2 ); 
  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2935
    Ravi on #45949

    Hello Tosin,

    Try the following.

    
    /**
     * BuddyPress Auto Friendship Pro + BuddyPress Featured Members autofollow.
     */
    add_action( 'wp_login', function ( $user_login, $user ) {
    
    	if ( ! function_exists( 'bp_follow_start_following' ) ) {
    		return;
    	}
    
    	if ( empty( bp_get_user_last_activity( $user->ID ) ) ) {
    		$featured_user_ids = get_users(
    			array(
    				'meta_key' => '_is_featured',
    				'fields'   => 'ID',
    				'number'   => - 1,
    			)
    		);
    
    		if ( empty( $featured_user_ids ) ) {
    			return;
    		}
    
    		foreach ( $featured_user_ids as $featured_user_id ) {
    			bp_follow_start_following( array(
    				'leader_id'   => $featured_user_id,
    				'follower_id' => $user->ID,
    			) );
    		}
    	}
    }, -5, 2 );
    
    

    Regards
    Ravi

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

    Thank you RAavi, the code worked perfectly

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

    Hello Tosin,

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

    Regards
    Ravi

The topic ‘ [Resolved] BuddyPress Auto Friendship Pro + BuddyPress Featured Members (2)’ is closed to new replies.

This topic is: resolved