[Resolved] Logged-In User Profile Link URL
-
I have searched and searched for at least 2 hours now and I am not finding a solution.
I am setting up a community through Buddypress on a client site. Here is what it looks like so far: http://www.soulwomansanctuary.com/community/
I have set up the sidebar and WordPress menu to have links to things like Community Members. Activity, Forum, etc. I have also added a link called “Edit Profile” which I would like to link to the user’s profile page. I have it set up this way because I am not going to be using the normal Buddypress sidebar widget. I am going through Wishlist member so that only members can access the community.
I have tried all different things to get the link and nothing seems to be working.
Here are some of the links that people have suggested using:
http://soulwomansanctuary.com/community-members/USERNAME/profile/
http://soulwomansanctuary.com/community-members/%username%/profileI appreciate any help that you might have.
-
It’s a dynamic URL — i.e. it changes for each user, so you can’t just type in a single link in html.
It’s easy to do with a bit of PHP code though — just call the function bp_loggedin_user_domain()
Something like this should work:
`if ( is_user_logged_in() ) {
global $current_user;
$username = $current_user->user_login;
echo ‘ | My Profile‘;
}`Thankyou so much for your fast reply! Can I just insert this code into a text widget? Or do I need a special plugin?
That did not work for me Toby. I even added a special PHP widget. Any ideas?
Use the function I provided – there’s no need to try and construct the URL yourself (as Toby has tried).
I am not great with code so my apologies, but how would I do that exactly? I am trying to add a link in the sidebar along with the other community links. Do I need the PHP widget and then add specific code with your “function”? Can you provide the exact code? Sorry again to be a pain. My client is about to give up on it altogether so I just want to try one last time to see if we can get it working.
Thanks so much for your help. I appreciate it.
@rogercoathup is right. Use `bp_loggedin_user_domain()` and not my function. …note to self, update header code in my theme…
Regarding how and where to add the code, try adding the following to your template:
“
What is the result?
Hi Toby. I am not seeing any code. Maybe you can email it to me? Dawn(at)DPK-GraphicDesign.com. I soooo appreciate your help.
And just a reminder… I need the code to add to the widget to get the link to work under the other links in the sidebar. Thankyou!
I am still looking for help. Anyone?
I am looking for the code to this function as well! I would like to add it as a main menu item. would appreciate any help!
https://wordpress.org/extend/plugins/buddypress-profile-menu/screenshots/
@paintermommy k8peterson Create custom menu and use the menu widget for sidebar.
thank you @mercime !
I had no idea that this plugin existed. Thankyou!
@paintermommy did you ever get this to work with the wishlist plugin? Are your forums private and only for paid members?
@mercime, your solution works for my site. However, I’dd like to add the menu as a child menu. Looking at the source code, I know this much information about the parent menu (id=”menu-item-822″). How would I proceed? Please assist.
Thanks.
@bookee is this related to the login link you wanted in other post?
@mercime, thanks for the reply. Yes, this is somewhat related with my request on the other post. In this case, the menu position being the different factor. I appreciate the support, I truly do.
@paintermommy
try thisa href="<?php bp_loggedinuser_link() ?>"> profile
To solve this I decided to hijack a page. If the member is logged in, they get their profile, otherwise, they go to a signup page.
Just pop the following code into your functions.php file… and create a page named ‘profile’. Now you can add that page to your WP menu and it should do what you need.
function redirect2profile(){ include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); if($_SERVER['REQUEST_URI'] == '/profile/' && is_plugin_active('buddypress/bp-loader.php') && is_user_logged_in()){ global $current_user; wp_redirect( get_bloginfo('url') . '/members/'. $current_user->user_login . '/profile/'); exit(); } } add_action('init', 'redirect2profile');
@jackreichert Worked perfectly for me. thank you!
A few years ago I set up my first buddypress site and sold it.
I definitely remember using a dynamic url for links to the users profile, activity stream etc.
It was something like:
http://www.mydomain.com/member/$profile/
Are we all sure that this can no longer be done?
@jackreichert your a bloody genius Mr Jacoby, buddyPress just gets better & then some, thanks you mate!
Do you mind if I include your code in my “n00bish” wp plugin:
function redirect2profile(){
include_once( ABSPATH . ‘wp-admin/includes/plugin.php’ );
if($_SERVER[‘REQUEST_URI’] == ‘/profile/’ && is_plugin_active(‘buddypress/bp-loader.php’) && is_user_logged_in()){
global $current_user;
wp_redirect( get_bloginfo(‘url’) . ‘/members/’. $current_user->user_login . ‘/profile/’);
exit();
}
}
add_action(‘init’, ‘redirect2profile’);I’m just beginning my journey into php & I’ve always wanted to write a toolbox for wp and buddy, you gotta start somewhere : )
PS:Do I credit you in the plugin as a contributor?
Best Regards
John HartHi there!
This worked quite fine for me, but i have the problem that this code doesnt bring me to a signup page when you aren’t logged in.
I tried to add the redirect with “else” but it didn’t work for me either.
The code has now changed, since I tried to figure out why it doesn’t redirect me to my register page.I’m not very skilled with PHP so maybe someone can help me out.
I want the code to redirect the not logged in user to a register pagefunction redirect2profile(){ include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); if ( is_user_logged_in()){ if ($_SERVER['REQUEST_URI'] == '/profile/' && is_plugin_active('buddypress/bp-loader.php')) { global $current_user; wp_redirect( get_bloginfo('url') . '/member/'. $current_user->user_login . '/profile/'); exit(); } } else { if ($_SERVER['REQUEST_URI'] == '/profile/' && is_plugin_active('buddypress/bp-loader.php')) { wp_redirect( get_bloginfo('url') . '/register/'); exit(); } } } add_action('init', 'redirect2profile');
- The topic ‘[Resolved] Logged-In User Profile Link URL’ is closed to new replies.