Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- *
- *
- * This file defines and implements custom group fields for Great Books Great Discussions.
- *
- *
- */
- 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;?>
- <label for="group-custom-field-address">Address</label>
- <input id="group-custom-field-address" type="text" name="group-custom-field-address" value="<?php echo custom_field('group-custom-field-address'); ?>" />
- <label for="group-custom-field-address-unit">Apt. / Unit / Suite:</label>
- <input id="group-custom-field-address-unit" type="text" name="group-custom-field-address-unit" value="<?php echo custom_field('group-custom-field-address-unit'); ?>" />
- <label for="group-custom-field-city">City</label>
- <input id="group-custom-field-city" type="text" name="group-custom-field-city" value="<?php echo custom_field('group-custom-field-city'); ?>" />
- <label for="group-custom-field-state">State</label>
- <input id="group-custom-field-state" type="text" name="group-custom-field-state" value="<?php echo custom_field('group-custom-field-state'); ?>" />
- <label for="group-custom-field-zip">Zip Code</label>
- <input id="group-custom-field-zip" type="text" name="group-custom-field-zip" value="<?php echo custom_field('group-custom-field-zip'); ?>" />
- <br>
- <?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(
- 'group-custom-field-address',
- 'group-custom-field-address-unit',
- 'group-custom-field-city',
- 'group-custom-field-state',
- 'group-custom-field-zip',
- );
- 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>Address:" . custom_field('group-custom-field-address') . "</p>";
- echo "<p>Apt. / Unit / Suite:" . custom_field('group-custom-field-address-unit') . "</p>";
- echo "<p>City:" . custom_field('group-custom-field-city') . "</p>";
- echo "<p>State:" . custom_field('group-custom-field-state') . "</p>";
- echo "<p>Zip code:" . custom_field('group-custom-field-zip') . "</p>";
- }
- add_action('bp_group_header_meta' , 'show_field_in_header') ;
- function gbgd_bpgf_filter_ajax_querystring( $querystring = '', $object = '' ) {
- /* bp_ajax_querystring is also used by other components, so you need
- to check the object is groups, else simply return the querystring and stop the process */
- if( $object != 'groups' )
- return $querystring;
- // Let's rebuild the querystring as an array to ease the job
- $defaults = array(
- 'type' => 'active',
- 'action' => 'active',
- 'scope' => 'all',
- 'page' => 1,
- 'user_id' => 0,
- 'search_terms' => '',
- 'exclude' => false,
- );
- $gbgd_bpgf_querystring = wp_parse_args( $querystring, $defaults );
- /* this is your meta_query */
- $gbgd_bpgf_querystring['meta_query'] = array(
- 'relation' => 'OR',
- array(
- 'key' => 'group-custom-field-zip',
- 'value' => $gbgd_bpgf_querystring["search_terms"],
- 'type' => 'numeric',
- 'compare' => 'LIKE'
- )
- );
- echo '<pre>';
- var_dump($gbgd_bpgf_querystring["search_terms"]);
- echo '</pre>';
- // using a filter will help other plugins to eventually extend this feature
- return apply_filters( 'gbgd_bpgf_filter_ajax_querystring', $gbgd_bpgf_querystring, $querystring );
- }
- /* The groups loop uses bp_ajax_querystring( 'groups' ) to filter the groups
- depending on the selected option */
- add_filter( 'bp_ajax_querystring', 'gbgd_bpgf_filter_ajax_querystring', 20, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement