bp_groups_set_group_type( int $group_id, string|array $group_type, bool $append = false )
Set type for a group.
Description Description
Parameters Parameters
- $group_id
-
(Required) ID of the group.
- $group_type
-
(Required) Group type or array of group types to set.
- $append
-
(Optional) True to append this to existing types for group, false to replace. Default: false.
Default value: false
Return Return
(false|array) $retval See bp_set_object_terms().
Source Source
File: bp-groups/bp-groups-functions.php
function bp_groups_set_group_type( $group_id, $group_type, $append = false ) {
// Pass an empty group type to remove group's type.
if ( ! empty( $group_type ) && is_string( $group_type ) && ! bp_groups_get_group_type_object( $group_type ) ) {
return false;
}
// Cast as array.
$group_type = (array) $group_type;
// Validate group types.
foreach ( $group_type as $type ) {
// Remove any invalid group types.
if ( is_null( bp_groups_get_group_type_object( $type ) ) ) {
unset( $group_type[ $type ] );
}
}
$retval = bp_set_object_terms( $group_id, $group_type, 'bp_group_type', $append );
// Bust the cache if the type has been updated.
if ( ! is_wp_error( $retval ) ) {
wp_cache_delete( $group_id, 'bp_groups_group_type' );
/**
* Fires just after a group type has been changed.
*
* @since 2.6.0
*
* @param int $group_id ID of the group whose group type has been updated.
* @param string|array $group_type Group type or array of group types.
* @param bool $append Whether the type is being appended to existing types.
*/
do_action( 'bp_groups_set_group_type', $group_id, $group_type, $append );
}
return $retval;
}
Changelog Changelog
| Version | Description |
|---|---|
| 2.7.0 | $group_type parameter also accepts an array of group types now. |
| 2.6.0 | Introduced. |