Skip to:
Content
Pages
Categories
Search
Top
Bottom

New Group creation fields


  • David
    Participant

    @dlabbe

    I am learning php and I am not at the level in how BP is written so it is hard for me to break down all that code at this time. So with that said I need some help. I would like to create a new field in the group creation process. For example…when someone adds a new group they are asked for “name” and “description” of the group. I want to be able to add something like “country” and have a select from list of the countries and when the group is created the new field in bp_groups table will list the country that group is in.
    Now…all I need is to figure out how to insert the option into the creation forms. I can add the field manual to the database if needed and design the form part(the select option) I just need help with the logic of it using BP.
    My last option will to be to design the insert to database after the group is created and have the extra options in the group-header.php file that is logically only seen by the admin. Don’t want to go that route, but until I learn more about php and can understand the BP way…it might be my only option. Thanks for any help in advance.

Viewing 18 replies - 1 through 18 (of 18 total)

  • David
    Participant

    @dlabbe

    any help would be greatly appreciated…thanks


    Boone Gorges
    Keymaster

    @boonebgorges

    Basically, you’ll need two functions to make it happen. One will create the form markup, and the other will process the data. Here’s a skeleton:

    `function bbg_extra_group_fields_markup() {
    // Put your form markup here, eg:
    ?>

    <?php
    }
    add_action( ‘groups_custom_group_fields_editable’, ‘bbg_extra_group_fields_markup’ );`

    That’ll insert the fields into the group admin page. Keep in mind that you might want to echo the current value in the value=”” field. Then:

    `function bbg_save_extra_group_details() {
    // Grab the $_POST data and do something with it. Simplified example:
    global $bp;
    if ( isset( $_POST ) )
    groups_update_groupmeta( $bp->groups->current_group->id, ‘country’, $_POST );
    }
    add_action( ‘groups_group_details_edited’, ‘bbg_save_extra_group_details’ );
    add_action( ‘groups_create_group_step_save_group-details’, ‘bbg_save_extra_group_details’ );`

    That’s untested, so you might need to do some finagling to make it work for both group creation and editing. But that should give you an idea.


    David
    Participant

    @dlabbe

    thanks so much for the reply. The code all makes sense…. just a question of where to insert it? I am working with a child theme so can I create a custom function.php file within my child theme? Also…is that all it will take is to insert the functions into the functions.php file(if that is where to insert them)?


    David
    Participant

    @dlabbe

    Just tested it. I made a functions.php in my child theme and it works….well not really. I have the extra form field showing, but it is not working. I added the extra field to the database, but it is not working. I will have to test it more, but at least I now have some what of a clue of how BP works. I will play with it more before asking anymore questions….thanks for your help!


    David
    Participant

    @dlabbe

    @boonebgorges thanks for the help! My php skills have increased a notch from just playing with this….not to mention of having a better understanding of BP. I used the trick above, but put a major twist on it. I took it to a new level and created new tables within the database so I can organize all the extra setting I am adding to groups. Thanks again. Just wanted to ask however….I am including the functions in my child theme as the bg-custom.php in the plugins did not work for what ever reason. Is it ok to use the functions.php in the child theme? Do you know why the bg-custom.php would not work in the plugins folder?


    Boone Gorges
    Keymaster

    @boonebgorges

    Make sure it’s /wp-content/plugins/bp-custom.php (‘bp’ as in ‘BuddyPress’, not ‘bg’ as in ‘Boone Gorges’) :)

    It’s fine to keep it in your functions.php if it works for you, though.


    David
    Participant

    @dlabbe

    sorry yes bp-custom.php. That was a bad on my part in the post. I used “bp” in the site. I think i will just keep things the way they are as they are working. Thanks again.


    David
    Participant

    @dlabbe

    @boonebgorges My plan has hit a snag. I am having trouble using what you gave me above to include more then one set of form markups. Let me explain…if I include something like

    function bbg_extra_group_fields_markup() {
    ?>

    this form is for a new data table that I created
    }
    add_action( ‘groups_custom_group_fields_editable’, ‘bbg_extra_group_fields_markup’ );

    function bbg_save_extra_group_details() {

    // form 1 processing goes here with insert/update
    }
    add_action( ‘groups_group_details_edited’, ‘bbg_save_extra_group_details’ );
    add_action( ‘groups_create_group_step_save_group-details’, ‘bbg_save_extra_group_details’ );

    The above formula works great! I created a new table and I am able to populate it with no issues. Now..this is where things get messy and I am having trouble trying to figure a way around it. I want to duplicate the same code above with another table for separate settings. I am using jquery show/hide to show the form that is needed for the desired group settings. Another words Group A gets one type of settings and Group B gets another inputing the data to their own data table. So if i duplicate the code above twice the processing clashes…meaning if both groups have a table field with the same name things get a little messed up processing. Is there a way to group the code for Group A and Group B? meaning ” function bbg_save_extra_group_details()” for Group A belongs to “function bbg_extra_group_fields_markup()” of Group A. I am thinking “if” statements but then not sure. I know it sounds confusing but again any ides would be greatly appreciated. Also forgot to mention that when I duplicated the functions for Group B I did name it something new. Thanks


    Boone Gorges
    Keymaster

    @boonebgorges

    You shouldn’t need more functions, just conditional checks inside of the plugins. Something like:

    `function bbg_save_extra_group_details() {
    global $bp;

    if ( ‘yes’ == groups_get_groupmeta( $bp->groups->current_group->id, ‘is_this_group_a’ ) ) {
    // do some group A stuff
    } else {
    // do some group B stuff
    }
    }`

    You don’t have to use groupmeta to distinguish between the groups, but you will definitely have to have some way of distinguishing between them.


    David
    Participant

    @dlabbe

    @boonebgorges Once again thanks for the help. I used the code above but noticed that the database dose not take in the data when the group is created. It will only work if once the group is created and then I re-enter the information in the “country” form and the submit that the database updates with the new information. My only thought is that when the group is being created it yet has an ID so it causes an issue. Any thoughts?


    Boone Gorges
    Keymaster

    @boonebgorges

    I just took a peek at the BP source, and it looks like the group *has* been created by the point in question, but the information hasn’t been loaded into $bp->groups->current_group yet. Here’s a variant on the code that might work (or something like it):
    `
    function bbg_save_extra_group_details() {
    global $bp;

    if ( $bp->groups->new_group_id )
    $group_id = $bp->groups->new_group_id;
    else
    $group_id = $bp->groups->current_group->id;

    if ( ‘yes’ == groups_get_groupmeta( $group_id, ‘is_this_group_a’ ) ) {
    // do some group A stuff
    } else {
    // do some group B stuff
    }
    }
    `


    David
    Participant

    @dlabbe

    @boonebgorges works perfect! thanks. I have hopefully one last issue that completely has me stumped. It works on my testing machine, but when I put it live I get errors. It has to do with me including the above idea but using my own custom data table. I insert my own form and add it with the function like above and put my own processing in the save function like above using the standard insert/update sql pointing to the new table for the form. It works on my local machine, but when I upload it live and click on ” create group” i get the following error….sorry for all the code

    Warning: Cannot modify header information – headers already sent by (output started at /home/clubmash/public_html/wordpress/wp-content/themes/chatCaddie_theme/functions.php:141) in /home/clubmash/public_html/wordpress/wp-content/plugins/buddypress/bp-groups.php on line 1053

    Warning: Cannot modify header information – headers already sent by (output started at /home/clubmash/public_html/wordpress/wp-content/themes/chatCaddie_theme/functions.php:141) in /home/clubmash/public_html/wordpress/wp-content/plugins/buddypress/bp-groups.php on line 1054

    Warning: Cannot modify header information – headers already sent by (output started at /home/clubmash/public_html/wordpress/wp-content/themes/chatCaddie_theme/functions.php:141) in /home/clubmash/public_html/wordpress/wp-includes/pluggable.php on line 890

    I am working in a child theme and I am at my ends trying to fix this. I am so close to what I want to do I just would hate to give up now. thanks for any tips you can give me.


    Boone Gorges
    Keymaster

    @boonebgorges

    Hi David. It’s impossible to tell from what you give here exactly what’s going on. My guess is that something that you’re doing in functions.php is throwing an error that can’t be printed to the screen because of other stuff that BP core has already output. Try some var_dump statements in the passages leading up to line 141 to see if you can locate the issue.


    David
    Participant

    @dlabbe

    @boonebgorges I got it working….it was white space in the php. I did a search and others had the same issue. Something so small can turn into hours of hair pulling. I am for sure getting a crash course in php, but loving it. Thanks again and I think everything is the way I need it for now…but then again I still need much more testing under all possibilities.


    Boone Gorges
    Keymaster

    @boonebgorges

    Great! Good luck.


    David
    Participant

    @dlabbe

    @boonebgorges thought I would rehash this old post as what I need applies. How do i validate custom fields that I added?


    Boone Gorges
    Keymaster

    @boonebgorges

    @dlabbe – Check out how BP itself validates its own fields. See groups_action_create_group() in bp-groups.php, in particular the stuff after
    `if ( ‘group-details’ == $bp->groups->current_create_step ) {`


    David
    Participant

    @dlabbe

    yes thanks…I was looking at it earlier and starting to get a feel for it. I only wanted to ask as with everything there seems be more then one way to do everything and was hoping there might be a neat little trick BP had up its sleeve. Thanks for the reply.

Viewing 18 replies - 1 through 18 (of 18 total)
  • The topic ‘New Group creation fields’ is closed to new replies.
Skip to toolbar