Skip to:
Content

Ticket #1150: hook-to-stop-group-creation.diff

File hook-to-stop-group-creation.diff, 1.9 KB (added by simonwheatley, 5 years ago)

Patch to add a hook allowing plugins to restrict group creation

  • Users/simon/Projects/BuddyPress/trunk/site/wp-content/plugins/buddypress/bp-groups.php

     
    449449                                bp_core_redirect( $bp->loggedin_user->domain . $bp->groups->slug . '/create/step/' . $bp->groups->current_create_step ); 
    450450                        } 
    451451                         
    452                         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() ) ) ) { 
     452                        $group_details = array(  
     453                                'group_id' => $bp->groups->new_group_id,  
     454                                'name' => $_POST['group-name'],  
     455                                'description' => $_POST['group-desc'],  
     456                                'news' => $_POST['group-news'],  
     457                                'slug' => groups_check_slug( sanitize_title($_POST['group-name']) ),  
     458                                'date_created' => time() ); 
     459                         
     460                        /* Allow plugins to halt group creation for whatever reason. On doing this the plugin 
     461                           should use the bp_core_add_message function to inform the user why the group creation 
     462                           has failed. 
     463                           N.B. The data passed in $new_group is unsanitised. */ 
     464                        if ( ! apply_filters( 'bp_allow_create_group', true, $group_details ) ) 
     465                                return bp_core_redirect( $bp->loggedin_user->domain . $bp->groups->slug . '/create' ); 
     466 
     467                        if ( !$bp->groups->new_group_id = groups_create_group( $group_details ) ) { 
    453468                                bp_core_add_message( __( 'There was an error saving group details, please try again.', 'buddypress' ), 'error' ); 
    454469                                bp_core_redirect( $bp->loggedin_user->domain . $bp->groups->slug . '/create/step/' . $bp->groups->current_create_step );                                 
    455470                        }