a direct link from my shop site to the logged in users admin panel

<?php global $user_login;
									get_currentuserinfo();
echo"<a href=\"$BASE_URL$user_login/wp-admin/\">dashboard</a>";
?>

Hi there
I am using the above code to make a link to the dashboard form the current logged in users page. It kind of works, but only when I click on it from the main page.
If I click on it from another page it adds the echoed url onto the end of the current page url in the browser rather than clearing the urll from the browser and then echoing the url I need.

I hope that makes sense to someone.

I am not a php expert and it took me a couple of hours to get this far :slight_smile:

  • DavidM
    • DEV MAN’s Mascot

    Hi cstevenson,

    I think that would depend on where $BASE_URL is defined. Assuming it is defined, you might still have to ensure it has a trailing slash at the end of it. In any case, perhaps the following simple rewrite might fix that for ya?

    <?php
    global $current_user;
    get_currentuserinfo();
    echo '<a href="' . bloginfo('url') . '/' . $current_user->user_login . '/wp-admin/">dashboard<a>';
    ?>

    I guess that assumes your user login is also the url/slug/name of the site being logged into, no?

    Cheers,
    David

  • cstevenson
    • Site Builder, Child of Zeus

    ok cheers
    ill try it now

    I also forgot to add the http:// at the beginning, which meant the browser was reading the echoed line as a directory change rather than an http request

    (I think thats what happened anyway, I am learning)

  • cstevenson
    • Site Builder, Child of Zeus

    yes that worked thanks although weirdly it adds the full url to the displayed text on the page..

    So instead of "dashboard" it says "http://mysite.co.uk/dashboard"

    I rekon I can work that out though, thanks for the code, I can adapt that to all the links I need.

  • DavidM
    • DEV MAN’s Mascot

    Hi cstevenson,

    If your $BASE_URL had the http:// added to it, you wouldn't need to add that here, however, given how it was in the code you posted, I really couldn't imagine it working, as the $BASE_URL$user_login wouldn't add those two variables together. I'd think they would throw an error.

    In any case, could you let me know how that adjusted snippet works for ya?

    Thanks,
    David

  • cstevenson
    • Site Builder, Child of Zeus
    <?php global $user_login;
    get_currentuserinfo();
    echo"<a href=\"http://mysite.co.uk/wpshop/$user_login/\">my shop |</a>";
    echo"<a href=\"http://mysite.co.uk/wpshop/$user_login/wp-admin/\">settings |</a>";
    ?>

    Ive also added the http to the above which also works. Hard coding the url as well.
    But your method is neater if I need to move the site somewhere else.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.