Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] How to redirect bp users to activity page


  • tse11
    Participant

    @tse11

    Hi all, I am running WP 3.6.1 and BP 1.8.1

    I am trying to redirect a user to their activity page when they log in.

    I was able to do this by using this plugin: http://wordpress.org/plugins/buddypress-login-redirect/

    However, because I am using a multisite, when an admin logs in to edit their site in dashboard, they too are redirected to the bp activity page.

    SO, what I am looking for is a way to redirect main site users (subscribers) to their activity page, but NOT redirect them when they are logging in to theirsite.mydomain.com/wp-login.php

    *my site is in production mode, so I cannot provide a link TIA for any help

Viewing 10 replies - 1 through 10 (of 10 total)

  • bp-help
    Participant

    @bphelp

    @tse11
    Search the forum. This has been covered before! You could create a conditional to do this. Basically an if and else statement. You would need to include is_super_admin in the conditional check and the user would be redirected appropriately. For instance:

    
    function bphelp_redirect() {
      if( is_user_logged_in() && is_super_admin ) {
        // redirect to dashboard code
      }else {
          if( is_user_loggedin() && !is_super_admin ) {
        // redirect to activity code
          }
       }
    }
    add_action( 'template_redirect', 'bphelp_redirect', 1 );
    

    This would go in bp-custom.php:
    https://codex.buddypress.org/plugin-development/bp-custom-php/


    tse11
    Participant

    @tse11

    @bphelp
    Thanks! I have scoured the forums and have not found the exact thing that I need, but I guess it’s all in the wording of search terms 😉

    This is the code I have for the plugin I am using:

    function buddypress_login_redirection($redirect_url,$request_url,$user)
    {
    	global $bp;
    	$selected_option = get_option('blr_select_redirection');
    	if($selected_option == 'one')
    	{
    		return bp_core_get_user_domain($user->ID);
    	}
    	elseif($selected_option=='two')
    	{
    		$activity_slug = bp_get_activity_root_slug();
    		$redirect_url = $bp->root_domain."/".$activity_slug;
    		return $redirect_url;
    	}
    	elseif($selected_option=='four')
    	{
    		//$activity_slug = bp_get_activity_root_slug();
    		//$redirect_url = $bp->root_domain."/".$activity_slug;
    		$redirect_url = $_SERVER['HTTP_REFERER'];
    		return $redirect_url;
    	}
    	else
    	{
    		$activity_slug = bp_get_activity_root_slug();
    		$friends_activity = bp_core_get_user_domain($user->ID).$activity_slug."/friends/";
    		return $friends_activity;
    	}
    }
    function buddypress_login_redirection_menu()
    {
    	add_options_page(__('BP Login Redirect Settings','blr-menu'), __('BP Login Redirect Settings','blr-menu'), 'manage_options', 'blrmenu', 'blr_settings_page');
    }
    function blr_settings_page()
    {
    	if (!current_user_can('manage_options'))
        {
          wp_die( __('You do not have sufficient permissions to access this page.') );
        }
    	$opt_name = 'blr_select_redirection';
    	$hidden_field_name = 'blr_submit_hidden';
    	$data_field_name = 'blr_select_redirection';
    	
    	$opt_val = get_option($opt_name);
    	
    	if( isset($_POST[ $hidden_field_name ]) && $_POST[ $hidden_field_name ] == 'Y' )
    	{
    		$opt_val = $_POST[ $data_field_name ];
    		update_option( $opt_name, $opt_val );
    ?>

    Any idea where I would add those conditions you mentioned?


    tse11
    Participant

    @tse11

    Anyone can help with this, please?


    bp-help
    Participant

    @bphelp

    @tse11
    Patience please! Deactivate the plugin you was using for redirecting and try this in bp-custom.php https://codex.buddypress.org/plugin-development/bp-custom-php/ :

    
    function bphelp_redirect() {
      if( is_user_logged_in() && is_super_admin && is_home) {
        // redirect to dashboard code
        bp_core_redirect( get_option( 'home' ) . '/wp-admin/' );
      }else {
          if( is_user_loggedin() && !is_super_admin  && is_home) {
        // redirect to activity code
        bp_core_redirect( get_option( 'home' ) . '/activity/' );
          }
       }
    }
    add_action( 'template_redirect', 'bphelp_redirect', 1 );
    

    bp-help
    Participant

    @bphelp

    @tse11
    If the code above doesn’t work try this one because I just noticed you had mentioned multisite.

    
    function bphelp_redirect() {
      if( is_user_logged_in() && is_multisite() && is_super_admin && is_home) {
        // redirect to dashboard code
        bp_core_redirect( get_option( 'home' ) . '/wp-admin/' );
      }else {
          if( is_user_loggedin() && is_multisite() && !is_super_admin  && is_home) {
        // redirect to activity code
        bp_core_redirect( get_option( 'home' ) . '/activity/' );
          }
       }
    }
    add_action( 'template_redirect', 'bphelp_redirect', 1 );
    

    tse11
    Participant

    @tse11

    @bphelp Thanks a lot for helping. I tried both codes, what’s happening is now every time I click any page, I’m being redirected to wp-admin. Removed code of course.


    tse11
    Participant

    @tse11

    If anyone knows how to do this, I would soooo appreciate it! Please


    bp-help
    Participant

    @bphelp

    @tse11
    What have you set as your front page? Links are always helpful!


    tse11
    Participant

    @tse11

    My site is not yet live, @bphelp I am using a post page as homepage. I don’t know if this will help but as I stated earlier, my site is an MU and I am using sub-domains. So when a user logs in from theirsitename.mysite.com/wp-login.php with any redirect codes I’m using, they too are redirected to a buddypress page which is confusing for the user since they are logging in to edit their site. I basically just need a condition that works properly where I can add if_user_is_admin DON’T redirect or if_user_is on subdomain login page don’t redirect. 😉


    tse11
    Participant

    @tse11

    Got it working now, thanks anyway. In case anyone is wondering how, I changed the log in to /wp-admin instead of /wp-login.php in the user email when a user creates a new site and this page will not redirect anyone to a buddypress page.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘[Resolved] How to redirect bp users to activity page’ is closed to new replies.
Skip to toolbar