Advertisement
Guest User

Untitled

a guest
Oct 20th, 2011
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.28 KB | None | 0 0
  1. <?php
  2. class My_Group_Extension extends BP_Group_Extension {
  3.  
  4. function my_group_extension() {
  5. $this->name = get_option('group_plus_tab_name');
  6. $this->slug = get_option('group_plus_tab_slug');
  7.  
  8. $this->create_step_position = 21;
  9. $this->nav_item_position = 31;
  10. }
  11.  
  12. function create_screen() {
  13. if ( !bp_is_group_creation_step( $this->slug ) )
  14. return false;
  15. ?>
  16.  
  17. <?php if (function_exists('bpgp_group_textfield_field') && get_option('group_plus_textfield') == '1') bpgp_group_textfield_field(); ?>
  18. <?php if (function_exists('bpgp_group_textfield_field2') && get_option('group_plus_textfield2') == '1') bpgp_group_textfield_field2(); ?>
  19. <?php if (function_exists('bpgp_group_textarea_field') && get_option('group_plus_textarea') == '1') bpgp_group_textarea_field(); ?>
  20. <?php if (function_exists('bpgp_group_textarea_field2') && get_option('group_plus_textarea2') == '1') bpgp_group_textarea_field2(); ?>
  21. <?php if (function_exists('bpgp_group_maps_field') && get_option('group_plus_map') == '1') bpgp_group_maps_field(); ?>
  22.  
  23. <?php
  24. wp_nonce_field( 'groups_create_save_' . $this->slug );
  25. }
  26.  
  27. function create_screen_save() {
  28. global $bp;
  29.  
  30. check_admin_referer( 'groups_create_save_' . $this->slug );
  31.  
  32. /* Save any details submitted here */
  33. $this->settings_save( $bp->groups->new_group_id );
  34. }
  35.  
  36. function edit_screen() {
  37. if ( !bp_is_group_admin_screen( $this->slug ) )
  38. return false; ?>
  39.  
  40. <h2><?php echo esc_attr( $this->name ) ?></h2>
  41.  
  42. <?php if (function_exists('bpgp_group_textfield_field') && get_option('group_plus_textfield') == '1') bpgp_group_textfield_field(); ?>
  43. <?php if (function_exists('bpgp_group_textfield_field2') && get_option('group_plus_textfield2') == '1') bpgp_group_textfield_field2(); ?>
  44. <?php if (function_exists('bpgp_group_textarea_field') && get_option('group_plus_textarea') == '1') bpgp_group_textarea_field(); ?>
  45. <?php if (function_exists('bpgp_group_textarea_field2') && get_option('group_plus_textarea2') == '1') bpgp_group_textarea_field2(); ?>
  46. <?php if (function_exists('bpgp_group_maps_field') && get_option('group_plus_map') == '1') bpgp_group_maps_field(); ?>
  47.  
  48.  
  49. <p class="submit">
  50. <p><input type="submit" value="<?php _e( 'Save Changes' ) ?>" id="save" name="save" /></p>
  51. </p>
  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'] ) )
  61. return false;
  62.  
  63. check_admin_referer( 'groups_edit_save_' . $this->slug );
  64.  
  65. /* Insert your edit screen save code here */
  66. $this->settings_save( $bp->groups->current_group->id );
  67. /* Need to work this */
  68. $success = true;
  69.  
  70. /* To post an error/success message to the screen, use the following */
  71. if ( !$success )
  72. bp_core_add_message( __( 'There was an error saving, please try again', 'buddypress' ), 'error' );
  73. else
  74. bp_core_add_message( __( 'Settings saved successfully', 'buddypress' ) );
  75.  
  76. bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . 'admin/' . $this->slug );
  77. }
  78.  
  79. function display() {
  80.  
  81. /* Use this function to display the actual content of your group extension when the nav item is selected */
  82.  
  83. echo '<div id="plus-tab-holder" style="overflow:hidden">';
  84.  
  85. if (function_exists('bpgp_show_group_maps') && get_option('group_plus_map') == '1') {
  86. echo '<div id="plus-info-holder" style="float: left;width: 70%;">';
  87. } else {
  88. echo '<div id="plus-info-holder" style="float: left;width: 100%;">';
  89. }
  90.  
  91.  
  92. if (function_exists('bpgp_group_textfield_field') && get_option('group_plus_textfield') == '1') bpgp_show_group_textfield();
  93. if (function_exists('bpgp_group_textfield_field2') && get_option('group_plus_textfield2') == '1') bpgp_show_group_textfield2();
  94. if (function_exists('bpgp_group_textarea_field') && get_option('group_plus_textarea') == '1') bpgp_show_group_textarea();
  95. if (function_exists('bpgp_group_textarea_field2') && get_option('group_plus_textarea2') == '1') bpgp_show_group_textarea2();
  96. echo '</div>';
  97.  
  98. if (function_exists('bpgp_show_group_maps') && get_option('group_plus_map') == '1') bpgp_show_group_maps();
  99.  
  100. echo '</div>';
  101. }
  102.  
  103. function widget_display() { ?>
  104. <div class=&quot;info-group&quot;>
  105. <h4><?php echo esc_attr( $this->name ) ?></h4>
  106. <p>
  107. You could display a small snippet of information from your group extension here. It will show on the group
  108. home screen.
  109. </p>
  110. </div>
  111. <?php
  112. }
  113.  
  114. function settings_save( $group_id ) {
  115. global $bp, $wpdb;
  116.  
  117. $plain_fields = array(
  118. 'map_field',
  119. 'textfield_field',
  120. 'textfield_field2',
  121. 'textarea_field',
  122. 'textarea_field2'
  123. );
  124. foreach( $plain_fields as $field ) {
  125. $key = 'group_plus_' . $field;
  126. if ( isset( $_POST[$key] ) ) {
  127. $value = $_POST[$key];
  128. groups_update_groupmeta( $group_id, 'group_plus_' . $field, $value );
  129. }
  130. }
  131.  
  132. }
  133. }
  134. bp_register_group_extension( 'My_Group_Extension' );
  135. ?>
  136.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement