Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to add fields to group creation with Group extension API (please read)

  • Profile photo of alfredojp
    alfredojp
    Participant

    @alfredojp

    I’m pretty good with MySql but not so hot with PHP. I’ve spent two weeks trying to figure out how to add
    another field(s) to the group creation so that a few more fields would be standard for the groups (i already know about that plugin that lets group admin put in fields aftewards), hours and hours and hours on these same forums with little help. I ran across group extension API code ( http://codex.buddypress.org/developer-docs/group-extension-api/ ) but i have no idea how to use it. What do i add, and in what file do i put it in (functions.php, bp-custom.php) so that i can have group fields (at creation) for city, state, country and phone number.

    Any help in this is greatly appreciated.

Viewing 25 replies - 1 through 25 (of 57 total)
  • Profile photo of Boone Gorges
    Boone Gorges
    Keymaster

    @boonebgorges

    You can put the group class into bp-custom.php.

    Put the HTML markup for your fields in the display() method. In the create_screen_save() and edit_screen_save() methods, save the data in the $_POST array using groups_update_groupmeta().

    Profile photo of alfredojp
    alfredojp
    Participant

    @alfredojp

    Hi @boonebgorges
    I’m not exactly sure how I save the data from the “create_screen_save()” and “edit_screen_save()” methods in the $_post. I know you’re busy but could you help me out with an exxample?

    Thank you for the help….i’m going to try what you just said to the best of my abilities

    I also ran across the post which you helped someone else on about 9 months ago…same basic problem.
    Here’s the link:
    https://buddypress.org/community/groups/miscellaneous/forum/topic/new-group-creation-fields

    What do you recommend? Any further help is appreciated

    Profile photo of Boone Gorges
    Boone Gorges
    Keymaster

    @boonebgorges

    Profile photo of alfredojp
    alfredojp
    Participant

    @alfredojp

    @boonebgorges
    so from looking at the code you were implementing something for group docs in the group creation process. am I correct? I get kind of confused because the more and more i look at the code the more and more i start to think that its purpose is to add another Screen to the group creation process and not specifically for more fields.
    Correct me if i’m wrong

    Profile photo of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    Yes, it creates a new screen during creation.

    Profile photo of alfredojp
    alfredojp
    Participant

    @alfredojp

    but what about the fields?

    Profile photo of alfredojp
    alfredojp
    Participant

    @alfredojp

    @modemlooper did you see the other code i posted above? which one would be more appropriate to follow to create new fields in the group creation process?

    Thank for the confirmation that it creates a new screen. which is cool too but i also need extra fields for city, state, country, phone number and mestre(teacher)

    Profile photo of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    You will have to edit core files or add_action to the creation. I’m pretty sure this has been asked before search google instead of search on this site

    Profile photo of alfredojp
    alfredojp
    Participant

    @alfredojp

    @modemlooper (if me grabbing your attention this way is rude please let me know)
    Thanks…..but are you referring to the API or to the code i posted when you said i’ll have to edit core files. And yes it has been asked many times before but no one ever seems to complete it.

    Thank you for your time. :)

    Profile photo of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    I’ll find the link and post it but someone even created a plugin to add extra fields below name and description

    Profile photo of alfredojp
    alfredojp
    Participant

    @alfredojp

    I found one called gField but it doesn’t really work…it adds a location field but doens’t make any change tot he group table in the database.

    Profile photo of alfredojp
    alfredojp
    Participant

    @alfredojp

    I found one called gField but it doesn’t really work…it adds a location field but doens’t make any change tot he group table in the database.

    Profile photo of alfredojp
    alfredojp
    Participant

    @alfredojp

    @boonebgorges
    does the groups API code only create a new screen or can i also use it to create extra fields?

    Profile photo of Boone Gorges
    Boone Gorges
    Keymaster

    @boonebgorges

    The groups extension API is meant to add a new tab to the groups interface. If by “create extra fields” you mean that you want to add additional metadata to the Group Details tab, here is some code from a client project I once did. I’ve modified it a bit to remove some custom functions. This should give you an idea of how to start.

    `add_filter( ‘groups_custom_group_fields_editable’, ‘group_details_markup’ );
    add_action( ‘groups_group_details_edited’, ‘group_details_save’ );
    add_action( ‘groups_created_group’, ‘group_details_save’ );

    function group_details_markup() {
    $group_links = groups_get_groupmeta( $bp->groups->current_group->id, ‘e2e_links’ );
    extract( $group_links );

    $group_text = groups_get_groupmeta( $bp->groups->current_group->id, ‘e2e_text’ );

    ?>

    (Type of food, etc)


    groups->current_group->id, ‘e2e_price’ ); ?>

    <option value="1" selected=”selected”>$
    <option value="2" selected=”selected”>$$
    <option value="3" selected=”selected”>$$$
    <option value="4" selected=”selected”>$$$$
    <option value="5" selected=”selected”>$$$$$

    groups->current_group->id, ‘e2e_url’ ); ?>


    <input type="text" name="group-url" id="group-url" value="” />

    groups->current_group->id, ‘e2e_url’ ); ?>


    <input type="text" name="group-phone" id="group-phone" value="” />


    <input type="text" name="group-menupages" id="group-menupages" value="” />


    <input type="text" name="group-yelp" id="group-yelp" value="” />


    <input type="text" name="group-chow" id="group-chow" value="” />


    <input type="text" name="group-everyblock" id="group-everyblock" value="” />

    <?php

    return;
    }

    function group_details_save( $group_id ) {
    global $bp, $wpdb;

    $plain_fields = array(
    ‘url’,
    ‘phone’,
    ‘text’,
    ‘price’
    );

    $links_fields = array(
    ‘menupages’ => ‘MenuPages’,
    ‘yelp’ => ‘Yelp’,
    ‘chow’ => ‘Chow’,
    ‘everyblock’ => ‘EveryBlock’
    );

    foreach( $plain_fields as $field ) {
    $key = ‘group-‘ . $field;
    if ( isset( $_POST[$key] ) ) {
    $value = $_POST[$key];
    groups_update_groupmeta( $group_id, ‘e2e_’ . $field, $value );
    }
    }

    $links = array();
    foreach( $links_fields as $fn => $name ) {
    $key = ‘group-‘ . $fn;
    if ( isset( $_POST[$key] ) ) {
    $links[$name] = $_POST[$key];
    }
    }
    groups_update_groupmeta( $group_id, ‘e2e_links’, $links );

    // Prevent null searches by entering dummy values for important meta
    if ( !groups_get_groupmeta( $group_id, ‘bpgr_rating’ ) )
    groups_update_groupmeta( $group_id, ‘bpgr_rating’, ‘null’ );

    if ( !groups_get_groupmeta( $group_id, ‘bpgr_how_many_ratings’ ) )
    groups_update_groupmeta( $group_id, ‘bpgr_how_many_ratings’, ‘null’ );

    if ( !groups_get_groupmeta( $group_id, ‘e2e_price’ ) )
    groups_update_groupmeta( $group_id, ‘e2e_price’, ‘null’ );
    }`

    Profile photo of alfredojp
    alfredojp
    Participant

    @alfredojp

    @boonebgorges

    Thank you i’m starting to understand alot more……but where would this and the Group API code go?? in bp-custom.php or in functions.php?

    Profile photo of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    @boonebgorges I don’t think that code will work with 1.5

    Did these get changed in 1.5

    add_action( ‘groups_group_details_edited’, ‘group_details_save’ );
    add_action( ‘groups_created_group’, ‘group_details_save’ );

    Profile photo of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    oops, missing global. Making this into a plugin but might need some help. i’ll post it on git hub. Think we need same extra field functionality as profiles

    `function group_details_markup() {
    global $bp, $wpdb;`

    Profile photo of alfredojp
    alfredojp
    Participant

    @alfredojp

    @modemlooper @boonebgorges
    It would be nice if 1.5 was already capable of adding more fields like location, phone,, blah blah blah to the group creation process.

    But where do i put this? i already have another function in bp-custom.php.

    Profile photo of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    @alfredojp I agree but that’s not happening, it could be added to1.6. First a plugin and then a move to core if it works well.

    Profile photo of alfredojp
    alfredojp
    Participant

    @alfredojp

    @modemlooper

    hehe so should i put this in functions.php?

    Profile photo of alfredojp
    alfredojp
    Participant

    @alfredojp

    I’m sorry, i really am quite lost! :(

    Profile photo of alfredojp
    alfredojp
    Participant

    @alfredojp

    I’m sorry, i really am quite lost! :(

    Profile photo of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    Profile photo of alfredojp
    alfredojp
    Participant

    @alfredojp

    oooo wow….i’m gonna try it now

    Profile photo of alfredojp
    alfredojp
    Participant

    @alfredojp

    @modemlooper @boonebgorges

    It worked beautifully, thank you both for all of your help however underneath the description when i went to try it out it has a warning:
    `Warning: extract() [function.extract]: First argument should be an array in /home/caradaca/public_html/wp-content/plugins/Buddypress-group-fields/buddypress-group-fields.php on line 9`

    and when i created the group and then checked my settings none of the newly added fields were there until i added them again and hit “save settings”. I didn’t check the database to see if it was there or not. Does it do anything to the database?

Viewing 25 replies - 1 through 25 (of 57 total)
  • The topic ‘How to add fields to group creation with Group extension API (please read)’ is closed to new replies.