The MU forums have moved to WordPress.org

Login form on home page (47 posts)

  1. amanzi
    Member
    Posted 17 years ago #

    Would anyone like to share their code for putting a login form on the home page of their site? The idea is that a user would be able to login on the home page and would either be redirected to their blog's home page or their admin area.

    I found a couple of old threads on these forums about how to do this, but seeing that the WPMU code has changed so much I was hoping that someone else has done all the hard work of getting it working! :)

    Thanks - Stuart.

  2. Xen
    Member
    Posted 17 years ago #

    I'll look into this, i'd find it quite useful as well :-p

  3. drmike
    Member
    Posted 17 years ago #

    Wouldn't it just be cut and paste the signin form out of wp-login.php?

  4. Xen
    Member
    Posted 17 years ago #

    formatting issues I should imagine... it'll distort sidebars.. but in essence yes :-p

  5. amanzi
    Member
    Posted 17 years ago #

    I implemented this previously with some code that I got from these forums - but I can't find the original post. Part of the solution is that if the user is already logged in, they won't see the login form - just links to their home page or admin area. I've got some time today, I may work on it again.

  6. samchng
    Member
    Posted 17 years ago #

    As far as i am concern, the login form codes are there through the search. I am currently using that without any problems. If you cant find it through search, try looking at source codes from wugga, wurk.net, and many other sites on AndWat's blogroll.

  7. amanzi
    Member
    Posted 17 years ago #

    OK - here's my first hack/attempt. I put this function in a functions.php file in my theme's folder. Then just drop in the home_page_login_form() in the header of my home page. You can see it in action here: http://blogtown.co.nz

    As you can see from the coding below, I'm no expert - use this at your risk! In fact, I wouldn't recommend copying it line for line, because you'll need to add your own css formatting to make it work with your theme.

    <?php
    function home_page_login_form() {
    global $current_user, $blog_id;

    if ( ! is_user_logged_in() ) {
    ?>
    <div id="headerlogin">
    <form name="loginform" id="loginform" action="wp-login.php" method="post">
    <h2>Already a member? Sign in here...</h2>
    <div class="left">
    Username:<br />
    <input type="text" name="log" id="log" value="" size="20" tabindex="1" /><br />
    <input name="rememberme" type="checkbox" id="rememberme" value="forever" tabindex="3" /> Remember me
    </div>
    <div class="right">
    Password:<br />
    <input type="password" name="pwd" id="pwd" value="" size="20" tabindex="2" /><br />
    <input type="submit" name="submit" id="submitform" value="Login &raquo;" tabindex="4" />
    <input type="hidden" name="redirect_to" value="/" />
    </div>
    </form>
    </div>
    <?php
    } else {
    $blogs = get_blogs_of_user($current_user->ID);
    $username = $current_user->user_login;
    $siteurl= get_settings('siteurl');
    ?>
    <div id="headerlogin">
    <h2>Hi, <?php echo $username; ?>! (<a href="/wp-login.php?action=logout&amp;redirect_to=<?php echo $siteurl; ?>">Logout</a>)</h2>
    <p>Here are your blogs:</p>
    <ul>
    <?php

    if ( ! empty($blogs) ) foreach ( $blogs as $blog ) {
    echo "<li><a href='http://" . $blog->domain . $blog->path . "'>" . $blog->domain . $blog->path . "</a> | <a href='http://" . $blog->domain . $blog->path . "wp-admin/'>Admin page</a></li>";
    }
    ?>
    </ul>
    </div>
    <?php
    }
    }
    ?>

  8. samchng
    Member
    Posted 17 years ago #

    Cool new form amanzi :)))

  9. drmike
    Member
    Posted 17 years ago #

    Thanks.

  10. jeanvallery
    Member
    Posted 17 years ago #

    I haven't the code but a programmer named Jason Douglas at jason@jdouglasmedia.com did it for me on two diffrent websites. the first on the wordpress mu page http://www.bicyclejournals.net and on a completely diffrent webpage at http://www.bicyclejournal.net which isn't a blog page.

    Jean Andre Vallery
    Sarasota Florida
    941-232-2183

  11. mshao
    Member
    Posted 17 years ago #

    amanzi,
    I tried your function home_page_login_form(). I have found one problem with IE. Once I login successfully, the web page displays my blog name and a link to my blog site and a link to my Site Admin. After I click the site link, it takes me to my blog site, which is great. Except on the blog page, it doesn't know I have logged in. So it displays Login link instead of Site Admin under Meta section. You have to clear all the cookies before replicate the problem.

    I have aslo tried the standard way of login used on wp.com. But in IE, it asks me to login twice. Also the Logout doesn't work. However, admin account works fine.

    So the workaround I have is having a link on my home page to the standalone Login page. This way, it seems to clear away all the cookie issues.

    Any advise.

    Thanks

    Michael

  12. Crimsontech
    Member
    Posted 17 years ago #

    Wouldn't this be better implemented as a widget? Embrace the widgets, for they will set you free. :P

  13. andrea_r
    Moderator
    Posted 17 years ago #

    Already did:
    http://www.atypicalhomeschool.net/wordpress-plugins/ah-login-widget.txt

    Rename to .php and plunk in with your widgets, I have it in the mu-plugins folder. This particular plugin does NOT redirect though. Useful for when users have comments set to "logged in users only" and someone wants to comment quickly.

    See it in action here:
    http://homeschooljournal.net - look on the top right sidebar.

  14. kahless
    Member
    Posted 17 years ago #

    In the latest revision, the code by amanzi does not redirect. I am presented with the login form on the page again. Refreshing the browser shows that the user was logged in but for some reason the redirect isn't working. Any suggestion on what I should do?

    http://test.blogs.wooster.edu username:test password:testuser

    I need the site to be live on Monday and this issue needs to be solved by the end of the week.

  15. drmike
    Member
    Posted 17 years ago #

    What's it redirecting to? I'm on one of those locked down terminals today. Don't mind helping but I can't unzip teh file here to look at the code.

  16. kahless
    Member
    Posted 17 years ago #

    Mike,

    So if you go to the test site listed and login, you used to see the same page so http://test.blogs.wooster.edu/ but since you had logged in you saw a list of your blogs instead of the login form. Now you see the login form and it takes a refresh of the window to see your list of blogs. The code has redirect_to with a value of / I would like the old behavior to work but since I need to go live I am copying the wp-login.php stuff into the function so it redirects to wp-admin. This is working, but not as cool as the old behavior. All I can figure is some strangeness with the redirect.

  17. kahless
    Member
    Posted 17 years ago #

    Oh and no code to download. I'm just using the code listed above with some mods for CSS styling.

  18. drmike
    Member
    Posted 17 years ago #

    No, I meant I couldn't unzip the zip file that someone stuck up here earlier here today.

    Redirects for me. When I login, I get presented the wp-admin .php page.

    Using Netscape 7.2.

  19. kahless
    Member
    Posted 17 years ago #

    That's because I changed the redirect. It should redirect back to the main page for the blog but be showing a list of blogs that you are registered on. This wasn't working I was getting the login form on the main page and a refresh was required to show my list of blogs and confirm I had logged in. This was unacceptable so I changed the behavior to something my boss will be able to live with come Monday.

  20. corourke
    Member
    Posted 17 years ago #

    This is an awesome hack. I was up a large part of the night trying to do this myself and then when I couldn't quite get it to work, I searched the forums and viola! A pity I'm so headstrong and have to try things for myself first.

    What would I change the
    $username = $current_user->user_login;

    line for it to show the user name instead (with it defaulting back to login if there wasn't one..)

  21. corourke
    Member
    Posted 17 years ago #

    Figured out how to have it use the "friendly name":

    Changing the line
    $username = $current_user->user_login
    to
    $username = $current_user->display_name

    The display_name defaults to the user_login unless the user has changed the display name setting in the user profile. This allows much friendlier names (mine for example now says "hi, Chris")

  22. umair
    Member
    Posted 17 years ago #

    hey guys !

    i m using the widget thingie for the login form on main page. its works fine as long as login part is concerened. But when it redirects to the main page, the same page with login boxes appears. It actually has already logged in, as refreshing the page shows the list of all the registered blogs. How can i implement something like automatic refreshing ?

  23. demonicume
    Member
    Posted 17 years ago #

    this sounds ike a cookie or cache issue. when i activated wp-cache, i got the same thing. i was rapidly switching between logins and i got tired of having to clear the cache every few minutes. i had to deactivate it. :-(

  24. macuser9214
    Member
    Posted 16 years ago #

    How would I call the script, if my blog is in another directory?

  25. macuser9214
    Member
    Posted 16 years ago #

    ANYONE??

  26. macuser9214
    Member
    Posted 16 years ago #

    Got it working with THIS: (replace site url with your BLOG url)

    <form name="loginform" id="loginform" action="(SITEURL)" method="post">

    <label>Username:<input type="text" name="log" id="log" value="" size="20" tabindex="1" /></label>

    <label>Password: <input type="password" name="pwd" id="pwd" value="" size="20" tabindex="2" /></label>

    <label><input name="rememberme" type="checkbox" id="rememberme" value="forever" tabindex="3" />Remember me</label>

    <input type="submit" name="submit" id="login" value="Login »" tabindex="4" />

    </form>

  27. mixle
    Blocked
    Posted 16 years ago #

    I have made a login form on my home page that redirects users to their own blog dashboard.

    What I did was to download the fancy login script from
    http://trac.mu.wordpress.org/wiki/FancyLogin

    and did the following with it
    Open it in your text editor notepad or whatever you use, where you will see http://###/wp-signup.php change the ### to the url of your main site, do this wherever the http://###/wp-signup.php appears.

    Save it as fancy login script.php.

    So now you have got the script what do you do with it.

    Choose the theme that you want to use for your main blog,

    Open up your text editor. and paste the following in to it

    <div id=”normalcontent”>
    <h3><?php bloginfo(’name’);?> <span><?php bloginfo(’description’);?> </span></h3>
    <div class=”contentarea”>
    <?php if (is_user_logged_in()): { ?>

  28. <?php global $user_identity, $current_user;

    get_currentuserinfo();

    _e(’Hello, ‘);

    echo $user_identity;

    _e(’!');

    echo “

  29. \n”;

    echo “

  30. \n”;

    _e(’Here\’s a list of your current blogs:’);

    $blogs = get_blogs_of_user($current_user->ID);

    echo “

    \n”;

    ?>

  31. <?php _e(’Need an additional blog?’); ?>
  32. <?php } endif; ?>

    <?php if ( !is_user_logged_in()): { ?>

  33. <?php _e(’Create your own blog:’); ?>

    Signup in under a minute!

  34. <?php _e(’Already have an account?’); ?>

      <form name=”loginform” id=”loginform” action=”http://###/wp-login.php” method=”post”>

      <label>Username:
      <input type=”text” name=”log” id=”log” value=”" size=”20″ tabindex=”1″ /></label>

      <label>Password:
      <input type=”password” name=”pwd” id=”pwd” value=”" size=”20″ tabindex=”2″ /></label>

      <label><input name=”rememberme” type=”checkbox” id=”rememberme” value=”forever” tabindex=”3″ />Remember me</label>

      <input type=”submit” name=”submit” id=”login” value=”Login »” tabindex=”4″ />

      </form>

  35. And then save it as intro.php ( remember to change the### to your blog url)

    Upload the intro.php into whatever theme you have chosen as your main site one.

    Now open up the index.php of the theme and add

    <?php include_once(TEMPLATEPATH.’/intro.php’);?>

    I added this on my site like this.

    top two lines of index.php

    <?php get_header(); ?><br>

    <div class=”narrow_column”><br>

    now add <?php include_once(TEMPLATEPATH.’/intro.php’);?>

    That will put a login form on your home blog index page.

    If you want to add text etc as well at the end of the intro page that you made you will see

    </form>

    Your text can go here.

    If you don’t want a post to appear at the bottom of this edit out the post function in index.php , and so that you don’t have - Not Found Sorry, but you are looking for something that isn’t here.

    edit this out of the theme index.php as well. You will now have a fancy login form plus any text you want on the home page of your main blog. See a demo of it at my site
    http://uk2uonline.info/

    Hope this helps.

  • drmike
    Member
    Posted 16 years ago #

    YOu'll note that the forums mucked up your code. if you want to try again, please your code inbetween backticks. That's the key above the tab and to teh left of the '1' key on a standard PC keyboard.

    Else copy it to a txt file, zip it up and put it up on http://wpmudevorg.wordpress.com That would probably be best.

  • mixle
    Blocked
    Posted 16 years ago #

    Thanks for reply drmike, I have made into a text file and zipped it, but when I logged into wpmudev.org I only have the option of putting into a post, I can't see where to upload a zip file to.

  • mixle
    Blocked
    Posted 16 years ago #

    Managed to upload to http://wpmudevorg.wordpress.com/ as a zip file
    So anyone that wants this can download the zip file from there.
    It contains full instructions etc.

  • 1 2

    About this Topic