Created
April 13, 2015 13:16
-
-
Save imath/980751372693ee0b652d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Exit if accessed directly | |
defined( 'ABSPATH' ) || exit; | |
/** | |
* This will only get the displayed group's menu items | |
* 1/ if a group is displayed | |
* 2/ if the theme is containing the template 'buddypress/groups/single/home.php' | |
* 3/ if the theme's template replaced <ul><?php bp_get_options_nav();?></ul> by <?php bp_nav_menu();?> | |
*/ | |
function mat_single_group_nav_menu( $menus = array() ) { | |
// Simply return the menu if not viewing a single group. | |
if ( ! bp_is_group() ) { | |
return $menus; | |
} | |
// Get the current group | |
$current_group = groups_get_current_group(); | |
// Should never be the case... | |
if ( empty( $current_group->slug ) ) { | |
return array(); | |
} | |
// Init an empty single group menus | |
$single_group_menus = array(); | |
/** | |
* Loop through each menu items to check that | |
* the parent property is the current group's slug | |
* before adding the menu to the single group's ones | |
*/ | |
foreach ( $menus as $menu ) { | |
// Do not keep user's nav elements | |
if ( $current_group->slug !== $menu->parent ) { | |
continue; | |
} | |
// Add the single group menu item | |
$single_group_menus[] = $menu; | |
} | |
return $single_group_menus; | |
} | |
add_filter( 'bp_get_nav_menu_items', 'mat_single_group_nav_menu', 10, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment