Skip to:
Content
Pages
Categories
Search
Top
Bottom

Login re-direct

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

  • stwc
    Participant

    @stwc

    Without knowing anything about the paid plugin in question, it’s pretty hard to make a guess. You might want to contact the plugin author, since I assume that if they made you pay for it, they offer support.

    I note that it’s not one of the ones they explicitly say are Buddypress compatible, though, so you may have issues.

    It can’t be a complicated bit of code, though, so I’d just open it up and see what’s in the code, and hack in the URL necessary. You’ll need to get the currently logged-in user from BP in order to build the URL of their profile, page, though, because their username is part of the URL.

    That’s more than I know how to do off the top of my head, but I’m sure someone with more knowledge of BP coding can help you there.


    Boone Gorges
    Keymaster

    @boonebgorges

    It’s a little bit hard to do with the standard method of appending the redirect URL as an argument to the href link. At the time that the page is built from the template, you don’t know what the username is – it’s only after the user types in his username that you know what the redirect URL should be (eg http://example.com/members/boonebgorges), but by that time the page has already been built.

    Unless there’s an all-purpose logged-in-user-profile URL alias built into BP that I don’t know about (maybe something like http://example.com/members/myprofile). Actually, now that I think about it, such a thing might not be too hard to create. If I get some spare time in the next few days maybe I’ll take a swing at it.


    Shnooka30
    Participant

    @shnooka30

    Boone that would be cool.

    I used the plug-in to block members from going strait to the dash. But I have it set for them to go to the home page.

    Again it would be cool if they logeed in, it would be cool for them to go there profile. This would also encourage new members to fill out there profile details as well.


    Boone Gorges
    Keymaster

    @boonebgorges

    OK, I cobbled together a solution. Two steps:

    1. Add the following code to your bp-custom.php folder or in your child theme’s functions.php (or a plugin if you roll that way):
      function myprofile_redirect() {
      global $bp;

      if ( $bp->current_component == 'myprofile' && $bp->loggedin_user->domain != '' ) {
      bp_core_redirect( $bp->loggedin_user->domain );
      } elseif ( $bp->current_component == 'myprofile' ) {
      bp_core_redirect( $bp->root_domain );
      }

      }
      add_action( 'plugins_loaded', 'myprofile_redirect');

    2. In header.php of your child theme (copy it over from bp-sn-parent if you don’t have one there already) replace

      <input type="hidden" name="redirect_to" value="<?php echo bp_root_domain() ?>" />

      around line 57 with

      <input type="hidden" name="redirect_to" value="<?php print ( bp_root_domain() . '/myprofile' ) ?>" />

    Anytime a logged-in user types in the address http://example.com/myprofile, they’ll get their profile. Non-logged-in visitors will be redirected to the home page.

    Let me know if it works for you.


    Shnooka30
    Participant

    @shnooka30

    Wow, thanks. Ill look into this and let you know how it goes.


    Brajesh Singh
    Participant

    @sbrajesh

    hi all,

    Well,I had experimented with login feature and came up with another solution.I just blogged :) it and here is the code for your reference.

    My goal was

    1.redirect normal users to their profile,whether they try to login from front pages(yeh,site front page or any other page on site) or wp-login.php

    2.If the user is Site admin, and logs from site front page,redirect him to front page

    3.If User is Site admin and tries to login from wp-login.php,that means he is interested in login to wp-admin,so let him go to the mu dashboard.

    here is the code you need to put in your bp-custom.php and It will handle it all for you.

    add_filter("login_redirect","bpdev_redirect_to_profile",10,3);

    function bpdev_redirect_to_profile($redirect_to_calculated,$redirect_url_specified,$user)
    {
    if(empty($redirect_to_calculated))
    $redirect_to_calculated=admin_url();

    /*if the user is not site admin,redirect to his/her profile*/
    if(!is_site_admin($user->user_login))
    return bp_core_get_user_domain($user->ID );
    else
    return $redirect_to_calculated; /*if site admin or not logged in,do not do anything much*/

    }

    and No need to modify anything else.

    Edit:I tried posting code twice ,hopefully the code is their in this post.


    peterverkooijen
    Participant

    @peterverkooijen

    Thanks for this excellent bit of code Brajesh Singh! Should be part of the core imho.


    abcde666
    Participant

    @erich73

    agree that it should be in Core, that a user will be immediately at his own Profile-page after log-in.

    Hope to see this.

    Thanks Andy !

    ;-)


    Anonymous
    Inactive

    Sorry to sound like a dummy, but Brajesh — where do I put this code? I need this functionality. But I can’t find a bp-custom.php on my server. I have Buddy Press activated and am using the New Yorker theme — http://www.thecommunity.com/wpmu .

    Thanks very much.

    Mary


    r-a-y
    Keymaster

    @r-a-y

    Create a file called /wp-content/plugins/bp-custom.php and put the following code in there:

    <?php
    add_filter("login_redirect","bpdev_redirect_to_profile",10,3);

    function bpdev_redirect_to_profile($redirect_to_calculated,$redirect_url_specified,$user)
    {
    if(empty($redirect_to_calculated))
    $redirect_to_calculated=admin_url();

    /*if the user is not site admin,redirect to his/her profile*/
    if(!is_site_admin($user->user_login))
    return bp_core_get_user_domain($user->ID );
    else
    return $redirect_to_calculated; /*if site admin or not logged in,do not do anything much*/

    }

    ?>

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Login re-direct’ is closed to new replies.
Skip to toolbar