This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Buddypress Profile Fields for Groups

By: a guest on Nov 8th, 2010  |  syntax: PHP  |  size: 3.82 KB  |  views: 67  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3. class BuddyPress_Group_Fields extends BP_Group_Extension {     
  4.  
  5.         function buddypress_group_fields() {
  6.                 //echo "HELLO PLUGIN INIT SCREEN!";
  7.                 //print_r($this); //see what all you can change for the plugin
  8.                 $this->name = 'Group Info';
  9.                 $this->slug = 'info';
  10.                 $this->enable_nav_item = true;
  11.                 $this->create_step_position = 21;
  12.                 $this->nav_item_position = 41;
  13.         }
  14.  
  15.         function create_screen() {
  16.                 if ( !bp_is_group_creation_step( $this->slug ) )
  17.                         return false;
  18.                 ?>
  19.                
  20.                 <p>Please set your group field options below. Any group admin can also change these using the Admin tab.</p>
  21.                 <p>Welcome Message:</p>
  22.                 <p><textarea name="bpgf_welcome_text"><?php echo groups_get_groupmeta($bp->groups->current_group->id, 'bpgf_welcome_text'); ?></textarea></p>
  23.                 <p>Location: <input type="text" name="bpgf_location" value="<?php echo groups_get_groupmeta($bp->groups->current_group-id, 'bpgf_location'); ?>" /></p>
  24.  
  25.                 <?php
  26.                 wp_nonce_field( 'groups_create_save_' . $this->slug );
  27.         }
  28.  
  29.         function create_screen_save() {
  30.                 global $bp;
  31.  
  32.                 if ( !isset( $_POST['save'] ) ) return false; //did not come from save button
  33.  
  34.                 check_admin_referer( 'groups_create_save_' . $this->slug );
  35.  
  36.                 /* Save any details submitted here */
  37.                 groups_update_groupmeta( $bp->groups->new_group_id, 'bpgf_welcome_text', $_POST['bpgf_welcome_text'] );
  38.                 groups_update_groupmeta( $bp->groups->new_group_id, 'bpgf_location', $_POST['bpgf_location'] );
  39.         }
  40.  
  41.         function edit_screen() {
  42.                 global $bp;
  43.                 if ( !bp_is_group_admin_screen( $this->slug ) )
  44.                         return false; ?>
  45.  
  46.                 <h2><?php echo attribute_escape( $this->name ) ?></h2>
  47.                 <p>Please use this to update your group welcome message and location:</p>
  48.                 <p>Message:</p>
  49.                 <p><textarea name="bpgf_welcome_text"><?php echo groups_get_groupmeta($bp->groups->current_group->id, 'bpgf_welcome_text'); ?></textarea></p>
  50.                 <p>Location: <input type="text" name="bpgf_location" value="<?php echo groups_get_groupmeta($bp->groups->current_group-id, 'bpgf_location'); ?>" /></p>
  51.                 <input type="submit" name="save" value="Save" />
  52.  
  53.                 <?php
  54.                 wp_nonce_field( 'groups_edit_save_' . $this->slug );
  55.         }
  56.  
  57.         function edit_screen_save() {
  58.                 global $bp;
  59.  
  60.                 if ( !isset( $_POST['save'] ) ) return false; //did not come from save button
  61.  
  62.                 check_admin_referer( 'groups_edit_save_' . $this->slug );
  63.  
  64.                 /* Insert your edit screen save code here */
  65.                 $success = true; //assume BuddyPress can do it
  66.                 if (!groups_update_groupmeta($bp->groups->current_group->id, 'bpgf_welcome_text', $_POST['bpgf_welcome_text'])) $success = false;
  67.                 if (!groups_update_groupmeta($bp->groups->current_group->id, 'bpgf_location', $_POST['bpgf_location'])) $success = false;
  68.  
  69.                 /* To post an error/success message to the screen, use the following */
  70.                 if ( !$success )
  71.                         bp_core_add_message( __( 'There was an error saving, please try again', 'buddypress' ), 'error' );
  72.                 else
  73.                         bp_core_add_message( __( 'Settings saved successfully', 'buddypress' ) );
  74.  
  75.                 bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . '/admin/' . $this->slug );
  76.         }
  77.  
  78.         function display() {
  79.                 /* Use this function to display the actual content of your group extension when the nav item is selected */
  80.                 global $bp;
  81.                 ?>
  82.                 <strong>Thanks for visiting <?=$bp->groups->current_group->name?></strong><br />
  83.                 <p><?php echo groups_get_groupmeta($bp->groups->current_group->id, 'bpgf_welcome_text'); ?></p>
  84.                 <p>Location: <?php echo groups_get_groupmeta($bp->groups->current_group->id, 'bpgf_location'); ?></p>
  85.                 <?php
  86.         }
  87.  
  88.         function widget_display() { ?>
  89.                 <div class="info-group">
  90.                         <h4><?php echo attribute_escape( $this->name ) ?></h4>
  91.                         <p>
  92.                                 You could display a small snippet of information from your group extension here. It will show on the group
  93.                                 home screen.
  94.                         </p>
  95.                 </div>
  96.                 <?php
  97.         }
  98. }
  99. bp_register_group_extension( 'BuddyPress_Group_Fields' );
  100. ?>
clone this paste RAW Paste Data