/**
  * @ticket BP7110
  */
 public function test_top_level_link_should_point_to_displayed_user_for_loggedout_user()
 {
     $user = $this->factory->user->create();
     $this->set_current_user(0);
     $user_domain = bp_core_get_user_domain($user);
     $this->go_to($user_domain);
     $found = bp_get_nav_menu_items();
     // Find the Activity top-level item.
     $activity_item = null;
     foreach ($found as $f) {
         if ('activity' === $f->css_id) {
             $activity_item = $f;
             break;
         }
     }
     $this->assertSame(trailingslashit($user_domain) . 'activity/', $activity_item->link);
 }
 public function test_backcompat_remove_group_nav_items()
 {
     $g1 = $this->factory->group->create();
     // In group context
     $g_obj = groups_get_group($g1);
     $this->go_to(bp_get_group_permalink($g_obj));
     bp_core_new_subnav_item(array('name' => 'Clam', 'slug' => 'clam', 'parent_slug' => bp_get_current_group_slug(), 'parent_url' => bp_get_group_permalink($g_obj), 'screen_function' => 'clam_subnav'));
     bp_core_remove_subnav_item($g_obj->slug, 'clam');
     $nav = bp_get_nav_menu_items('groups');
     $found = false;
     foreach ($nav as $_nav) {
         if ('clam' === $_nav->css_id) {
             $found = true;
             break;
         }
     }
     $this->assertFalse($found);
 }
/**
 * Display a navigation menu.
 *
 * @since 1.7.0
 *
 * @param string|array $args {
 *     An array of optional arguments.
 *
 *     @type string $after           Text after the link text. Default: ''.
 *     @type string $before          Text before the link text. Default: ''.
 *     @type string $container       The name of the element to wrap the navigation
 *                                   with. 'div' or 'nav'. Default: 'div'.
 *     @type string $container_class The class that is applied to the container.
 *                                   Default: 'menu-bp-container'.
 *     @type string $container_id    The ID that is applied to the container.
 *                                   Default: ''.
 *     @type int    $depth           How many levels of the hierarchy are to be included.
 *                                   0 means all. Default: 0.
 *     @type bool   $echo            True to echo the menu, false to return it.
 *                                   Default: true.
 *     @type bool   $fallback_cb     If the menu doesn't exist, should a callback
 *                                   function be fired? Default: false (no fallback).
 *     @type string $items_wrap      How the list items should be wrapped. Should be
 *                                   in the form of a printf()-friendly string, using numbered
 *                                   placeholders. Default: '<ul id="%1$s" class="%2$s">%3$s</ul>'.
 *     @type string $link_after      Text after the link. Default: ''.
 *     @type string $link_before     Text before the link. Default: ''.
 *     @type string $menu_class      CSS class to use for the <ul> element which
 *                                   forms the menu. Default: 'menu'.
 *     @type string $menu_id         The ID that is applied to the <ul> element which
 *                                   forms the menu. Default: 'menu-bp', incremented.
 *     @type string $walker          Allows a custom walker class to be specified.
 *                                   Default: 'BP_Walker_Nav_Menu'.
 * }
 * @return string|null If $echo is false, returns a string containing the nav
 *                     menu markup.
 */
function bp_nav_menu($args = array())
{
    static $menu_id_slugs = array();
    $defaults = array('after' => '', 'before' => '', 'container' => 'div', 'container_class' => '', 'container_id' => '', 'depth' => 0, 'echo' => true, 'fallback_cb' => false, 'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>', 'link_after' => '', 'link_before' => '', 'menu_class' => 'menu', 'menu_id' => '', 'walker' => '');
    $args = wp_parse_args($args, $defaults);
    /**
     * Filters the parsed bp_nav_menu arguments.
     *
     * @since 1.7.0
     *
     * @param array $args Array of parsed arguments.
     */
    $args = apply_filters('bp_nav_menu_args', $args);
    $args = (object) $args;
    $items = $nav_menu = '';
    $show_container = false;
    // Create custom walker if one wasn't set.
    if (empty($args->walker)) {
        $args->walker = new BP_Walker_Nav_Menu();
    }
    // Sanitise values for class and ID.
    $args->container_class = sanitize_html_class($args->container_class);
    $args->container_id = sanitize_html_class($args->container_id);
    // Whether to wrap the ul, and what to wrap it with.
    if ($args->container) {
        /**
         * Filters the allowed tags for the wp_nav_menu_container.
         *
         * @since 1.7.0
         *
         * @param array $value Array of allowed tags. Default 'div' and 'nav'.
         */
        $allowed_tags = apply_filters('wp_nav_menu_container_allowedtags', array('div', 'nav'));
        if (in_array($args->container, $allowed_tags)) {
            $show_container = true;
            $class = $args->container_class ? ' class="' . esc_attr($args->container_class) . '"' : ' class="menu-bp-container"';
            $id = $args->container_id ? ' id="' . esc_attr($args->container_id) . '"' : '';
            $nav_menu .= '<' . $args->container . $id . $class . '>';
        }
    }
    /**
     * Filters the BuddyPress menu objects.
     *
     * @since 1.7.0
     *
     * @param array $value Array of nav menu objects.
     * @param array $args  Array of arguments for the menu.
     */
    $menu_items = apply_filters('bp_nav_menu_objects', bp_get_nav_menu_items(), $args);
    $items = walk_nav_menu_tree($menu_items, $args->depth, $args);
    unset($menu_items);
    // Set the ID that is applied to the ul element which forms the menu.
    if (!empty($args->menu_id)) {
        $wrap_id = $args->menu_id;
    } else {
        $wrap_id = 'menu-bp';
        // If a specific ID wasn't requested, and there are multiple menus on the same screen, make sure the autogenerated ID is unique.
        while (in_array($wrap_id, $menu_id_slugs)) {
            if (preg_match('#-(\\d+)$#', $wrap_id, $matches)) {
                $wrap_id = preg_replace('#-(\\d+)$#', '-' . ++$matches[1], $wrap_id);
            } else {
                $wrap_id = $wrap_id . '-1';
            }
        }
    }
    $menu_id_slugs[] = $wrap_id;
    /**
     * Filters the BuddyPress menu items.
     *
     * Allow plugins to hook into the menu to add their own <li>'s
     *
     * @since 1.7.0
     *
     * @param array $items Array of nav menu items.
     * @param array $args  Array of arguments for the menu.
     */
    $items = apply_filters('bp_nav_menu_items', $items, $args);
    // Build the output.
    $wrap_class = $args->menu_class ? $args->menu_class : '';
    $nav_menu .= sprintf($args->items_wrap, esc_attr($wrap_id), esc_attr($wrap_class), $items);
    unset($items);
    // If we've wrapped the ul, close it.
    if (!empty($show_container)) {
        $nav_menu .= '</' . $args->container . '>';
    }
    /**
     * Filters the final BuddyPress menu output.
     *
     * @since 1.7.0
     *
     * @param string $nav_menu Final nav menu output.
     * @param array  $args     Array of arguments for the menu.
     */
    $nav_menu = apply_filters('bp_nav_menu', $nav_menu, $args);
    if (!empty($args->echo)) {
        echo $nav_menu;
    } else {
        return $nav_menu;
    }
}
 /**
  * @group groups
  */
 public function test_bp_core_new_subnav_item_should_work_in_group_context()
 {
     $this->set_up_group();
     bp_core_new_subnav_item(array('name' => 'Foo Subnav', 'slug' => 'foo-subnav', 'parent_slug' => bp_get_current_group_slug(), 'parent_url' => bp_get_group_permalink(groups_get_current_group()), 'screen_function' => 'foo_subnav'));
     $bp = buddypress();
     // Touch bp_nav since we told PHPUnit it was expectedDeprecated.
     $f = $bp->bp_options_nav[bp_get_current_group_slug()];
     $nav = bp_get_nav_menu_items('groups');
     foreach ($nav as $_nav) {
         if ('foo-subnav' === $_nav->css_id) {
             $found = $_nav;
             break;
         }
     }
     $this->assertSame('Foo Subnav', $found->name);
 }