Skip to:
Content

BuddyPress.org

Ticket #1150: restrict-group-creation.php

File restrict-group-creation.php, 1.4 KB (added by simonwheatley, 14 years ago)

Plugin showing how the new hook might be used in a plugin which stops group creation

Line 
1<?php
2/*
3
4Plugin Name: Restrict Group Creation
5Plugin URI: http://simonwheatley.co.uk/wordpress/restrict-group-creation/
6Description: Stops anyone and everyone from creating groups.
7Version: 1.0
8Author: Simon Wheatley
9Author URI: http://www.simonwheatley.co.uk/
10
11*/
12
13// Stop the creation of a group
14function rgc_validate_creation( $allowed, $group_details ) {
15        // At this point one could check the capabilities of the user, the details of the
16        // group to be created, etc.
17        bp_core_add_message( 'Sorry, you are not allowed to create groups.', 'error' );
18        return false;
19}
20add_filter( 'bp_allow_create_group', 'rgc_validate_creation', null, 2 );
21
22// Remove the create group link, so people don't get confused.
23function rgc_remove_create_group_link() {
24        global $bp;
25        // Again, at this point one could check the capabilities of the user, the details
26        // of the group to be created, etc.
27        bp_core_remove_subnav_item( $bp->groups->slug, 'create' );
28}
29add_action( 'groups_setup_nav', 'rgc_remove_create_group_link', 15 );
30
31// Put a notice on the Group Creation screen warning the user that group creation
32// will not be possible.
33function rgc_notify_no_group_creation( $data ) {
34        // Again, at this point one could check the capabilities of the user, the details
35        // of the group to be created, etc.
36        bp_core_add_message( 'Sorry, you are not allowed to create groups.', 'error' );
37        return $data;
38}
39add_filter( 'bp_group_creation_stage_title', 'rgc_notify_no_group_creation' );
40
41?>