Custom Login Redirect
-
A lot of login redirect plugins allow you to choose the url you want someone to be redirected to. This works great if it’s a static URL. But how do I create a url that reads the users username so I can have the plugin redirect the user to their profile wall? Is there a variable in BuddyPress that represents the username of the person logging in? Something like %%buddypress_username%%.
I am thinking the url will look like this; http://milemarker20.com/members/(insert variable for username)/
-
bp_loggedin_user_domain()
The codex is worth checking also there have been quite a few posts here in general on re-directs so those may help.
So @shanebp would the link look like this?
http://milemarker20.com/members/bp_loggedin_user_domain()/
@hugo where do I access the codex?I found this post https://buddypress.org/support/topic/create-a-link-or-redirect/
And the question answered by @henrywright is what I am going for only I need the dynamic value to represent the username so anyone who logs in will be directed to their own profile wall.
This link – http://milemarker20.com/members/bp_loggedin_user_domain()/ did not work.
Admittedly I am not a programmer, I know a decent amount of html but not enough to really understand what is happening, I’m just trying to avoid paying $50 an hour to a programmer who will take 30 seconds to do this for me.
@ad4m_wordpress
See my snippet here for one solution:Redirect logged out visitors to home, and logged in users to profile
Thanks for the link @bphelp.
I’d rather not implement a blanket solution to the core of the site. I’d like to know how to construct an individual link to redirect all users to their individual profile wall.
Is there a parameter that when inserted into a common html link it represents the dynamic url of the users actual username?
@ad4m_wordpress
Not really sure what your trying to accomplish but you need to understand the dynamic nature when a user logs in and is redirected to their profile is in PHP language and there is no full html equivalent that could pull that info from the database to take that user to their profile.
I am certain you will have to use PHP to make this happen. If you copy and pasted the snippet in the link I supplied into bp-custom.php it shouldn’t take a few minutes and is very simple.It sounds like the function is more complex than I realize.
A use case, just for clarification, would be this;
There is a plugin that inserts a dropdown box in the log in screen.
As the admin you can select what values go into the dropdown box.
In order to activate values for population in the dropdown you give them a name and assign a url.
This would allow me to show users who are logging in multiple options for where they can be redirected to after the log in. The drop down box could have a value for, all group activity, all site activity, a specific page with featured members, or any number of things to help the user be exposed to more pages as part of their logging in.
But since there is no 1 url for directing a member to their profile page I was hoping there was an html variable to insert into the url to redirect members. But if there is not because the function of logging in requires php than I understand and can work towards a different solution.
@ad4m_wordpress
Just out of curiosity what plugin are you referring to that creates this dropdown box on the login screen? Most plugins can be modified to suit your needs if you don’t mind editing the code.I would LOVE to be able to edit the code. The plugin url is here –
https://wordpress.org/plugins/custom-login-redirect/
I would LOVE to be able to change the ‘default’ value to say ‘My Profile Wall’ and then hard code it so it using the php method you mentioned above so it gives users the option of redirecting themselves to their profile wall.
You can see a live version of it on my site http://milemarker20.com/wp-login.php
(I plan to change the location of the login url to help prevent spam.)
@ad4m_wordpress
On lines 471-474 in that plugins custom-login-redirect.php maybe try switching this:<option value="">Default</option> <?php if (get_option('custom_login_redirect_display6','yes') == 'yes'){ ?> <option value="<?php home_url ?>wp-admin/">Dashboard</option> <?php } ?>
To to something like this:
<option value="">My Profile Wall</option> <?php if (get_option('custom_login_redirect_display6','yes') == 'yes'){ ?> <option value="<?php home_url . '/members/' . bp_core_get_username( bp_loggedin_user_id() ) . '/profile/' ?>My Profile Wall</option> <?php } ?>
Note that I haven’t tested this at all so test at your own discretion.
@ad4m_wordpress Codex is another word for documentation, ‘codify’, here it’s the link on the main menu labelled ‘Documentation’ The WP documentation is also referred to as ‘The Codex’.
Your initial requirement would have been served by the simple use of one of the provided BP template tags e.g:
<?php echo bp_core_get_userlink(bp_loggedin_user_id()); ?>
which will render a fully formed link and also takes parameters.Iām just trying to avoid paying $50 an hour to a programmer who will take 30 seconds to do this for me.
In that case you will need to learn to code! That is how you will avoid the skilled services of a developer š
@hugo – thanks for helping me out, I really do appreciate it.
If I could go back to school I absolutely would learn to code.
- The topic ‘Custom Login Redirect’ is closed to new replies.