Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: [Resolved] Group Extension API – Display() under Admin

@danbp

Participant

Hi @nickpeplow,

it’s not possible to add sub nav items with the group API and the only other possibility that eventually could work a day (but not tomorrow 😉 ) would be bp_core_new_subnav_item(), but it is a Todo, as stated in bp-groups-classes.php:3307

Here are 2 snippets (i tested them within bp-custom.php – BP 2.0.2 Twentythirteen)

This one let you add some content on the new screen.

function add_admin_tab_content() {
	echo 'Quis scelerisque lacinia tempus nullam felis';
	}
add_action( 'groups_custom_edit_steps', 'add_admin_tab_content' );

This one create a sub nav item when you’re on the group admin screen


function bpfr_add_page_to_group() {
	
	if ( class_exists( 'BP_Group_Extension' ) ) :
  
class My_Custom_Group_Extension extends BP_Group_Extension {
 
    function __construct() {
        $args = array(  
			'slug' => 'houba-houba',
			'parent_slug' => 'admin', // URL slug of the parent nav item
            'nav_item_position' => 100,
            'screens' => array(
                'edit' => array(
                    'name' => 'Houba Houba', // the tab name                 
                ),
                'create' => array(
                    'position' => 100,
                ),
            ),
        );
        parent::init( $args );
    }
 

     function settings_screen( $group_id ) {
		// don't remove this function
           }  
} // end of class

		bp_register_group_extension( 'My_Custom_Group_Extension' );
 
	endif;
}
add_filter('bp_groups_default_extension', 'bpfr_add_page_to_group' );

Once installed you will see that the “save change” button is still there. This button is contextual and cannot be removed, as it is used elsewhere. So you make it diseapear with the appropriate CSS with display:none!important; on the div with the ID of your/each group save button.

If you want to display that only for one group, you add a condition to bp_register_group_extension like this

} // end class
////////////////////////////////////////////////////////////
/* display content only in one group (ex. group_ID is 14) */
////////////////////////////////////////////////////////////
     
    // check for a group ID
        if( bp_has_groups() ) {
            // Grab current group ID
            bp_the_group();
            $group_id = bp_get_group_ID();
        }
     
    //////////////////////////////////////////
    /* apply our changes only to this group */
    //////////////////////////////////////////
     
        // conditionnal action
        if ( $group_id == 14 ) {   
            bp_register_group_extension( 'My_Custom_Group_Extension' );          
        } 

Voilà ! May this help.

More BP tips and tricks on my blog. (FR, sometimes EN – but php is always in english)

Skip to toolbar