BuddyDev

Search

[Resolved] Do not force redirect on non BuddyPress pages with force follow function

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #19684

    Hello Brajesh,

    I would like to skip the forced redirect on non BuddyPress pages with this force follow function you provided, The redirection should only occur on buddypress pages.

    Thanks

     /**
     * Buddydev force follow 6 members function.
     */
    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 >= 6 ) {
    		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 3 more members to continue.' ), 'error' );
    
    	bp_core_redirect( bp_get_members_directory_permalink() );
    }  
    
    add_action( 'bp_template_redirect', 'buddydev_check_or_redirect', 0 ); 
  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #19689

    Hi Tosin,
    Do you want to skip for all or logged in users only?

    Regards
    Brajesh

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #19691

    I want to skip for logged in users only. So logged in users can access the normal WordPress post and pages but the redirection should only be triggered on all buddypress pages.

    Thanks

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #19791

    Hi Tosin,
    Here is your update function

    
    
    /**
     * Buddydev force follow 6 members function.
     */
    function buddydev_check_or_redirect() {
    	// Force profile photo active?
    	$fp_active = class_exists( 'BD_Force_User_Avatar_Helper' );
    
    	// skip if logged and on non bp page.
    	if ( is_user_logged_in() && ! is_buddypress() ) {
    		if ( $fp_active ) {
    			remove_action( 'bp_template_redirect', array(
    				BD_Force_User_Avatar_Helper::get_instance(),
    				'check_or_redirect',
    			), 1 );
    		}
    
    		return;
    	}
    
    	if ( ! function_exists( 'bp_follow_get_the_following_count' ) || ! is_user_logged_in() || is_super_admin() ) {
    		return;
    	}
    
    	$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 >= 6 ) {
    		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 3 more members to continue.' ), 'error' );
    
    	bp_core_redirect( bp_get_members_directory_permalink() );
    }
    
    add_action( 'bp_template_redirect', 'buddydev_check_or_redirect', 0 );
    
    

    Please give it a try.

    Thank you
    Brajesh

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #19885

    Happy new year Brajesh,

    Thanks you so much for the snippet it worked perfectly.

    Thanks

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #19886

    Happy New Year Tosin 🙂

    I am glad it worked.

    Regards
    Brajesh

The topic ‘ [Resolved] Do not force redirect on non BuddyPress pages with force follow function’ is closed to new replies.

This topic is: resolved