Guest User

Buddypress group tab

a guest
May 16th, 2013
431
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.16 KB | None | 0 0
  1. <?php
  2.  
  3. if ( class_exists( 'BP_Group_Extension' ) ) : // Recommended, to prevent problems during upgrade or when Groups are disabled
  4.  
  5.     class Group_tab1 extends BP_Group_Extension {
  6.  
  7.         function __construct() {
  8.             $this->name = 'Group tab1';
  9.             $this->slug = 'group-tab1';
  10.  
  11.             $this->create_step_position = 21;
  12.             $this->nav_item_position = 31;
  13.            
  14.             $this->enable_create_step = false;
  15.         }
  16.  
  17.         function settings_save( $group_id ) {
  18.             global $bp, $wpdb;
  19.  
  20.             $plain_fields = array(
  21.                 'field-1'
  22.         //      'field-2',    
  23.         //      'field-3'    
  24.             );
  25.    
  26.             foreach( $plain_fields as $field ) {
  27.                 $key = 'group-tab1-' . $field;
  28.                 if ( isset( $_POST[$key] ) ) {
  29.                     $value = $_POST[$key];
  30.                     groups_update_groupmeta( $group_id, 'group-tab1-' . $field, $value );
  31.                 }
  32.             }
  33.    
  34.         }
  35.  
  36.         /**
  37.          * The content of the My Group Extension tab of the group admin
  38.          */
  39.         function edit_screen() {
  40.             if ( !bp_is_group_admin_screen( $this->slug ) )
  41.                 return false; ?>
  42.  
  43.             <h2><?php echo esc_attr( $this->name ) ?></h2>
  44.  
  45.             <p>Edit steps here</p>
  46.            
  47.             <label for="group-tab1-field-1">Field Title* <i>editable</i></label>
  48.             <input type="text" name="group-tab1-field-1" id="group-tab1-field-1" value="<?php echo get_group_tab1_field_1(); ?>" />
  49.        
  50.             <input type="submit" name="save" value="Save" />
  51.  
  52.             <?php
  53.             wp_nonce_field( 'groups_edit_save_' . $this->slug );
  54.         }
  55.  
  56.         /**
  57.          * The routine run after the user clicks Save from your admin tab
  58.          *
  59.          * You'll be pulling your data out of the $_POST global. Be sure to
  60.          * sanitize as necessary.
  61.          */
  62.         function edit_screen_save() {
  63.             global $bp;
  64.  
  65.             if ( !isset( $_POST['save'] ) )
  66.                 return false;
  67.  
  68.             check_admin_referer( 'groups_edit_save_' . $this->slug );
  69.  
  70.             /* Insert your edit screen save code here */
  71.             $this->settings_save( $bp->groups->current_group->id );
  72.             /* Need to work this */
  73.             $success = true;
  74.  
  75.             /* To post an error/success message to the screen, use the following */
  76.             if ( !$success )
  77.                 bp_core_add_message( __( 'There was an error saving, please try again', 'buddypress' ), 'error' );
  78.             else
  79.                 bp_core_add_message( __( 'Settings saved successfully', 'buddypress' ) );
  80.  
  81.             bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . 'admin/' . $this->slug );
  82.         }
  83.  
  84.         /**
  85.          * Use this function to display the actual content of your group extension when the nav item is selected
  86.          */
  87.         function display() {
  88.             ?>
  89.  
  90.             <p>Welcome to my cool group-tab1 extension!</p>
  91.  
  92.             <?php
  93.         }
  94.     }
  95.    
  96.         function get_group_tab1_field_1() {
  97.             global $bp, $wpdb;
  98.             $field_1_meta = groups_get_groupmeta( $bp->groups->current_group->id, 'group-tab1-field-1' );
  99.             return $field_1_meta;
  100.         }
  101.  
  102.     bp_register_group_extension( 'Group_Tab1' );
  103.  
  104. endif; // class_exists( 'BP_Group_Extension' )
Advertisement
Add Comment
Please, Sign In to add comment