Advertisement
Guest User

Untitled

a guest
Jul 18th, 2012
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Favorite Color
  4. Plugin URI: http://MyWebsite.com
  5. Description: Let Groups Pick their favorite Color
  6. Version: 1.0
  7. Requires at least: 3.3
  8. Tested up to: 3.3.1
  9. License: GPL3
  10. Author: Your Name
  11. Author URI: http://YourCoolWebsite.com
  12. */
  13. function bp_group_meta_init() {
  14. function custom_field($meta_key='') {
  15. //get current group id and load meta_key value if passed. If not pass it blank
  16. return groups_get_groupmeta( bp_get_group_id(), $meta_key) ;
  17. }
  18. //code if using seperate files require( dirname( __FILE__ ) . '/buddypress-group-meta.php' );
  19. // This function is our custom field's form that is called in create a group and when editing group details
  20. function group_header_fields_markup() {
  21. global $bp, $wpdb;?>
  22. <label for="favorite-color">My Favorite Color</label>
  23. <input id="favorite-color" type="text" name="favorite-color" value="<?php echo custom_field('favorite-color'); ?>" />
  24. <br>
  25. <label for="favorite-color2">My Favorite Color 2</label>
  26. <input id="favorite-color2" type="text" name="favorite-color2" value="<?php echo custom_field('favorite-color2'); ?>" />
  27. <br>
  28. <label for="favorite-color3">My Favorite Color 3</label>
  29. <input id="favorite-color3" type="text" name="favorite-color3" value="<?php echo custom_field('favorite-color2'); ?>" />
  30. <br>
  31. <?php }
  32. // This saves the custom group meta – props to Boone for the function
  33. // Where $plain_fields = array.. you may add additional fields, eg
  34. // $plain_fields = array(
  35. // 'field-one',
  36. // 'field-two'
  37. // );
  38. function group_header_fields_save( $group_id ) {
  39. global $bp, $wpdb;
  40. $plain_fields = array(
  41. 'favorite-color',
  42. 'favorite-color2',
  43. 'favorite-color3'
  44. );
  45. foreach( $plain_fields as $field ) {
  46. $key = $field;
  47. if ( isset( $_POST[$key] ) ) {
  48. $value = $_POST[$key];
  49. groups_update_groupmeta( $group_id, $field, $value );
  50. }
  51. }
  52. }
  53. add_filter( 'groups_custom_group_fields_editable', 'group_header_fields_markup' );
  54. add_action( 'groups_group_details_edited', 'group_header_fields_save' );
  55. add_action( 'groups_created_group', 'group_header_fields_save' );
  56.  
  57. // Show the custom field in the group header
  58. function show_field_in_header( ) {
  59. echo "<p> My favorite color is:" . custom_field('favorite-color') . "</p>";
  60. }
  61. add_action('bp_group_header_meta' , 'show_field_in_header') ;
  62. }
  63. add_action( 'bp_include', 'bp_group_meta_init' );
  64. /* If you have code that does not need BuddyPress to run, then add it here. */
  65. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement