That’s the same as I am trying. My problem is that class_exists( 'BP_Group_Extension' ) returns false, which means that what I put in my if never get executed. But I’m happy to hear it’s working for you, what version of BP are you running? And are you running this in a plugin or in a theme?
Just to be sure, do you have ‘User Groups’ enabled here /wp-admin/admin.php?page=bp-components ?
What hook are you using to call your extension ?
This should work:
function jim_add_group_extension() {
if ( class_exists( 'BP_Group_Extension' ) ) {
...
}
}
add_action('bp_init', 'jim_add_group_extension');
I’m doing a call to bp_register_group_extension( 'EP_Group_Tasks' ); with a class I want to extend the BP_Group_Extensionclass. Full code of the file:
<?php
/**
* User: jimtrim
* Date: 11/11/14
* Time: 09:17
*/
if ( class_exists( 'BP_Group_Extension' ) ) {
class BP_Group_Tasks extends BP_Group_Extension{
/**
* Here you can see more customization of the config options
*/
function __construct() {
$args = array(
'slug' => 'tasks',
'name' => __('Tasks', 'revyweb'),
'nav_item_position' => 90,
'screens' => array(
'create' => array(
'name' => __('Create task', 'revyweb'),
'submit_text' => __('Save task', 'revyweb')
),
'edit' => array(
'name' => __('Edit task', 'revyweb'),
'submit_text' => __('Save task', 'revyweb')
),
'admin' => array(
'name' => __('Administer task', 'revyweb'),
'submit_text' => __('Save task', 'revyweb')
),
),
);
parent::init( $args );
}
function display() {
//get_template_part( 'buddypress/custom/view', 'tasks' );
$group_id = bp_get_group_id();
echo "GET READY FOR SOME TASKS";
}
public function settings_screen( $group_id = null ) {
//get_template_part( 'buddypress/custom/settings', 'tasks' );
$setting = groups_get_groupmeta( $group_id, 'task_name' );
?>
Save your task name here: <input type="text" name="task_name" value="<?php echo esc_attr( $setting ) ?>" />
<?php
}
function settings_screen_save( $group_id = NULL ) {
$setting = '';
if ( isset( $_POST['task_name'] ) ) {
$setting = $_POST['task_name'];
}
groups_update_groupmeta( $group_id, 'task_name', $setting );
}
}
bp_register_group_extension( 'EP_Group_Tasks' );
} else {
$msg = "Class BP_Group_Extension not found for Revyweb_Personal";
// trigger_error($msg, E_USER_NOTICE);
echo $msg;
}
Edit: yes, User Groups are enabled, and I can display user groups on the frontend, but I can’t add my own BP_Group_Extention
BP_Group_Extension will not be available until BP is fully loaded.
Did you try using the function wrapper I provided ?
I only get fatal error class declarations may not be nested. I that I may have this be a function living in the global scope, but thats extremly ugly OOP-wise.
Also: according to Group Extension API/ it should not be neccessary, as this method is to declare the class during plugin initiation.
I’ve tried with putting the function on the global scope, and yes, class_exists( 'BP_Group_Extension' ) now returns true, but there is no added menu item in the groups, and no slug called tasks
The latest BP and WP, and thanks to maintainers for updating codex. Pretty sweet.