Skip to:
Content
Pages
Categories
Search
Top
Bottom

Login moved from sidebar to admin bar

Viewing 13 replies - 1 through 13 (of 13 total)
  • @r-a-y

    Keymaster

    If you’re using a child theme of the default BP theme, use this tidbit to remove the login widget from the sidebar:

    https://buddypress.org/forums/topic/how-to-remove-login-sidebar-from-bp-12-default-theme#post-46264

    To add the login form to the BuddyBar, you’ll need to create a function that outputs the login form and then you’ll need to hook it to the BuddyBar.

    Here’s some sample code that you can add to your theme’s functions.php:

    function my_login_bar() {
    // basically a copy of the login form from the BP sidebar
    ?>
    <form name="login-form" id="sidebar-login-form" class="standard-form" action="<?php echo site_url( 'wp-login.php', 'login' ) ?>" method="post">
    <label><?php _e( 'Username', 'buddypress' ) ?><br />
    <input type="text" name="log" id="sidebar-user-login" class="input" value="<?php echo attribute_escape(stripslashes($user_login)); ?>" /></label>

    <label><?php _e( 'Password', 'buddypress' ) ?><br />
    <input type="password" name="pwd" id="sidebar-user-pass" class="input" value="" /></label>

    <p class="forgetmenot"><label><input name="rememberme" type="checkbox" id="sidebar-rememberme" value="forever" /> <?php _e( 'Remember Me', 'buddypress' ) ?></label></p>

    <input type="submit" name="wp-submit" id="sidebar-wp-submit" value="<?php _e('Log In'); ?>" tabindex="100" />
    <input type="hidden" name="testcookie" value="1" />
    </form>
    <?php
    }
    // the magic that hooks your my_login_bar() function to the BuddyBar
    add_action( 'bp_adminbar_menus', 'my_login_bar', 2);

    Keep in mind, you’ll need to style the form to make it look nice in the admin bar, but that should get you started.

    More info in modifying the BuddyBar can be found here:

    https://codex.buddypress.org/how-to-guides/modifying-the-buddypress-admin-bar/

    @imayana

    Member

    wow, how cool ray thanks :)

    will prolly work this out tonight

    this is actually simple enough I think I can do it.

    @absticles

    Participant

    Hi there.

    I’ve just had a go at implementing this and it’s all working fine. But I was just wondering whether it was possible to run this function if the user is logged out only?

    Thanks,
    Abi

    @r-a-y

    Keymaster

    Wrap the whole block in a !is_user_logged_in() conditional.

    @absticles

    Participant

    Hi again.

    Firstly, thanks so much for your help r-a-y! I managed to get it working…. But then it has issues when I try to login or out. I think it’s probably to do with where I’ve placed my if/else statements. Just can’t seem to get it working! The first part looks like this:

    if ( is_user_logged_in() ) : ?>

    Followed by the url to log out, then the else statement and then the function… Any idea where I’m going wrong?

    Thanks,
    Abi

    @r-a-y

    Keymaster

    @absticles – use:

    if ( !is_user_logged_in() ) : ?>

    Note the exclamation mark.

    @absticles

    Participant

    Can I post all of my code here? I don’t know the right tags to post it! It’s still messing up!

    Thanks,
    Abi

    @r-a-y

    Keymaster

    @absticles

    Participant

    THANK YOUUU! You are an absolute star.

    @quirhijn

    Member

    Hey guys,

    What if it’s otherwise. I have installed buddypress yesterday, and I can’t find the widget (or tool) to get the login in the sidebar (just like on this website) On my buddypress (the default 1.2.3. theme) there is only the text saying to sign in or register, and not the username and password fields. After logging in, I also don’t have the ‘Logged in as’ titlebar above my avatar just like on this website.

    I’ve posted more than 3 threads about this on WP forum and Buddypress….no responses so far, so please, if anyone can help me on this….

    @bizkit1981

    Member

    Hi,

    Thanks very much for this code – works perfectly on my site. I want to add one thing to it…

    When a user is logged in, it still has the “Username/Password” fields in the admin bar and I want to replace these with a message that says something like “Hello (Username), click HERE to sign out” with the click-able link obviously signing them out.

    Also, how do you put a “Sign Up” button up there with it, again to show only when user is logged out?

    Thanks.

    @cpkid2

    Participant

    Is there anyway to not have the form show up under `ul class=”main-nav”` ? It’s not reading as valid xhtml and also I think this is the reason the fields don’t show up in IE7.

    @cpkid2

    Participant

    I figured out why this isn’t working in IE7. For some reason, IE 7 doesn’t add the closing /li tag to “li class=bp-login no-arrow” so the form gets lumped into that li.

    The problem is I have “bp-login no-arrow” hidden so everything in it including the form gets hidden as well. You can see exactly what I mean here: http://bit.ly/bVtufR

    Is there any way to fix this?

    -edit- I fixed this by adding li tags around the form.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Login moved from sidebar to admin bar’ is closed to new replies.
Skip to toolbar