/**
 * Render the Group Type metabox.
 *
 * @since 2.6.0
 *
 * @param BP_Groups_Group|null $user The BP_Groups_Group object corresponding to the group being edited.
 */
function bp_groups_admin_edit_metabox_group_type(BP_Groups_Group $group = null)
{
    // Bail if no group ID.
    if (empty($group->id)) {
        return;
    }
    $types = bp_groups_get_group_types(array(), 'objects');
    $current_types = (array) bp_groups_get_group_type($group->id, false);
    $backend_only = bp_groups_get_group_types(array('show_in_create_screen' => false));
    ?>

	<label for="bp-groups-group-type" class="screen-reader-text"><?php 
    /* translators: accessibility text */
    esc_html_e('Select group type', 'buddypress');
    ?>
</label>

	<ul class="categorychecklist form-no-clear">
		<?php 
    foreach ($types as $type) {
        ?>
			<li>
				<label class="selectit"><input value="<?php 
        echo esc_attr($type->name);
        ?>
" name="bp-groups-group-type[]" type="checkbox" <?php 
        checked(true, in_array($type->name, $current_types));
        ?>
>
					<?php 
        echo esc_html($type->labels['singular_name']);
        if (in_array($type->name, $backend_only)) {
            printf(' <span class="description">%s</span>', esc_html__('(Not available on the frontend)', 'buddypress'));
        }
        ?>

				</label>
			</li>

		<?php 
    }
    ?>

	</ul>

	<?php 
    wp_nonce_field('bp-group-type-change-' . $group->id, 'bp-group-type-nonce');
}
/**
 * Locate a custom group front template if it exists.
 *
 * @since 2.4.0
 * @since 2.6.0 Adds the Group Type to the front template hierarchy.
 *
 * @param  BP_Groups_Group|null $group Optional. Falls back to current group if not passed.
 * @return string|bool                 Path to front template on success; boolean false on failure.
 */
function bp_groups_get_front_template($group = null)
{
    if (!is_a($group, 'BP_Groups_Group')) {
        $group = groups_get_current_group();
    }
    if (!isset($group->id)) {
        return false;
    }
    if (isset($group->front_template)) {
        return $group->front_template;
    }
    $template_names = array('groups/single/front-id-' . sanitize_file_name($group->id) . '.php', 'groups/single/front-slug-' . sanitize_file_name($group->slug) . '.php');
    if (bp_groups_get_group_types()) {
        $group_type = bp_groups_get_group_type($group->id);
        if (!$group_type) {
            $group_type = 'none';
        }
        $template_names[] = 'groups/single/front-group-type-' . sanitize_file_name($group_type) . '.php';
    }
    $template_names = array_merge($template_names, array('groups/single/front-status-' . sanitize_file_name($group->status) . '.php', 'groups/single/front.php'));
    /**
     * Filters the hierarchy of group front templates corresponding to a specific group.
     *
     * @since 2.4.0
     * @since 2.5.0 Added the `$group` parameter.
     *
     * @param array  $template_names Array of template paths.
     * @param object $group          Group object.
     */
    return bp_locate_template(apply_filters('bp_groups_get_front_template', $template_names, $group), false, true);
}
_e('This group will not be listed in the groups directory or search results.', 'buddypress');
?>
</li>
			<li><?php 
_e('Group content and activity will only be visible to members of the group.', 'buddypress');
?>
</li>
		</ul>

	</div>

</fieldset>

<?php 
// Group type selection
if ($group_types = bp_groups_get_group_types(array('show_in_create_screen' => true), 'objects')) {
    ?>

	<fieldset class="group-create-types">
		<legend><?php 
    _e('Group Types', 'buddypress');
    ?>
</legend>

		<p><?php 
    _e('Select the types this group should be a part of.', 'buddypress');
    ?>
</p>

		<?php 
    foreach ($group_types as $type) {
    /**
     * Markup for the Group Type bulk change select.
     *
     * @since 2.7.0
     *
     * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
     */
    public function add_group_type_bulk_change_select($which)
    {
        // `$which` is only passed in WordPress 4.6+. Avoid duplicating controls in earlier versions.
        static $displayed = false;
        if (version_compare(bp_get_major_wp_version(), '4.6', '<') && $displayed) {
            return;
        }
        $displayed = true;
        $id_name = 'bottom' === $which ? 'bp_change_type2' : 'bp_change_type';
        $types = bp_groups_get_group_types(array(), 'objects');
        ?>
		<div class="alignleft actions">
			<label class="screen-reader-text" for="<?php 
        echo $id_name;
        ?>
"><?php 
        _e('Change group type to&hellip;', 'buddypress');
        ?>
</label>
			<select name="<?php 
        echo $id_name;
        ?>
" id="<?php 
        echo $id_name;
        ?>
" style="display:inline-block;float:none;">
				<option value=""><?php 
        _e('Change group type to&hellip;', 'buddypress');
        ?>
</option>

				<?php 
        foreach ($types as $type) {
            ?>

					<option value="<?php 
            echo esc_attr($type->name);
            ?>
"><?php 
            echo esc_html($type->labels['singular_name']);
            ?>
</option>

				<?php 
        }
        ?>

				<option value="remove_group_type"><?php 
        _e('No Group Type', 'buddypress');
        ?>
</option>

			</select>
			<?php 
        wp_nonce_field('bp-bulk-groups-change-type-' . bp_loggedin_user_id(), 'bp-bulk-groups-change-type-nonce');
        submit_button(__('Change', 'buddypress'), 'button', 'bp_change_group_type', false);
        ?>
		</div>
		<?php 
    }
/**
 * Retrieve a group type object by name.
 *
 * @since 2.6.0
 *
 * @param string $group_type The name of the group type.
 * @return object A group type object.
 */
function bp_groups_get_group_type_object($group_type)
{
    $types = bp_groups_get_group_types(array(), 'objects');
    if (empty($types[$group_type])) {
        return null;
    }
    return $types[$group_type];
}
Example #6
0
 public function test_bp_groups_get_group_types_filter()
 {
     bp_groups_register_group_type('foo');
     bp_groups_register_group_type('bar');
     $types = bp_groups_get_group_types(array('name' => 'bar'));
     $this->assertEqualSets(array('bar'), $types);
 }
/**
 * Handle the display of a group's admin/group-settings page.
 *
 * @since 1.0.0
 */
function groups_screen_group_admin_settings()
{
    if ('group-settings' != bp_get_group_current_admin_tab()) {
        return false;
    }
    if (!bp_is_item_admin()) {
        return false;
    }
    $bp = buddypress();
    // If the edit form has been submitted, save the edited details.
    if (isset($_POST['save'])) {
        $enable_forum = isset($_POST['group-show-forum']) ? 1 : 0;
        // Checked against a whitelist for security.
        /** This filter is documented in bp-groups/bp-groups-admin.php */
        $allowed_status = apply_filters('groups_allowed_status', array('public', 'private', 'hidden'));
        $status = in_array($_POST['group-status'], (array) $allowed_status) ? $_POST['group-status'] : 'public';
        // Checked against a whitelist for security.
        /** This filter is documented in bp-groups/bp-groups-admin.php */
        $allowed_invite_status = apply_filters('groups_allowed_invite_status', array('members', 'mods', 'admins'));
        $invite_status = isset($_POST['group-invite-status']) && in_array($_POST['group-invite-status'], (array) $allowed_invite_status) ? $_POST['group-invite-status'] : 'members';
        // Check the nonce.
        if (!check_admin_referer('groups_edit_group_settings')) {
            return false;
        }
        /*
         * Save group types.
         *
         * Ensure we keep types that have 'show_in_create_screen' set to false.
         */
        $current_types = bp_groups_get_group_type(bp_get_current_group_id(), false);
        $current_types = array_intersect(bp_groups_get_group_types(array('show_in_create_screen' => false)), (array) $current_types);
        if (isset($_POST['group-types'])) {
            $current_types = array_merge($current_types, $_POST['group-types']);
            // Set group types.
            bp_groups_set_group_type(bp_get_current_group_id(), $current_types);
            // No group types checked, so this means we want to wipe out all group types.
        } else {
            /*
             * Passing a blank string will wipe out all types for the group.
             *
             * Ensure we keep types that have 'show_in_create_screen' set to false.
             */
            $current_types = empty($current_types) ? '' : $current_types;
            // Set group types.
            bp_groups_set_group_type(bp_get_current_group_id(), $current_types);
        }
        if (!groups_edit_group_settings($_POST['group-id'], $enable_forum, $status, $invite_status)) {
            bp_core_add_message(__('There was an error updating group settings. Please try again.', 'buddypress'), 'error');
        } else {
            bp_core_add_message(__('Group settings were successfully updated.', 'buddypress'));
        }
        /**
         * Fires before the redirect if a group settings has been edited and saved.
         *
         * @since 1.0.0
         *
         * @param int $id ID of the group that was edited.
         */
        do_action('groups_group_settings_edited', $bp->groups->current_group->id);
        bp_core_redirect(bp_get_group_permalink(groups_get_current_group()) . 'admin/group-settings/');
    }
    /**
     * Fires before the loading of the group admin/group-settings page template.
     *
     * @since 1.0.0
     *
     * @param int $id ID of the group that is being displayed.
     */
    do_action('groups_screen_group_admin_settings', $bp->groups->current_group->id);
    /**
     * Filters the template to load for a group's admin/group-settings page.
     *
     * @since 1.0.0
     *
     * @param string $value Path to a group's admin/group-settings template.
     */
    bp_core_load_template(apply_filters('groups_template_group_admin_settings', 'groups/single/home'));
}