Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Buddypress Group meta fields
  4. Plugin URI: http://MyWebsite.com
  5. Description: extra group meta fields for buddypress
  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. ?>
  23.  
  24. <?php $country_list = array( "country1_key" => "country1_value",
  25.  
  26. "country2_key" => "country2_value",
  27.  
  28. "country3_key" => "country3_value" );
  29.  
  30. ?>
  31.  
  32. <label for="country">country</label> <select id="country" value="<?php echo custom_field('country') ?>">
  33.  
  34. <?php
  35.  
  36. $setting = groups_get_groupmeta( $group_id, 'group_extension_country' );
  37.  
  38. foreach($country_list as $country_k => $country_v){
  39.  
  40. if($setting == $country_k)
  41.  
  42. $selected = 'selected="selected"';
  43.  
  44. else
  45.  
  46. $selected = "";
  47.  
  48. echo '<option value="'.$country_k.'" '.$selected.'>'.$country_v.'</option>';
  49.  
  50. }
  51.  
  52. ?>
  53.  
  54. </select>
  55. <label for="Website url">url</label>
  56. <input id="url" type="text" name="url" value="<?php echo custom_field('url'); ?>" />
  57.  
  58. <?php }
  59. // This saves the custom group meta – props to Boone for the function
  60. // Where $plain_fields = array.. you may add additional fields, eg
  61. // $plain_fields = array(
  62. // 'field-one',
  63. // 'field-two'
  64. // );
  65. function group_header_fields_save( $group_id ) {
  66. global $bp, $wpdb;
  67. $plain_fields = array(
  68. 'country','url'
  69. );
  70. foreach( $plain_fields as $field ) {
  71. $key = $field;
  72. if ( isset( $_POST[$key] ) ) {
  73. $value = $_POST[$key];
  74. groups_update_groupmeta( $group_id, $field, $value );
  75. }
  76. }
  77. }
  78. add_filter( 'groups_custom_group_fields_editable', 'group_header_fields_markup' );
  79. add_action( 'groups_group_details_edited', 'group_header_fields_save' );
  80. add_action( 'groups_created_group', 'group_header_fields_save' );
  81.  
  82. // Show the custom field in the group header
  83. function show_field_in_header( ) {
  84. echo "<p> Country:" . custom_field('country') . "</p>";
  85. echo "<p> Site URL:" . custom_field('url'). "</p>";
  86. }
  87. add_action('bp_group_header_meta' , 'show_field_in_header') ;
  88. }
  89. add_action( 'bp_include', 'bp_group_meta_init' );
  90. /* If you have code that does not need BuddyPress to run, then add it here. */
  91. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement