Showing or hiding buddypress icon menu based on login status

Hey. I’m creating a membership site. I love the way X-Theme integrates buddypress into that single icon dropdown. I am using a plugin called ‘Menu Item Visibility’ to handle some of the hidden menu’s for users and wondering, how can I show or hide the buddypress icon dropdown menu intrinsic to X based on a user’s login status?

Is there a way to key that into the menu item visibility through a hook or something similar? (This is because the menu item visibility plugin allows for conditional tags which can relate to specific memberships on my membership plugin).

I do realize that X theme only offers support with X, so I wanted to check the options. To see how a solution could be done within X as a conditional login, and then to see if it could be implemented with the plugin. Just checking in.

Thanks in advance

Hello Peter,

Thanks for updating in! What you have in mind can be done by overriding the built in function that displays the BuddyPress Menu group in the primary menu. The original code is:

//
// Outputs a navigation item with quick links to bbPress-specific components
// such as the forums, et cetera.
//

if ( ! function_exists( 'x_bbpress_navbar_menu' ) ) :
  function x_bbpress_navbar_menu( $items, $args ) {

    if ( X_BBPRESS_IS_ACTIVE && x_get_option( 'x_bbpress_header_menu_enable' ) == '1' && did_action( 'x_classic_headers' ) ) {

      $submenu_items  = '';
      $submenu_items .= '<li class="menu-item menu-item-bbpress-navigation"><a href="' . bbp_get_search_url() . '" class="cf"><i class="x-icon-search" data-x-icon-s="&#xf002;" aria-hidden="true"></i> <span>' . __( 'Forums Search', '__x__' ) . '</span></a></li>';

      if ( is_user_logged_in() ) {
        $submenu_items .= '<li class="menu-item menu-item-bbpress-navigation"><a href="' . bbp_get_favorites_permalink( get_current_user_id() ) . '" class="cf"><i class="x-icon-star" data-x-icon-s="&#xf005;" aria-hidden="true"></i> <span>' . __( 'Favorites', '__x__' ) . '</span></a></li>';
        $submenu_items .= '<li class="menu-item menu-item-bbpress-navigation"><a href="' . bbp_get_subscriptions_permalink( get_current_user_id() ) . '" class="cf"><i class="x-icon-bookmark" data-x-icon-s="&#xf02e;" aria-hidden="true"></i> <span>' . __( 'Subscriptions', '__x__' ) . '</span></a></li>';
      }

      if ( ! X_BUDDYPRESS_IS_ACTIVE || X_BUDDYPRESS_IS_ACTIVE && x_get_option( 'x_buddypress_header_menu_enable' ) == '' ) {
        if ( ! is_user_logged_in() ) {
          $submenu_items .= '<li class="menu-item menu-item-bbpress-navigation"><a href="' . wp_login_url() . '" class="cf"><i class="x-icon-sign-in" data-x-icon-s="&#xf2f6;" aria-hidden="true"></i> <span>' . __( 'Log in', '__x__' ) . '</span></a></li>';
        } else {
          $submenu_items .= '<li class="menu-item menu-item-bbpress-navigation"><a href="' . bbp_get_user_profile_url( get_current_user_id() ) . '" class="cf"><i class="x-icon-cog" data-x-icon-s="&#xf013;" aria-hidden="true"></i> <span>' . __( 'Profile', '__x__' ) . '</span></a></li>';
        }
      }

      if ( $args->theme_location == 'primary' ) {
        $items .= '<li class="menu-item current-menu-parent menu-item-has-children x-menu-item x-menu-item-bbpress">'
                  . '<a href="' . get_post_type_archive_link( bbp_get_forum_post_type() ) . '" class="x-btn-navbar-bbpress">'
                    . '<span><i class="x-icon-comment" data-x-icon-s="&#xf075;" aria-hidden="true"></i><span class="x-hidden-desktop"> ' . __( 'Forums', '__x__' ) . '</span></span>'
                  . '</a>'
                  . '<ul class="sub-menu">'
                    . $submenu_items
                  . '</ul>'
                . '</li>';
      }
    }

    return $items;

  }
  add_filter( 'wp_nav_menu_items', 'x_bbpress_navbar_menu', 9996, 2 );
endif;


// =============================================================================

You can override the code above or modify it by adding your conditions so that the menu will show or hide when the user is logged in or logged out.

Please note that custom coding is outside the scope of our support. Issues that might arise from the use of custom code and further enhancements should be directed to a third party developer.

Hope this helps.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.