Last active
May 26, 2021 16:26
-
-
Save shanebp/c9cdde9443bdeab9b4ca to your computer and use it in GitHub Desktop.
example of using BP_Group_Extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* example of using BP_Group_Extension | |
* replace 'test' with something else - remember that it is case-sensitive | |
* checks for any selected Group Types in the 'Settings' step | |
*/ | |
function test_add_group_extension() { | |
if ( bp_is_active( 'groups' ) ) : | |
class Test_Group_Extension extends BP_Group_Extension { | |
function __construct() { | |
$args = array( | |
'slug' => 'group-test', | |
'name' => __( 'Test', 'buddypress' ), | |
'nav_item_position' => 200, | |
'show_tab' => 'anyone', | |
'screens' => array( | |
'edit' => array( | |
'name' => __( 'Test', 'buddypress' ), | |
), | |
'create' => array( 'position' => 10, ), | |
), | |
); | |
parent::init( $args ); | |
} | |
function display( $group_id = NULL ) { | |
$group_id = bp_get_group_id(); | |
$group_extension_test = groups_get_groupmeta( $group_id, 'group_extension_setting' ); | |
echo 'Test: ' . esc_attr( $group_extension_test ); | |
} | |
function settings_screen( $group_id = NULL ) { | |
$setting = groups_get_groupmeta( $group_id, 'group_extension_setting' ); | |
$group_types = bp_groups_get_group_type( $group_id, false ); | |
?> | |
<h4><?php _e( 'Test Settings', 'buddypress' ); ?></h4> | |
<?php | |
echo 'Group Types: ' . $group_types; | |
// will be an array if multiple groups were chosen in Settings step | |
// write code here to do something based on $group_types | |
// if you need details about each group type, get data as an object | |
if ( is_array( $group_types ) ) { | |
foreach ( $group_types as $group_type ) { | |
$group_object = bp_groups_get_group_type_object( $group_type ); | |
var_dump( $group_object ); | |
} | |
} elseif ( $group_types ) { | |
$group_object = bp_groups_get_group_type_object( $group_types ); | |
var_dump( $group_object ); | |
} | |
?> | |
<br> | |
<div class="checkbox"> | |
<input type="checkbox" name="group_extension_setting" id="group_extension_setting" value="1"<?php if ( $setting == '1' ) echo ' checked="checked"'; ?> /> | |
<?php _e( 'Allow group members to do something', 'buddypress' ); ?> | |
</div> | |
<br> | |
<hr /> | |
<?php | |
} | |
function settings_screen_save( $group_id = NULL ) { | |
$setting = isset( $_POST['group_extension_setting'] ) ? '1' : '0'; | |
groups_update_groupmeta( $group_id, 'group_extension_setting', $setting ); | |
} | |
} | |
bp_register_group_extension( 'Test_Group_Extension' ); | |
endif; | |
} | |
add_action('bp_init', 'test_add_group_extension'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment