Skip to:
Content
Pages
Categories
Search
Top
Bottom

Hiding buddybar add-on menus when users are not logged in

  • @jfcarter

    Participant

    I have used code snippets from this site to add menu items to the buddybar (using bpcustom.php). They look great, but are visible to everyone, like the Login and Signup menu items. Does anyone know how I can hide these add-on menus when users are not logged in? (like My Account, Blogs, Notifications, etc.)

    Many thanks.

Viewing 11 replies - 1 through 11 (of 11 total)
  • @johnjamesjacoby

    Keymaster

    You want to hide the entire BuddyBar when they’re not logged in, or only the items you’ve added in bp-custom.php?

    @jfcarter

    Participant

    @JJJ

    Just the custom items. I want the rest of the buddybar (Login, Signup, etc.) to be visible to non-logged in users.

    @jfcarter

    Participant

    Sorry for the bump, but can anyone answer this?

    @johnjamesjacoby

    Keymaster

    Use the normal WordPress function is_user_logged_in().

    @jfcarter

    Participant

    @JJJ

    Thanks; I am not sure how to use that function. Is there a site I can visit or another thread with the syntax and details?

    And it seems like I should add the function to my add-on menus. Is that correct?

    @johnjamesjacoby

    Keymaster

    I actually linked to the function reference in my post above yours. :)

    That function is a WordPress function to check and see if the user browsing the site is logged in or not. It will return true if yes, false if no.

    if (if_user_logged_in())) {
    [..your custom menu item code...]
    }

    @jfcarter

    Participant

    Oh! I didn’t know I could click on that.

    Thanks so much, JJJ.

    @johnjamesjacoby

    Keymaster

    You bet! I’m marking this resolved. If you need more help with this you can still reply, or change the ticker back to unresolved.

    @jfcarter

    Participant

    Okay, I read the codex on the function, but cannot seem to get the syntax right. This is the sample code from another buddypress thread:

    function my_help_link(){

    ?>

  • Help

    <ul class=”your-ul-list-css-classname”>

  • Help 1
  • <li class=”alt”>Help 2

  • Help 3
  • <li class=”alt”>Help 4

  • Help 5
  • <?php

    }

    add_action( ‘bp_adminbar_menus’, ‘my_help_link’, 14 );

    [Here with formatting: http://pastie.org/451047%5D

    I cannot figure out where to add the if (is_user_logged_in()) {} function.

@johnjamesjacoby

Keymaster

Try:

function my_help_link(){
if (is_user_logged_in()) {
?>
<li><a href="http://someplace.org">Help</a>
<ul class="your-ul-list-css-classname">
<li><a href="http://someplace.org">Help 1</a></li>
<li class="alt"><a href="http://someplace.org">Help 2</a></li>
<li><a href="http://someplace.org">Help 3</a></li>
<li class="alt"><a href="http://someplace.org">Help 4</a></li>
<li><a href="http://someplace.org">Help 5</a></li>
</ul>
</li>
<?php
}
}
add_action( 'bp_adminbar_menus', 'my_help_link', 14 );

@jfcarter

Participant

YESSSSS!!!!!

Thank you so much. It worked perfectly!

:)

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Hiding buddybar add-on menus when users are not logged in’ is closed to new replies.
Skip to toolbar