Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Buddypress Group meta fields
- Plugin URI: http://MyWebsite.com
- Description: extra group meta fields for buddypress
- Version: 1.0
- Requires at least: 3.3
- Tested up to: 3.3.1
- License: GPL3
- Author: Your Name
- Author URI: http://YourCoolWebsite.com
- */
- function bp_group_meta_init() {
- function custom_field($meta_key='') {
- //get current group id and load meta_key value if passed. If not pass it blank
- return groups_get_groupmeta( bp_get_group_id(), $meta_key) ;
- }
- //code if using seperate files require( dirname( __FILE__ ) . '/buddypress-group-meta.php' );
- // This function is our custom field's form that is called in create a group and when editing group details
- function group_header_fields_markup() {
- global $bp, $wpdb;
- ?>
- <?php $country_list =
- array(
- 'AF' => 'Afghanistan',
- 'AL' => 'Albanië',
- 'DZ' => 'Algerije',
- 'AS' => 'Amerikaans-Samoa',
- 'VI' => 'Amerikaanse Maagdeneilanden',
- 'AD' => 'Andorra',
- 'AO' => 'Angola',
- 'AI' => 'Anguilla',
- 'AQ' => 'Antarctica',
- 'AG' => 'Antigua en Barbuda',
- 'AR' => 'Argentinië',
- 'AM' => 'Armenië',
- 'AW' => 'Aruba',
- 'AU' => 'Australië',
- 'AZ' => 'Azerbeidzjan',
- 'BS' => 'Bahama\'s',
- 'BH' => 'Bahrein',
- 'BD' => 'Bangladesh',
- 'BB' => 'Barbados',
- 'BE' => 'België',
- 'BZ' => 'Belize',
- 'BJ' => 'Benin',
- 'BM' => 'Bermuda',
- 'BT' => 'Bhutan',
- 'BO' => 'Bolivia',
- 'BA' => 'Bosnië en Herzegovina',
- 'BW' => 'Botswana',
- 'BV' => 'Bouvet',
- 'BR' => 'Brazilië',
- 'IO' => 'Brits Territorium in de Indische Oceaan',
- 'VG' => 'Britse Maagdeneilanden',
- 'BN' => 'Brunei',
- 'BG' => 'Bulgarije',
- 'BF' => 'Burkina Faso',
- 'BI' => 'Burundi',
- 'KH' => 'Cambodja',
- 'CA' => 'Canada',
- 'CF' => 'Centraal-Afrikaanse Republiek',
- 'CL' => 'Chili',
- 'CN' => 'China',
- 'CX' => 'Christmaseiland',
- 'CC' => 'Cocoseilanden',
- 'CO' => 'Colombia',
- 'KM' => 'Comoren',
- 'CG' => 'Congo-Brazzaville',
- 'CD' => 'Congo-Kinshasa',
- 'CK' => 'Cookeilanden',
- 'CR' => 'Costa Rica',
- 'CU' => 'Cuba',
- 'CY' => 'Cyprus',
- 'DK' => 'Denemarken',
- 'DJ' => 'Djibouti',
- 'DM' => 'Dominica',
- 'DO' => 'Dominicaanse Republiek',
- 'DE' => 'Duitsland',
- 'EC' => 'Ecuador',
- 'EG' => 'Egypte',
- 'SV' => 'El Salvador',
- 'GQ' => 'Equatoriaal-Guinea',
- 'ER' => 'Eritrea',
- 'EE' => 'Estland',
- 'ET' => 'Ethiopië',
- 'FO' => 'Faeröer',
- 'FK' => 'Falklandeilanden',
- 'FJ' => 'Fiji',
- 'PH' => 'Filipijnen',
- 'FI' => 'Finland',
- 'FR' => 'Frankrijk',
- 'GF' => 'Frans-Guyana',
- 'PF' => 'Frans-Polynesië',
- 'TF' => 'Franse Zuidelijke en Antarctische Gebieden',
- 'GA' => 'Gabon',
- 'GM' => 'Gambia',
- 'GE' => 'Georgië',
- 'GH' => 'Ghana',
- 'GI' => 'Gibraltar',
- 'GD' => 'Grenada',
- 'GR' => 'Griekenland',
- 'GL' => 'Groenland',
- 'GP' => 'Guadeloupe',
- 'GU' => 'Guam',
- 'GT' => 'Guatemala',
- 'GG' => 'Guernsey',
- 'GN' => 'Guinee',
- 'GW' => 'Guinee-Bissau',
- 'GY' => 'Guyana',
- 'HT' => 'Haïti',
- 'HM' => 'Heard en McDonaldeilanden',
- 'HN' => 'Honduras',
- 'HU' => 'Hongarije',
- 'HK' => 'Hongkong',
- 'IE' => 'Ierland',
- 'IS' => 'IJsland',
- 'IN' => 'India',
- 'ID' => 'Indonesië',
- 'IQ' => 'Irak',
- 'IR' => 'Iran',
- 'IM' => 'Isle of Man',
- 'IL' => 'Israël',
- 'IT' => 'Italië',
- 'CI' => 'Ivoorkust',
- 'JM' => 'Jamaica',
- 'JP' => 'Japan',
- 'YE' => 'Jemen',
- 'JE' => 'Jersey',
- 'JO' => 'Jordanië',
- 'KY' => 'Kaaimaneilanden',
- 'CV' => 'Kaapverdië',
- 'CM' => 'Kameroen',
- 'KZ' => 'Kazachstan',
- 'KE' => 'Kenia',
- 'KG' => 'Kirgizië',
- 'KI' => 'Kiribati',
- 'UM' => 'Kleine Pacifische eilanden van de Verenigde Staten',
- 'KW' => 'Koeweit',
- 'HR' => 'Kroatië',
- 'LA' => 'Laos',
- 'LS' => 'Lesotho',
- 'LV' => 'Letland',
- 'LB' => 'Libanon',
- 'LR' => 'Liberia',
- 'LY' => 'Libië',
- 'LI' => 'Liechtenstein',
- 'LT' => 'Litouwen',
- 'LU' => 'Luxemburg',
- 'MO' => 'Macau',
- 'MK' => 'Macedonië',
- 'MG' => 'Madagaskar',
- 'MW' => 'Malawi',
- 'MV' => 'Maldiven',
- 'MY' => 'Maleisië',
- 'ML' => 'Mali',
- 'MT' => 'Malta',
- 'MA' => 'Marokko',
- 'MH' => 'Marshalleilanden',
- 'MQ' => 'Martinique',
- 'MR' => 'Mauritanië',
- 'MU' => 'Mauritius',
- 'YT' => 'Mayotte',
- 'MX' => 'Mexico',
- 'FM' => 'Micronesia',
- 'MD' => 'Moldavië',
- 'MC' => 'Monaco',
- 'MN' => 'Mongolië',
- 'ME' => 'Montenegro',
- 'MS' => 'Montserrat',
- 'MZ' => 'Mozambique',
- 'MM' => 'Myanmar',
- 'NA' => 'Namibië',
- 'NR' => 'Nauru',
- 'NL' => 'Nederland',
- 'AN' => 'Nederlandse Antillen',
- 'NP' => 'Nepal',
- 'NI' => 'Nicaragua',
- 'NC' => 'Nieuw-Caledonië',
- 'NZ' => 'Nieuw-Zeeland',
- 'NE' => 'Niger',
- 'NG' => 'Nigeria',
- 'NU' => 'Niue',
- 'KP' => 'Noord-Korea',
- 'MP' => 'Noordelijke Marianen',
- 'NO' => 'Noorwegen',
- 'NF' => 'Norfolk',
- 'UG' => 'Oeganda',
- 'UA' => 'Oekraïne',
- 'UZ' => 'Oezbekistan',
- 'OM' => 'Oman',
- 'TL' => 'Oost-Timor',
- 'AT' => 'Oostenrijk',
- 'PK' => 'Pakistan',
- 'PW' => 'Palau',
- 'PS' => 'Palestijnse Autoriteit',
- 'PA' => 'Panama',
- 'PG' => 'Papoea-Nieuw-Guinea',
- 'PY' => 'Paraguay',
- 'PE' => 'Peru',
- 'PN' => 'Pitcairneilanden',
- 'PL' => 'Polen',
- 'PT' => 'Portugal',
- 'PR' => 'Puerto Rico',
- 'QA' => 'Qatar',
- 'RO' => 'Roemenië',
- 'RU' => 'Rusland',
- 'RW' => 'Rwanda',
- 'RE' => 'Réunion',
- 'KN' => 'Saint Kitts en Nevis',
- 'LC' => 'Saint Lucia',
- 'VC' => 'Saint Vincent en de Grenadines',
- 'BL' => 'Saint-Barthélemy',
- 'PM' => 'Saint-Pierre en Miquelon',
- 'SB' => 'Salomonseilanden',
- 'WS' => 'Samoa',
- 'SM' => 'San Marino',
- 'ST' => 'Sao Tomé en Principe',
- 'SA' => 'Saoedi-Arabië',
- 'SN' => 'Senegal',
- 'RS' => 'Servië',
- 'SC' => 'Seychellen',
- 'SL' => 'Sierra Leone',
- 'SG' => 'Singapore',
- 'SH' => 'Sint-Helena',
- 'MF' => 'Sint-Maarten',
- 'SI' => 'Slovenië',
- 'SK' => 'Slowakije',
- 'SD' => 'Soedan',
- 'SO' => 'Somalië',
- 'ES' => 'Spanje',
- 'SJ' => 'Spitsbergen en Jan Mayen',
- 'LK' => 'Sri Lanka',
- 'SR' => 'Suriname',
- 'SZ' => 'Swaziland',
- 'SY' => 'Syrië',
- 'TJ' => 'Tadzjikistan',
- 'TW' => 'Taiwan',
- 'TZ' => 'Tanzania',
- 'TH' => 'Thailand',
- 'TG' => 'Togo',
- 'TK' => 'Tokelau-eilanden',
- 'TO' => 'Tonga',
- 'TT' => 'Trinidad en Tobago',
- 'TD' => 'Tsjaad',
- 'CZ' => 'Tsjechië',
- 'TN' => 'Tunesië',
- 'TR' => 'Turkije',
- 'TM' => 'Turkmenistan',
- 'TC' => 'Turks- en Caicoseilanden',
- 'TV' => 'Tuvalu',
- 'UY' => 'Uruguay',
- 'VU' => 'Vanuatu',
- 'VA' => 'Vaticaanstad',
- 'VE' => 'Venezuela',
- 'GB' => 'Verenigd Koninkrijk',
- 'AE' => 'Verenigde Arabische Emiraten',
- 'US' => 'Verenigde Staten',
- 'VN' => 'Vietnam',
- 'WF' => 'Wallis en Futuna',
- 'EH' => 'Westelijke Sahara',
- 'BY' => 'Wit-Rusland',
- 'ZM' => 'Zambia',
- 'ZW' => 'Zimbabwe',
- 'ZA' => 'Zuid-Afrika',
- 'GS' => 'Zuid-Georgië en de Zuidelijke Sandwicheilanden',
- 'KR' => 'Zuid-Korea',
- 'SE' => 'Zweden',
- 'CH' => 'Zwitserland',
- 'AX' => 'Aland'
- );
- ?>
- <select name="country" id="country">
- <?php foreach ($country_list as $key => $value) { ?>
- <option value="<?php echo $value; ?>" <?php echo (custom_field('country') == $value)? 'selected="selected"' : '' ?>><?php echo $value; ?></option> <?php }; ?>
- </select>
- <label for="Website url">url</label>
- <input id="url" type="text" name="url" value="<?php echo custom_field('url'); ?>" />
- <?php }
- // This saves the custom group meta – props to Boone for the function
- // Where $plain_fields = array.. you may add additional fields, eg
- // $plain_fields = array(
- // 'field-one',
- // 'field-two'
- // );
- function group_header_fields_save( $group_id ) {
- global $bp, $wpdb;
- $plain_fields = array(
- 'country','url'
- );
- foreach( $plain_fields as $field ) {
- $key = $field;
- if ( isset( $_POST[$key] ) ) {
- $value = $_POST[$key];
- groups_update_groupmeta( $group_id, $field, $value );
- }
- }
- }
- add_filter( 'groups_custom_group_fields_editable', 'group_header_fields_markup' );
- add_action( 'groups_group_details_edited', 'group_header_fields_save' );
- add_action( 'groups_created_group', 'group_header_fields_save' );
- // Show the custom field in the group header
- function show_field_in_header( ) {
- echo "<p> Country:" . custom_field('country') . "</p>";
- echo "<p> Site URL:" . custom_field('url'). "</p>";
- }
- add_action('bp_group_header_meta' , 'show_field_in_header') ;
- }
- add_action( 'bp_include', 'bp_group_meta_init' );
- /* If you have code that does not need BuddyPress to run, then add it here. */
- ?>
Advertisement
Add Comment
Please, Sign In to add comment