Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Dynamic URL's for Buddypress User Profiles, Friends etc


  • craig
    Participant

    @craigheyworth

    Hi All,

    After sifting through the internet, I can’t seem to find a simple way to create a dynamic url for my buddypress users. I’m looking at creating a simple custom menu for user to have direct links to their profile, friends, messages, etc.

    I set up a buddypress site around 2 years ago and sold it, however I remember this being very simple but can’t remember how I did it.

    Does anyone have some solid links that I’ve missed that explains how to done?

Viewing 25 replies - 1 through 25 (of 27 total)

  • craig
    Participant

    @craigheyworth

    Ah, this is what I believe I was using

    <a href="http://yoursite.com/members/%USERNAME%/">Profile</a>

    however, this no longer works :-/. Anyone know why that would be?


    modemlooper
    Moderator

    @modemlooper

    <?php echo bp_core_get_userlink( bp_loggedin_user_id() ); ?>

    or

    <a href="<?php echo bp_loggedin_user_domain(); ?>">Profile</a>


    craig
    Participant

    @craigheyworth

    Thanks for the reply bud.

    I’ve just added
    <a href="<?php echo bp_loggedin_user_domain(); ?>">Profile</a>
    to a widget, and it’s giving me a 404 page. Probably because I’ve amended the url’s for users. They show under. http://www.mydomain.com/username (ie: I’ve removed ‘/members/’)

    I’m wanting to create a menu with personalized links ie:

    quick links:
    profile
    your messages
    your friends
    edit profile

    That type of thing


    modemlooper
    Moderator

    @modemlooper

    How have you removed /members/? BuddyPress as a way to do that so links get changed automatically.

    add_filter( 'bp_core_enable_root_profiles', '__return_true' );


    Ali Hendaoui
    Participant

    @horsesiq

    Hello, I have a quick questions and it would be great if I have it answered,I am using buddy press, 0n my site http://horsesiq.com/, and when members are added it shows like this: http://horsesiq.com/members/christie/, now is there anyway that I can get rid of the members so that I can have a link like this: http://horsesiq.com/christie, please let me know if there is any solution.

    Thank you


    @mercime
    Participant

    @mercime


    modemlooper
    Moderator

    @modemlooper

    Use the code I posted above


    Ali Hendaoui
    Participant

    @horsesiq

    Thank you and I am really sorry for the inconvenience, if I need anything else I will start a new topic.


    Ali Hendaoui
    Participant

    @horsesiq

    @modemlooper, thank you so much that code works, really appreciate the help


    craig
    Participant

    @craigheyworth

    Hey

    As this is a personal project, I’m only able to work on it at weekends.

    So I’m trying to get links as I say directly to the logged in users profile, messages, friends etc in a widget.

    What code would I need for this?


    bp-help
    Participant

    @bphelp

    @craigheyworth
    You would have to enable php in widgets before you do anything. You can use this code in your themes functions.php to enable it:

    
    add_filter('widget_text','execute_php',100);
    function execute_php($html){
         if(strpos($html,"<"."?php")!==false){
              ob_start();
              eval("?".">".$html);
              $html=ob_get_contents();
              ob_end_clean();
         }
         return $html;
    }
    

    Then in a text widget you could add @modemloopers code above for examples.


    craig
    Participant

    @craigheyworth

    ok great, that worked.

    and now how would I get the users messages, friends etc. custom links within a users profile?


    modemlooper
    Moderator

    @modemlooper

    I would not do that. Not safe. You can create your own widgets.


    craig
    Participant

    @craigheyworth

    how do you mean?

    I’m after a widget with some custom links basically… to the users profile (which we now have, thank you), their friends, messages etc.


    bp-help
    Participant

    @bphelp

    @craigheyworth
    I guess that is good info if you knew in the first place how to create your own widgets and I am assuming you wouldn’t otherwise you wouldn’t have asked for help. Also if one does not elaborate why it is not safe, I personally would like to here the explanation as to why myself. You just wanted to create some dynamic links correct? Its not like your giving them a form to execute malicious php code in. Saying it is not safe given the circumstances of the specific use is not really valid in my opinion without a clear explanation.


    craig
    Participant

    @craigheyworth

    huh? – think you may have pointed your comment the wrong way bud.

    So coming back to point, I’ve added to the function.php the code allowing php in the widgets, and I’ve then tested both of the following

    <a href="<?php echo bp_loggedin_user_domain(); ?>">Profile</a>
    <?php echo bp_core_get_userlink( bp_loggedin_user_id() ); ?>

    both of which now work as links to the profile. That’s one part of the initial question so thanks. The other is how do I change the code here to also link to the users /messages, /friends etc… does anyone know?


    bp-help
    Participant

    @bphelp

    @craigheyworth
    I was actually just responding about it being dangerous. I simply meant if someone tells you it is dangerous they should at least say why, after all you was only going to use it to add links.


    craig
    Participant

    @craigheyworth

    oh i see. Well that’s correct. I’m just looking to create links. Would you know how to create some links directly to users different profile elements?


    bp-help
    Participant

    @bphelp

    @craigheyworth
    You can try these with the text widget providing you enabled php like my example above.
    For Friends Link:
    user_login . ‘/friends/’; ?>”>Friends

    For Messages Link:
    user_login . ‘/messages/’; ?>”>Messages

    May not be perfect but it works. You could add an unordered list and wrap them in list items and style them how you choose. Good luck!


    craig
    Participant

    @craigheyworth

    thanks for the reply.

    I’m adding this to the widget but unfortunately I’m just getting the code display, or when I edit it, errors.

    Is this definitely correct?


    bp-help
    Participant

    @bphelp

    @craigheyworth
    Oops I forgot to wrap the code lets try again:
    For Friends Link:

    
    <a href="<?php global $current_user; echo home_url() . '/members/' . $current_user->user_login . '/friends/'; ?>">Friends</a>
    

    For Messages Link:

    
    <a href="<?php global $current_user; echo home_url() . '/members/' . $current_user->user_login . '/messages/'; ?>">Messages</a>
    

    craig
    Participant

    @craigheyworth

    ah hah… those work great!

    … god knows who marked this as resolved before now… haha. Pet peev when forum goers assume their answer’s gonna solve the problem before the thread poster even gets back.

    Anyway, thanks! Exactly what I was looking for


    bp-help
    Participant

    @bphelp

    @craigheyworth
    Your welcome glad I could assist you!


    craig
    Participant

    @craigheyworth

    oh, and having said that… is there a way to add the same links into the nav menu?


    bp-help
    Participant

    @bphelp

    @craigheyworth
    Where there is a will there is always a way!

Viewing 25 replies - 1 through 25 (of 27 total)
  • The topic ‘[Resolved] Dynamic URL's for Buddypress User Profiles, Friends etc’ is closed to new replies.
Skip to toolbar