So.. you need to add a tab and associated page to the BuddyPress Group single post page. I recently needed to do this for a pedometer plugin I’m working on as part of the iStep project I’m working on for the EU funded Innovage project. I created a new file in my plugin. Lets call the file ‘sins_plugin_bp_group.php’. I then added the following code to it:
function my_new_groups_individual_steps_page() {
global $bp;
if (isset($bp->groups->current_group->slug)) {
bp_core_new_subnav_item(array(
'name' => 'Steps',
'slug' => 'steps',
'parent_slug' => $bp->groups->current_group->slug,
'parent_url' => bp_get_group_permalink($bp->groups->current_group),
'screen_function' => 'my_new_group_show_screen',
'position' => 40));
}
}
add_action('wp', 'my_new_groups_individual_steps_page');
function my_new_group_show_screen() {
add_action('bp_template_title', 'my_new_group_show_screen_title');
add_action('bp_template_content', 'my_new_group_show_screen_content');
$templates = array('groups/single/plugins.php', 'plugin-template.php');
if (strstr(locate_template($templates), 'groups/single/plugins.php')) {
bp_core_load_template(apply_filters('bp_core_template_plugin', 'groups/single/plugins'));
} else {
bp_core_load_template(apply_filters('bp_core_template_plugin', 'plugin-template'));
}
}
function my_new_group_show_screen_title() {
echo 'New Tab Title';
}
function my_new_group_show_screen_content() {
echo 'New tab page content';
}
Hay presto. That is how you Add a tab to a Group in Buddypress.
Working 😀
Great finally it’s working.