Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if ( class_exists( 'BP_Group_Extension' ) ) : // Recommended, to prevent problems during upgrade or when Groups are disabled
- class Group_tab1 extends BP_Group_Extension {
- function __construct() {
- $this->name = 'Group tab1';
- $this->slug = 'group-tab1';
- $this->create_step_position = 21;
- $this->nav_item_position = 31;
- $this->enable_create_step = false;
- }
- function settings_save( $group_id ) {
- global $bp, $wpdb;
- $plain_fields = array(
- 'field-1'
- // 'field-2',
- // 'field-3'
- );
- foreach( $plain_fields as $field ) {
- $key = 'group-tab1-' . $field;
- if ( isset( $_POST[$key] ) ) {
- $value = $_POST[$key];
- groups_update_groupmeta( $group_id, 'group-tab1-' . $field, $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; ?>
- <h2><?php echo esc_attr( $this->name ) ?></h2>
- <p>Edit steps here</p>
- <label for="group-tab1-field-1">Field Title* <i>editable</i></label>
- <input type="text" name="group-tab1-field-1" id="group-tab1-field-1" value="<?php echo get_group_tab1_field_1(); ?>" />
- <input type="submit" name="save" value="Save" />
- <?php
- wp_nonce_field( 'groups_edit_save_' . $this->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 */
- $this->settings_save( $bp->groups->current_group->id );
- /* Need to work this */
- $success = true;
- /* 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() {
- ?>
- <p>Welcome to my cool group-tab1 extension!</p>
- <?php
- }
- }
- function get_group_tab1_field_1() {
- global $bp, $wpdb;
- $field_1_meta = groups_get_groupmeta( $bp->groups->current_group->id, 'group-tab1-field-1' );
- return $field_1_meta;
- }
- bp_register_group_extension( 'Group_Tab1' );
- endif; // class_exists( 'BP_Group_Extension' )
Advertisement
Add Comment
Please, Sign In to add comment