Skip to:
Content
Pages
Categories
Search
Top
Bottom

Restricting group creation to admins


  • Simon Wheatley
    Participant

    @simonwheatley

    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

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

  • Simon Wheatley
    Participant

    @simonwheatley

    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: https://trac.buddypress.org/ticket/1150

    How does it look?

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


    densyo15
    Participant

    @densyo15

    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?


    Simon Wheatley
    Participant

    @simonwheatley

    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: https://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: https://trac.buddypress.org/attachment/ticket/1150/restrict-group-creation.php


    densyo15
    Participant

    @densyo15

    Thanks for this Simon. I have 2 questions though:

    1. Do I just have to add this code at https://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 https://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!


    densyo15
    Participant

    @densyo15

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


    densyo15
    Participant

    @densyo15

    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!


    Simon Wheatley
    Participant

    @simonwheatley

    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;

    }


    vusis
    Participant

    @vusis

    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? :(


    vusis
    Participant

    @vusis

    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

    Any updates on this one?


    stefrusso
    Participant

    @stefrusso

    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.


    Mike Pratt
    Participant

    @mikepratt

    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.

    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

    } ?>

    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.


    stefrusso
    Participant

    @stefrusso

    HI Mike.. that ought to work for now.. how exactly do I remove the button for Create Group? Is it an image? If I can just get rid of the button then I can put a link in my browser fav bar that goes to the page where I can create a group and nobody else will ever find that page without the button.

    thanks for the help!


    Mike Pratt
    Participant

    @mikepratt

    @stefrusso add this to your style sheet

    form#groups-directory-form .button {
    display: none;
    }


    stefrusso
    Participant

    @stefrusso

    thanks, Mike.

    can i also ask exactly which style.css sheet? I tried adding the code in the specific theme (bp-widget by modemlooper), also in the default style sheet (the one found under themes, not under plugins), but it didn’t remove the button.

    given that I’m the equivalent of a 10-year old trying to fix an automobile, could you give me a few tips to help me get to the right file and insert the above code in the correct way?

    cheers!


    Mike Pratt
    Participant

    @mikepratt

    Sorry for the delay in rsponding. Damn job got it the way!

    Looking at the bp-widget theme, he only uses style.css. so adding the code to style.css in the bp-widget folder ought to do the trick.

    @modemlooper you could save an expensive import call by jsut importing bp-default/style.css instead

    Hi! Bit of an old thread I know, but is there still no way to do this other than:

    a) hacking the core with the diff @simonwheatley kindly posted
    b) Hiding the button in the template, which technically leaves the functionality in place

    Just had a look at the trunk and there still doesn’t seem to be anything there like this. Would have thought a lot of people would be after it!


    larrysmith1000
    Member

    @larrysmith1000

    I’m after it too vonkanehoffen. I’d have thought there would be lots of people in this boat.

    It seems the buddypress developers are discouraging the use of user capabilities in buddypress. They don’t want it to be used for content management. I’m not sure why. I think it is a mistake. It makes buddypress look like a hanging appendage off of wordpress. It doesn’t allow buddypress to integrate seamlessly into wordpress’s blog engine.


    aces
    Participant

    @aces


    Joshua Craig
    Participant

    @helpfulnerd

    Hi everyone,

    I’m currently working on a project and my client wants only the admins to be able to create groups, so I set that option in the BuddyPress admin area, easy peasy. But, the Create A Group button still appears on the front end. For now I am simply looking for a way to hide that button, and I’ve added the CSS @Mike Pratt suggested but the button remains. Any ideas?

    What would be really cool (not that I have a clue how to do this) would be:

    1.) BP functionality that automagically removes the Create A Group button when you select that only admins can create groups, that would be ideal.
    or
    2.) A way to change the URL of the Create A Group button for the members level, so you could create a Request A Group page with a form that a member can fill out requesting a group. That is what I’d like to do, but I’m at a loss for where to start in the code, and I’m not much of a PHP dev.

Viewing 22 replies - 1 through 22 (of 22 total)
  • The topic ‘Restricting group creation to admins’ is closed to new replies.
Skip to toolbar