Group Mods

  • Profile picture of @mercime
  • Profile picture of r-a-y
  • Profile picture of Hugo

Support: Creating & Extending

Existing and new plugins/components and themes.

Restricting group creation to admins (23 posts)

Started 2 years, 7 months ago by: Simon Wheatley

  • Profile picture of Simon Wheatley Simon Wheatley said 2 years, 7 months ago:

    I’m digging through the functions for creating a new group (particularly groups_screen_create_group), trying to find some hooks I can use for a plugin to restrict creation of groups to admins only. So far I’ve not had any luck… am I missing something? Would a patch to add some hooks in for this purpose be acceptable?

    TIA,

    S

  • Profile picture of Simon Wheatley Simon Wheatley said 2 years, 7 months ago:

    I’ve proposed a patch to add a hook which would allow the restriction of group creation through a plugin, and provided a plugin which demonstrates it’s use in this trac ticket: http://trac.buddypress.org/ticket/1150

    How does it look?

    (Also, not sure whether trac keywords should be comma separated?)

  • Profile picture of densyo15 densyo15 said 2 years, 7 months ago:

    I also like to do this on my site, thanks Simon! So where do I apply/install the files you just mentioned in trac to restrict group creation to admins?

  • Profile picture of Simon Wheatley Simon Wheatley said 2 years, 7 months ago:

    OK, but bear in mind you will be editing the core files, which is Not A Good Thing ™.

    Apply this diff to plugins/buddypress/bp-groups.php: http://trac.buddypress.org/attachment/ticket/1150/hook-to-stop-group-creation.diff

    Then use this plugin code as the basis for your own restrictions based on whatever you want: http://trac.buddypress.org/attachment/ticket/1150/restrict-group-creation.php

  • Profile picture of densyo15 densyo15 said 2 years, 7 months ago:

    Thanks for this Simon. I have 2 questions though:

    1. Do I just have to add this code at http://trac.buddypress.org/attachment/ticket/1150/hook-to-stop-group-creation.diff in the bp-groups.php or do I have to edit the whole file? If I have to edit it, in what particular part of the file should I put the code?

    2. The code in http://trac.buddypress.org/attachment/ticket/1150/restrict-group-creation.php will be used as a plugin right? and I will upload it in the plugins folder and activate it?

    Thanks in advance for your response!

  • Profile picture of densyo15 densyo15 said 2 years, 7 months ago:

    It’s fine now Simon, I got it! And thanks to you I have restricted group creation in my site, THANKS AGAIN!!!

  • Profile picture of densyo15 densyo15 said 2 years, 7 months ago:

    Simon, I just found out that with the patches and plugin installed even admins can’t even create a group! Is there a way in the patches you have given wherein admins are only the ones that can create the groups and not the normal users of the site?

    Thanks again in advance for your response!

  • Profile picture of Simon Wheatley Simon Wheatley said 2 years, 7 months ago:

    The plugin is proof of concept code, you need to decide under what circumstances you want to allow group creation. At the moment, as you say, everyone is restricted… perhaps you want to base it on user capabilities? Have a look at the WordPress function current_user_can (support forum tag) and use this in rgc_validate_group_creation something like this (untested):

    // Stop the creation of a group unless the current user can manage options
    function rgc_validate_creation( $allowed, $group_details ) {
    // User is OK to continue if they can manage options
    if ( current_user_can( 'manage_options' ) )
    return true;
    // Otherwise they can't
    bp_core_add_message( 'Sorry, you are not allowed to create groups.', 'error' );
    return false;
    }

  • Profile picture of vusis vusis said 2 years, 5 months ago:

    hey guys i cant seem to figure this one out hey; i’ve tried to patch the bp-groups.php file but i get a

    #1 HUNK Failed at 449 – please see my reject file

    ***************
    *** 453,459 ****
    bp_core_redirect( $bp->loggedin_user->domain . $bp->groups->slug . ‘/create/step/’ . $bp->groups->current_create_step );
    }

    - if ( !$bp->groups->new_group_id = groups_create_group( array( ‘group_id’ => $bp->groups->new_group_id, ‘name’ => $_POST['group-name'], ‘description’ => $_POST['group-desc'], ‘news’ => $_POST['group-news'], ‘slug’ => groups_check_slug( sanitize_title($_POST['group-name']) ), ‘date_created’ => time() ) ) ) {
    bp_core_add_message( __( ‘There was an error saving group details, please try again.’, ‘buddypress’ ), ‘error’ );
    bp_core_redirect( $bp->loggedin_user->domain . $bp->groups->slug . ‘/create/step/’ . $bp->groups->current_create_step );
    }
    — 453,474 —-
    bp_core_redirect( $bp->loggedin_user->domain . $bp->groups->slug . ‘/create/step/’ . $bp->groups->current_create_step );
    }

    + $group_details = array(
    + ‘group_id’ => $bp->groups->new_group_id,
    + ‘name’ => $_POST['group-name'],
    + ‘description’ => $_POST['group-desc'],
    + ‘news’ => $_POST['group-news'],
    + ‘slug’ => groups_check_slug( sanitize_title($_POST['group-name']) ),
    + ‘date_created’ => time() );
    +
    + /* Allow plugins to halt group creation for whatever reason. On doing this the plugin
    + should use the bp_core_add_message function to inform the user why the group creation
    + has failed.
    + N.B. The data passed in $new_group is unsanitised. */
    + if ( ! apply_filters( ‘bp_allow_create_group’, true, $group_details ) )
    + return bp_core_redirect( $bp->loggedin_user->domain . $bp->groups->slug . ‘/create’ );
    +
    + if ( !$bp->groups->new_group_id = groups_create_group( $group_details ) ) {
    bp_core_add_message( __( ‘There was an error saving group details, please try again.’, ‘buddypress’ ), ‘error’ );
    bp_core_redirect( $bp->loggedin_user->domain . $bp->groups->slug . ‘/create/step/’ . $bp->groups->current_create_step );
    }

    i’m not too sure what that means and how it can be fixed? :(

  • Profile picture of vusis vusis said 2 years, 5 months ago:

    I really don’t understand how the patch works, but i activated the plugin alone without the patch and it works; no one is allowed to create groups.

    now i’m working on conditions – thanks for the plugin

  • Profile picture of Ashfame (Ashish Kumar) Ashfame said 2 years, 3 months ago:

    Any updates on this one?

  • Profile picture of stefrusso stefrusso said 2 years, 3 months ago:

    I really think there should be a plugin for this… many other social network systems have it built in, like Ning. I wish I knew something about programming so I could make it but alas… I can donate 20$ since I really need this for my site before I launch.

  • Profile picture of Mike Pratt Mike Pratt said 2 years, 3 months ago:

    Thi si ugly, but until an elegant solution is presented you can just change teh nav element for the Create button to display: none; and 99.99% of your users will have no clue that it’s even possible. For those that sneak thru in the meantime, you can just delete the bog. Don’t worry, a solution is forthcoming.

  • Profile picture of ajohnson ajohnson said 2 years, 3 months ago:

    Try using the wordpress loop..having tried this yet but it should worked in theory to block the button from subscribers. This should really be built into buddypres though.

    <?php if ( current_user_can(‘edit_post’) ) {

    // button goes here

    } ?>

  • Profile picture of Ashfame (Ashish Kumar) Ashfame said 2 years, 3 months ago:

    Hiding the button to create group till any solution is fine but if its possible just by a plugin, I mean the core provides the necessary hook then I am ready to code this thing but I definitely need some guidance here.