Skip to:
Content
Pages
Categories
Search
Top
Bottom

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

  • Avatar of Jfcarter
    jfcarter
    Participant

    @jfcarter

    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)
  • Avatar of John James Jacoby
    John James Jacoby
    Keymaster

    @johnjamesjacoby

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

    Avatar of Jfcarter
    jfcarter
    Participant

    @jfcarter

    @JJJ

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

    Avatar of Jfcarter
    jfcarter
    Participant

    @jfcarter

    Sorry for the bump, but can anyone answer this?

    Avatar of John James Jacoby
    John James Jacoby
    Keymaster

    @johnjamesjacoby

    Use the normal WordPress function is_user_logged_in().

    Avatar of Jfcarter
    jfcarter
    Participant

    @jfcarter

    @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?

    Avatar of John James Jacoby
    John James Jacoby
    Keymaster

    @johnjamesjacoby

    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...]
    }

    Avatar of Jfcarter
    jfcarter
    Participant

    @jfcarter

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

    Thanks so much, JJJ.

    Avatar of John James Jacoby
    John James Jacoby
    Keymaster

    @johnjamesjacoby

    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.

    Avatar of Jfcarter
    jfcarter
    Participant

    @jfcarter

    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

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

Avatar of John James Jacoby
John James Jacoby
Keymaster

@johnjamesjacoby

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 );

Avatar of Jfcarter
jfcarter
Participant

@jfcarter

YESSSSS!!!!!

Thank you so much. It worked perfectly!

:)

Viewing 11 replies - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.