’BP_Group_Extension’ not found when using Group Extension API in bp-custom.php
-
I am trying to create custom tabs with their own content in different groups.
Looking around the forum it seems this can be done using the Group Extension API.
According to this thread it should be possible to do it by adding the API code (copied below) into bp-custom.php.
However when I do this I get the following error:
Fatal error: Class ‘BP_Group_Extension’ not found in (directory)bp-custom.php
This appears to be because it is loading after Buddypress. The codex supplies information on how to fix this for building a plugin but I’m not sure how to adapt this for my code in bp-custom.php.
Can anyone help me do this?
Here’s the code I’m using in bp-custom.php which is as found on the Group Extension API page:
class My_Group_Extension extends BP_Group_Extension { function my_group_extension() { $this->name = 'My Group Extension'; $this->slug = 'my-group-extension'; $this->create_step_position = 21; $this->nav_item_position = 31; } function create_screen() { if ( !bp_is_group_creation_step( $this->slug ) ) return false; ?> The HTML for my creation step goes here. <?php wp_nonce_field( 'groups_create_save_' . $this->slug ); } 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' ); } function edit_screen() { if ( !bp_is_group_admin_screen( $this->slug ) ) return false; ?> <h2>name ) ?></h2> Edit steps here <?php wp_nonce_field( 'groups_edit_save_' . $this->slug ); } function edit_screen_save() { global $bp; if ( !isset( $_POST ) ) 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 ); } function display() { /* Use this function to display the actual content of your group extension when the nav item is selected */ } function widget_display() { ?> <div class="info-group"> <h4>name ) ?></h4> You could display a small snippet of information from your group extension here. It will show on the group home screen. </div> <?php } } bp_register_group_extension( 'My_Group_Extension' );
Incidentally, I note there is a plugin designed to achieve what I’m trying to do but as it’s only in beta I can’t use it on a live site yet.
- The topic ‘’BP_Group_Extension’ not found when using Group Extension API in bp-custom.php’ is closed to new replies.