Skip to:
Content

BuddyPress.org

Changeset 4338


Ignore:
Timestamp:
05/09/2011 09:07:25 PM (9 years ago)
Author:
boonebgorges
Message:

Adds admin switch to allow group creation to be restricted to Super Admins only. Fixes #1150. Props cnorris23

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/admin/bp-core-admin.php

    r4257 r4338  
    133133                                <input type="radio" name="bp-admin[bp-disable-blogforum-comments]"<?php if ( (int)get_site_option( 'bp-disable-blogforum-comments' ) || false === get_site_option( 'bp-disable-blogforum-comments' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-blogforum-comments" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
    134134                                <input type="radio" name="bp-admin[bp-disable-blogforum-comments]"<?php if ( !(int)get_site_option( 'bp-disable-blogforum-comments' ) ) : ?> checked="checked"<?php endif; ?> id="bp-disable-blogforum-comments" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
     135                            </td>
     136                        </tr>
     137
     138                    <?php endif; ?>
     139
     140                    <?php if ( bp_is_active( 'groups' ) ) : ?>
     141
     142                        <tr>
     143                            <th scope="row"><?php _e( 'Restrict group creation to Site Admins?', 'buddypress' ) ?>:</th>
     144                            <td>
     145                                <input type="radio" name="bp-admin[bp_restrict_group_creation]"<?php checked( '1', get_site_option( 'bp_restrict_group_creation', '0' ) ); ?>id="bp-restrict-group-creation" value="1" /> <?php _e( 'Yes', 'buddypress' ) ?> &nbsp;
     146                                <input type="radio" name="bp-admin[bp_restrict_group_creation]"<?php checked( '0', get_site_option( 'bp_restrict_group_creation', '0' ) ); ?>id="bp-restrict-group-creation" value="0" /> <?php _e( 'No', 'buddypress' ) ?>
    135147                            </td>
    136148                        </tr>
  • trunk/bp-groups/bp-groups-actions.php

    r4236 r4338  
    1919    if ( !is_user_logged_in() )
    2020        return false;
     21
     22    if ( !bp_user_can_create_groups() ) {
     23        bp_core_add_message( __( 'Sorry, you are not allowed to create groups.', 'buddypress' ), 'error' );
     24        bp_core_redirect( trailingslashit( bp_get_root_domain() . '/' . bp_get_groups_root_slug() ) );
     25    }
    2126
    2227    // Make sure creation steps are in the right order
  • trunk/bp-groups/bp-groups-template.php

    r4335 r4338  
    17341734 **/
    17351735
     1736/**
     1737 * Determine if the current logged in user can create groups.
     1738 *
     1739 * @package BuddyPress Groups
     1740 * @since BuddyPress 1.3
     1741 *
     1742 * @uses apply_filters() To call 'bp_user_can_create_groups'.
     1743 * @uses get_site_option() To retrieve value of 'bp_restrict_group_creation'. Defaults to 0.
     1744 * @uses is_super_admin() To determine if current user if super admin.
     1745 *
     1746 * @return bool True if user can create groups. False otherwise.
     1747 */
     1748function bp_user_can_create_groups() {
     1749    // Super admin can always create groups
     1750    if ( is_super_admin() )
     1751        return true;
     1752
     1753    // Get group creation option, default to 0 (allowed)
     1754    $restricted = (int) get_site_option( 'bp_restrict_group_creation', 0 );
     1755
     1756    // Allow by default
     1757    $can_create = true;
     1758
     1759    // Are regular users restricted?
     1760    if ( $restricted )
     1761        $can_create = false;
     1762
     1763    return apply_filters( 'bp_user_can_create_groups', $can_create, $restricted );
     1764}
     1765
    17361766function bp_group_creation_tabs() {
    17371767    global $bp;
  • trunk/bp-themes/bp-default/groups/index.php

    r4270 r4338  
    1919        <form action="" method="post" id="groups-directory-form" class="dir-form">
    2020
    21             <h3><?php _e( 'Groups Directory', 'buddypress' ); ?><?php if ( is_user_logged_in() ) : ?> &nbsp;<a class="button" href="<?php echo trailingslashit( bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create' ); ?>"><?php _e( 'Create a Group', 'buddypress' ); ?></a><?php endif; ?></h3>
     21            <h3><?php _e( 'Groups Directory', 'buddypress' ); ?><?php if ( is_user_logged_in() && bp_user_can_create_groups() ) : ?> &nbsp;<a class="button" href="<?php echo trailingslashit( bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create' ); ?>"><?php _e( 'Create a Group', 'buddypress' ); ?></a><?php endif; ?></h3>
    2222
    2323            <div id="group-dir-search" class="dir-search" role="search">
     
    2626
    2727            </div><!-- #group-dir-search -->
     28
     29            <?php do_action( 'template_notices' ); ?>
    2830
    2931            <div class="item-list-tabs" role="navigation">
Note: See TracChangeset for help on using the changeset viewer.