Skip to:
Content
Pages
Categories
Search
Top
Bottom
Codex HomeBuddyPress Plugin Development → Admin UI for Groups

Admin UI for Groups

In BuddyPress 1.7, the Groups Component comes with a great Admin UI that allows Community Administrator to easily manage the created groups (members, settings…) directly from the WordPress backend.

edit group admin screen

Edit Group Admin Screen

As plugin authors, I think we should enjoy this new area and let the Community Administrator manage the settings of the group extension we might use in our custom component. To do so, I think the best way is to enrich the class we use to extend the BP Group Extension API.

Let’s consider this class as our plugin’s group component, just to refresh our memory about the BP Group Extension API  class and its functions:

class Bp_Plugin_Group extends BP_Group_Extension {
	function __construct() {}
	function create_screen() {}
	function create_screen_save() {}
	function edit_screen() {}
	function edit_screen_save() {}
	function admin_screen() {}
	function admin_screen_save() {}
	function display() {}
	function widget_display() {}
	function enable_nav_item() {}
}
bp_register_group_extension( 'Bp_Plugin_Group' );

Adding a meta box for our component in the “Edit Group” Admin screen.

When creating your component utilizing the BP Group Extension API you can include the functions below to add a meta box to the Group Admin Page. You can create anything from displaying group content or allowing an admin to update the group meta. The  admin_screen_save() function has an example of getting form parameters out of the $_POST global and saving it into the group meta.

        function admin_screen( $group_id ) {
            ?>

            <p>The HTML for my admin panel.</p>

            <?php
        }

        function admin_screen_save( $group_id ) {
            // Grab your data out of the $_POST global and save as necessary

$bp_plugin_status = !empty( $_POST['_bp_plugin_status'] ) ? $_POST['_bp_plugin_status'] : false ;

		/* If the checkbox is checked we have a value and we save it in a group meta,
		   else we simply delete the group meta ! */

		if( !empty( $bp_plugin_status ) )
			groups_update_groupmeta( $group_id, 'bp_plugin_status', $bp_plugin_status );

		else
			groups_delete_groupmeta( $group_id, 'bp_plugin_status' );

	}
 }

 function widget_display() { ?>
     <div class="info-group">
         <h4><?php echo esc_attr( $this->name ) ?></h4>
         <p>
         You could display a small snippet of information from your group extension          here. It will show on the group
         home screen.
         </p>
     </div>
 <?php
 }
}
Skip to toolbar