<?php
class BuddyPress_Group_Fields extends BP_Group_Extension {
function buddypress_group_fields() {
//echo "HELLO PLUGIN INIT SCREEN!";
//print_r($this); //see what all you can change for the plugin
$this->name = 'Group Info';
$this->slug = 'info';
$this->enable_nav_item = true;
$this->create_step_position = 21;
$this->nav_item_position = 41;
}
function create_screen() {
if ( !bp_is_group_creation_step( $this->slug ) )
return false;
?>
<p>Please set your group field options below. Any group admin can also change these using the Admin tab.</p>
<p>Welcome Message:</p>
<p><textarea name="bpgf_welcome_text"><?php echo groups_get_groupmeta($bp->groups->current_group->id, 'bpgf_welcome_text'); ?></textarea></p>
<p>Location: <input type="text" name="bpgf_location" value="<?php echo groups_get_groupmeta($bp->groups->current_group-id, 'bpgf_location'); ?>" /></p>
<?php
wp_nonce_field( 'groups_create_save_' . $this->slug );
}
function create_screen_save() {
global $bp;
if ( !isset( $_POST['save'] ) ) return false; //did not come from save button
check_admin_referer( 'groups_create_save_' . $this->slug );
/* Save any details submitted here */
groups_update_groupmeta( $bp->groups->new_group_id, 'bpgf_welcome_text', $_POST['bpgf_welcome_text'] );
groups_update_groupmeta( $bp->groups->new_group_id, 'bpgf_location', $_POST['bpgf_location'] );
}
function edit_screen() {
global $bp;
if ( !bp_is_group_admin_screen( $this->slug ) )
return false; ?>
<h2><?php echo attribute_escape( $this->name ) ?></h2>
<p>Please use this to update your group welcome message and location:</p>
<p>Message:</p>
<p><textarea name="bpgf_welcome_text"><?php echo groups_get_groupmeta($bp->groups->current_group->id, 'bpgf_welcome_text'); ?></textarea></p>
<p>Location: <input type="text" name="bpgf_location" value="<?php echo groups_get_groupmeta($bp->groups->current_group-id, 'bpgf_location'); ?>" /></p>
<input type="submit" name="save" value="Save" />
<?php
wp_nonce_field( 'groups_edit_save_' . $this->slug );
}
function edit_screen_save() {
global $bp;
if ( !isset( $_POST['save'] ) ) return false; //did not come from save button
check_admin_referer( 'groups_edit_save_' . $this->slug );
/* Insert your edit screen save code here */
$success = true; //assume BuddyPress can do it
if (!groups_update_groupmeta($bp->groups->current_group->id, 'bpgf_welcome_text', $_POST['bpgf_welcome_text'])) $success = false;
if (!groups_update_groupmeta($bp->groups->current_group->id, 'bpgf_location', $_POST['bpgf_location'])) $success = false;
/* 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 */
global $bp;
?>
<strong>Thanks for visiting <?=$bp->groups->current_group->name?></strong><br />
<p><?php echo groups_get_groupmeta($bp->groups->current_group->id, 'bpgf_welcome_text'); ?></p>
<p>Location: <?php echo groups_get_groupmeta($bp->groups->current_group->id, 'bpgf_location'); ?></p>
<?php
}
function widget_display() { ?>
<div class="info-group">
<h4><?php echo attribute_escape( $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
}
}
bp_register_group_extension( 'BuddyPress_Group_Fields' );
?>