Manage group creation by creating a group request form

If you want to simply manage group creation on your BuddyPress site, this Trick will show you how to add a form that will send an email containing a request from the member. To achieve this we’ll need to modify a 2 template files of your active (child)theme and put some some code in the functions.php file. Let’s get started!

Step 1 : Add two templates to your Child Theme

Copy the following folder from the BP-Default Theme to your Child Theme:

/groups/index.php
/groups/create.php.

So you should now have a folder called Groups in your Child Theme, with the files index.php and create.php in it

Step 2: Edit index.php

In index.php on line 7 replace:

 

with

   Request a Group

Step 3: Edit Create.php

What we are going to to is hide the Group Creation form for regular members, and only make it viewable for logged in Admins. To do so we just add the following code just before the tag form

Then after the closing tag of the form around line 255, add this :


        

You need to request the Admin to create your group !

Step 4 : Adding some code to functions.php

Simply paste in the following code :

//request group functions
function imath_req_gp_add_request_form(){
        if(!current_user_can('manage-options')){
                ?>
                


loggedin_user->userdata->user_login." wants to manage a group !nnGroup name:n ".stripslashes($_POST['group_slug'])."nnGroup description: n".stripslashes($_POST['group_desc'])."n________________nn"; $message.= "To view his/her profile: ".$bp->loggedin_user->domain."nTo send him an email: ".$bp->loggedin_user->userdata->user_email; if(wp_mail( $to, $subject, $message) ){ echo "ok"; } else echo "ko"; die(); } add_action('wp_ajax_imath_req_gp_ajax_call', 'imath_req_gp_handle_ajax'); function imath_req_gp_load_style_js(){ if(bp_is_page( BP_GROUPS_SLUG )){ ?>
'); }else{ jQuery("#gp_req_button_container").html(oldhtml); jQuery("#group_request_container #message").html('

OOps something went wrong, please try again..

'); } }); } jQuery(document).ready(function(){ jQuery("#imath_req_gp_button").click(function(){ jQuery("#group_request_container").slideToggle(); }); jQuery("#_confirm_request_button").click(function(){ if(jQuery("#_user_group_name").val().length < 1){ alert("Please choose a group name"); } else if(jQuery("#_user_group_desc").val().length < 1){ alert("Please add a short description of your group"); } else{ js_send_request(); } }); });

What we’ve done now, is created a custom form that regular members need to fill in, if they want a BuddyPress group to be created. When you receive a request you can then manually create the Group, and make the person who made the request the Group Admin.

Voilà icon smile Manage group creation by creating a group request form

BuddyPress Hosting Guide Looking for quality BuddyPress hosting? We will guide you through all the available hosting options and help you find the best webhost for your next BuddyPress project!

12 Responses to Manage group creation by creating a group request form

  1. imath January 5, 2011 at 9:29 pm #

    I think this plugin http://wordpress.org/extend/plugins/bp-admin-actions/ by slaFFik can be useful to add the member to the group once created..

    Reply
  2. Wendell August 16, 2011 at 6:57 pm #

    This is not working in BP 1.5b2. When clicking the “Create Group” button, regardless of whether you are a regular user or admin, you get the red message stating you have to request the group from the Admin. Also, the request form does not appear.

    Thank you for this site, I really appreciate it and look forward to your tricks for BP 1.5. :-)

    Reply
  3. Mistafo August 22, 2011 at 3:05 pm #

    when I add this it works great but I don’t see the create group button when I view it being the admin. Any ideas why? I can’t create groups at all with this enabled.

    Reply
  4. Igor Longagnani January 16, 2012 at 4:09 am #

    I managed to make Create Button appear when I am logged as WP Admin using the WP function
    current_user_can(‘administrator’)
    instead of
    current_user_can(‘manage-options’)
    still e-mail is not sent by normal users correctly, still checking why

    Reply
    • E.J. June 5, 2012 at 3:46 am #

      Did you ever figure this out? Im getting the same issue.

      Thanks!

      Reply
  5. March 12, 2012 at 8:19 am #

    I really appreciate this work and in fact in works like a charm for me! however I don’t understand why people is coding this way, I would love to see css alone in .css file and html alone with some of your functions API in ‘view’ and pure php script in functions.php. anyways this is just my personal thought,

    Again, thank you so much!

    Reply
  6. John April 20, 2012 at 4:12 pm #

    This would be great to automate. Is there anyway to automate the group creation? Lets say a user wants to create a group associated with a particular custom post. It would be cool if they could click create group from the front end and it would automatically create a group linked to their custom post.

    Reply
  7. Josh Craig April 30, 2012 at 1:19 pm #

    Thanks for the tutorial.

    But, I am having an issue.

    The Admin should be able to click on “Create Group” and create a group as normal. But in my case when I click “Create Group” I get the Red warning box, but the form does not show up.

    Second issue, is that when I’m logged into the site as a normal member when I click on create group the group page just reloads instead of showing the error message and the request a group form.

    I followed the steps exactly, is there anything I might have missed, or code that I can change?

    Thanks

    Reply
  8. imath July 30, 2012 at 8:51 pm #

    Hello,

    Sorry for my late reply, i’ve modified the script to make it work in BuddyPress 1.5+ and packed it in a child theme.. You can download it from my dropbox.

    Hope it will fix the issues mentioned.

    Reply
  9. Thrasher March 8, 2013 at 5:31 am #

    Thanks . Trick is good . :)

    Reply

Trackbacks/Pingbacks

  1. How to restrict or disable create group button in Buddypress | This Grasya on the road less traveled - November 26, 2011

    [...] https://bp-tricks.com/coding/manage-group-creation-by-creating-a-group-request-form/ [...]

  2. How to restrict or disable create group button in Buddypress | This Grasya on the Road - December 26, 2012

    [...] https://bp-tricks.com/coding/manage-group-creation-by-creating-a-group-request-form/ [...]

Leave a Reply