Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I hope this problem does not have too complicated of a solution. I also hope it isn't too easy so I don't feel like a fool for not figuring it out :)

On my website, (Wordpress), I have Peter's redirect plugin that redirects users after login to their specified personal page (not profile.php). This is great.

However, after leaving their page, the only way to get back to it is to type the address to the page in the address bar, or logout/login again.

Is there a way I can create a normal link, that will recognize the currently logged in user, and redirect them accordingly to their personal page?

I know this may be basic, but I have search relentlessly through various sites, and other venues to locate an answer, and cannot seem to find one. I imagine it is because I am missing a 'key' word in my search, or it is so basic no one feels it needs to be covered.

I also looked at the source code for the a fore mentioned redirect plugin to find this:

$current_user = wp_get_current_user();
$redirect_to = admin_url();
$redirect_url = redirect_wrapper( $redirect_to, '', $current_user );
wp_redirect( $redirect_url );
die();`

I know this probably means something to someone, would this work? If so, where could/should I put it to get the desired results?

share|improve this question
    
Try adding a <a href="<?php echo $redirect_url; ?>">Some Link Text</a> and see if it works. You don't need the wp_redirect(...) and die() parts. –  akTed Feb 11 '13 at 3:34
    
Give us the code of the 'redirect_wrapper' function. That's where the URL you want is being formed, apparently. –  tbuteler Feb 11 '13 at 14:59

1 Answer 1

up vote 0 down vote accepted

Thank you so much for the responses. Using both of the ideas received I started to play a little with the code, although I was not sure what to do with them.

I came up with a solution that works very well for me, I created a new template in my theme called 'redirect.php'. At the very beginning of the page template I inserted the code found in Peter's login Redirect.

$current_user = wp_get_current_user();
$redirect_to = admin_url();
$redirect_url = redirect_wrapper( $redirect_to, '', $current_user );
wp_redirect( $redirect_url );
die();

Then I added a link to that new template in regular html. When clicked, it automatically looks up the user, and sends the user to their page that is listed in Peter's login redirect.

What you need for this obviously is; Peter's login/redirect plugin, and to create your own blank template with the code snippet above. Thanks again for everyone, it helped me realize where to look and what to put.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.