Codex Home → Legacy Docs → Archived Section: Developer Resources → Group Extension API (legacy)
Group Extension API (legacy)
Archived file. Good only up to BP 1.7 version
Note: This guide is for use with versions of BuddyPress older than 1.8. In BP 1.8, the group extension API was rewritten. Plugins written as described below should continue to work, but for new projects you are highly encouraged to use the 1.8+ methods described on the main Group Extension API Codex page.
The group extension API (1.1+) makes it very easy to add custom creation steps, edit screens, navigation items and pages to a group. It essentially allows you to create fully functional extensions to BuddyPress created groups.
Note: If you are building a BuddyPress plugin, please make sure you have read how to check if BuddyPress is active. This is very important.
Note: The admin_screen() and admin_screen_save() methods are new in BuddyPress 1.7. On earlier versions of BP, they won』t do anything.
The API Syntax
A group extension could be created as a standalone plugin file, or included as code within a plugin that performs other tasks. The core API code is as follows:
if ( bp_is_active( 'groups' ) ) : // Recommended, to prevent problems during upgrade or when Groups are disabled
class My_Group_Extension extends BP_Group_Extension {
function __construct() {
$this->name = 'My Group Extension';
$this->slug = 'my-group-extension';
$this->create_step_position = 21;
$this->nav_item_position = 31;
}
/**
* The content of the My Group Extension tab of the group creation process
*
* Don't need a group creation step? In the __construct() method:
*
* $this->enable_create_step = false;
*/
function create_screen() {
if ( !bp_is_group_creation_step( $this->slug ) )
return false;
/**
* If your extension's Create step shares much of its code with
* its Edit step, you might consider putting shared markup into
* a separate method (such as edit_create_markup()), and then
* call the method here:
*
* $this->edit_create_markup();
*/
?>
The HTML for my creation step goes here.
slug );
}
/**
* The routine run after the user clicks Continue from your creation step
*
* You'll be pulling your data out of the $_POST global. Be sure to
* sanitize as necessary.
*/
function create_screen_save() {
global $bp;
check_admin_referer( 'groups_create_save_' . $this->slug );
/* Save any details submitted here */
groups_update_groupmeta( $bp->groups->new_group_id, 'my_meta_name', 'value' );
}
/**
* The content of the My Group Extension tab of the group admin
*/
function edit_screen() {
if ( !bp_is_group_admin_screen( $this->slug ) )
return false; ?>
name ) ?>
Edit steps here
slug );
}
/**
* The routine run after the user clicks Save from your admin tab
*
* You'll be pulling your data out of the $_POST global. Be sure to
* sanitize as necessary.
*/
function edit_screen_save() {
global $bp;
if ( !isset( $_POST['save'] ) )
return false;
check_admin_referer( 'groups_edit_save_' . $this->slug );
/* Insert your edit screen save code here */
/* To post an error/success message to the screen, use the following */
if ( !$success )
bp_core_add_message( __( 'There was an error saving, please try again', 'buddypress' ), 'error' );
else
bp_core_add_message( __( 'Settings saved successfully', 'buddypress' ) );
bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/admin/' . $this->slug );
}
/**
* Use this function to display the actual content of your group extension when the nav item is selected
*/
function display() {
?>
Welcome to my cool group extension!
The HTML for my admin panel.
name ) ?>
You could display a small snippet of information from your group extension here. It will show on the group
home screen.
enable_nav_item = $this->enable_nav_item();
/* Add this method the end of your extension class */
function enable_nav_item() {
global $bp;
/* You might want to check some groupmeta for this group, before determining whether to enable the nav item */
if ( groups_get_groupmeta( $bp->groups->current_group->id, 'settings_complete' ) )
return true;
else
return false;
}