BuddyDev

Search

[Resolved] How to set BuddyPress Profile Completion plugin redirect priority to last


  • Participant
    Level: Enlightened
    Posts: 61
    Tosin on #21349

    Hello Brajesh,

    I just installed your BuddyPress Profile Completion plugin, but I have some custom code with redirect you provided upon login and new user registration. I want BuddyPress Profile Completion redirect to take effect last after all other redirects.

    This are the code you provided

     /**
     * Buddydev force follow 7 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 welcome page.
    	if ( is_user_logged_in() && is_page( 'welcome' ) ) {
    		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 >= 7 ) {
    		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 4 or more members to continue.' ), 'error' );
    
    	bp_core_redirect( bp_get_members_directory_permalink() );
    }
    
    add_action( 'bp_template_redirect', 'buddydev_check_or_redirect', 0 );
     

    The second code

     /**
     * Do not redirect users on non bp pages.
     *
     * @param bool $skip should we skip or redirect.
     *
     * @return bool
     */
    function buddydev_skip_redirect_on_non_bp_pages( $skip ) {
     
        if ( ! is_buddypress() ) {
            $skip = true;
        }
     
        return $skip;
    }
     
    add_filter( 'bp_force_profile_photo_skip', 'buddydev_skip_redirect_on_non_bp_pages' );
     

    The third code

     /**
     * Example to show skipping urls from the BuddyPress Force Profile Photo plugin
     *
     * @param boolean $skip
     *
     * @return bool whether to skip or not?
     */
    function buddydev_skip_urls_from_force_profile_photo( $skip ) {
     
        if ( bp_is_members_directory() ) {
            $skip = true;
        }
     
        return $skip;
    }
    add_filter( 'bp_force_profile_photo_skip', 'buddydev_skip_urls_from_force_profile_photo' );
     
    
    /**
     * Do not skip redirect on new post.
     *
     * @param bool $skip should we skip?
     *
     * @return bool
     */
    function buddydev_dont_skip_redirect_on_new_post( $skip ) {
    
    	if ( is_page( 'create-public-post' ) ) {
    		$skip = false;
    	}
    
    	return $skip;
    }
    
    add_filter( 'bp_force_profile_photo_skip', 'buddydev_dont_skip_redirect_on_new_post', 20 ); 

    Fourth code

     /**
     * Redirect user to site home page when they register/login using BuddyPress Auto Activate Auto Login plugin.
     *
     * @return string
     */
    function buddydev_redirect_to_homepage_on_autologin() {
    	return site_url( '/welcome/' );
    }
    
    add_filter( 'bpdev_autoactivate_redirect_url', 'buddydev_redirect_to_homepage_on_autologin' );
     

    I want all this code above to take priority first before the BuddyPress Profile Completion plugin, This is needed in order to prevent login and new user sign up redirection conflicts

    I am not sure if the BuddyPress Profile Completion plugin and the BuddyPress Force Profile Photo plugin share the same code, so should I deactivate BuddyPress Force Profile Photo plugin if it has similar code with BuddyPress Profile Completion plugin.

    Thanks


  • Keymaster
    (BuddyDev Team)
    Posts: 10538
    Brajesh Singh on #21371

    Hi Tosin,

    1. BP Profile Completion is a super set of BP Force Profile. You can remove BP Force Profile in favour of the Profile completion.

    They have similar code but the custom code for force profile won’t work with profile completion.

    The above code needs proper testing on Bp profile completion plugin, I will need sometime before I can test and provide you an update for it. Please reminding me by early Tuesday if I do not post the update here before that.

    Thank you
    Brajesh


  • Participant
    Level: Enlightened
    Posts: 61
    Tosin on #21509

    Good day Brajesh,

    You said I should remind you about the code update today.

    Thanks


  • Keymaster
    (BuddyDev Team)
    Posts: 10538
    Brajesh Singh on #21522

    Hi Tosin,
    Thank you.

    I have asked @ravisharma to assist you on this. He will be assisting you today.

    regards
    Brajesh


  • Keymaster
    Level: Guru
    (BuddyDev Team)
    Posts: 600
    Ravi on #21530

    Hello Tosin,

    Please try the following code and let me know if it works or not.

    
    function buddydev_custom_skip_check( $skip ) {
    	if ( is_page( 'create-public-post' ) ) {
    		$skip = false;
    	} elseif ( ! is_buddypress() || bp_is_members_directory() ) {
    		$skip = true;
    	}
    
    	return $skip;
    }
    
    add_filter( 'bp_force_profile_completion_skip_check', 'buddydev_custom_skip_check' );
    
    function buddydev_custom_redirect() {
    
    	if ( ! is_user_logged_in() || is_super_admin() || ! function_exists( 'bp_follow_total_follow_counts' ) ) {
    		return;
    	}
    
    	$count = bp_follow_total_follow_counts( array( 'user_id' => get_current_user_id() ) );
    
    	if ( $count['following'] < 7 && ! bp_is_members_directory() ) {
    		bp_core_add_message( __( 'Please follow atleast 7 members to continue.', 'buddypress' ) );
    		$location = bp_get_members_directory_permalink();
    		header( 'location:' . $location );
    		exit;
    	}
    }
    
    add_action( 'bp_template_redirect', 'buddydev_custom_redirect' );
    
    

    Thank you
    Ravi


  • Participant
    Level: Enlightened
    Posts: 61
    Tosin on #21532

    Hello, the code works but I had the following problems

    1. Your plugin BuddyPress Auto Activate Autologin Redirect To Profile On Signup does not log in the newly registered users again. I am using this code with the plugin which redirects to welcome page instead of profile page.

     /**
     * Redirect user to site home page when they register/login using BuddyPress Auto Activate Auto Login plugin.
     *
     * @return string
     */
    function buddydev_redirect_to_homepage_on_autologin() {
    	return site_url( '/welcome/' );
    }
    
    add_filter( 'bpdev_autoactivate_redirect_url', 'buddydev_redirect_to_homepage_on_autologin' ); 

    This was the login error format in the address bar /wp-login.php?redirect_to=https%3A%2F%2Fwww.nigerpress.com%2Fteeguy%2Fprofile%2Fedit%2F&bp-auth=1&action=bpnoaccess

    2. This code for the FORCE FOLLOW does not include the redirect skip on the welcome page

     // skip if logged and on non welcome page.
    	if ( is_user_logged_in() && is_page( 'welcome' ) ) {
    		if ( $fp_active ) {
    			remove_action( 'bp_template_redirect', array(
    				BD_Force_User_Avatar_Helper::get_instance(),
    				'check_or_redirect',
    			), 1 );
    		}
    
    		return;
    	} 

    Thanks


  • Keymaster
    Level: Guru
    (BuddyDev Team)
    Posts: 600
    Ravi on #21540

    Hello Tosin,

    Please use the following code. It will work

    
    function buddydev_custom_skip_check( $skip ) {
    	if ( is_page( 'create-public-post' ) ) {
    		$skip = false;
    	} elseif ( ! is_buddypress() || bp_is_members_directory() ) {
    		$skip = true;
    	}
    
    	return $skip;
    }
    
    add_filter( 'bp_force_profile_completion_skip_check', 'buddydev_custom_skip_check' );
    
    function buddydev_custom_redirect() {
    
    	if ( ! is_user_logged_in() || is_super_admin() || ! function_exists( 'bp_follow_total_follow_counts' ) ) {
    		return;
    	}
    
            // Return if we are on welcome page
            if ( is_page( 'welcome' ) ) {
                 return;
            }
    
    	$count = bp_follow_total_follow_counts( array( 'user_id' => get_current_user_id() ) );
    
    	if ( $count['following'] < 7 && ! bp_is_members_directory() ) {
    		bp_core_add_message( __( 'Please follow atleast 7 members to continue.', 'buddypress' ) );
    		$location = bp_get_members_directory_permalink();
    		header( 'location:' . $location );
    		exit;
    	}
    }
    
    add_action( 'bp_template_redirect', 'buddydev_custom_redirect' );
    

  • Participant
    Level: Enlightened
    Posts: 61
    Tosin on #21552

    The code worked perfectly thank you very much

    Will you continue to provide updates to the BuddyPress Profile Completion plugin as this plugin is not officially listed on your plugins page


  • Keymaster
    Level: Guru
    (BuddyDev Team)
    Posts: 600
    Ravi on #21553

    Glad that code works….

    Yes, we will and we plan to discontinue Force profile photo plugin in favour of Profile completion.
    It will be available form our list in next 3-4 weeks(It is available form wp.org) for now.

    Thank You
    Ravi

    • This reply was modified 5 days, 21 hours ago by  Ravi.

The topic ‘ [Resolved] How to set BuddyPress Profile Completion plugin redirect priority to last’ is closed to new replies.

This topic is: resolved
Subscribe