bp_get_parent_group_id( int|bool $group_id = false, int|bool $user_id = false, string $context = 'normal' )

Get the parent group ID for a specific group.

Description

To return the parent group regardless of visibility, leave the $user_id parameter empty. To return the parent only when visible to a specific user, specify a $user_id.

Parameters

$group_id

(int|bool) (Optional) ID of the group.

Default value: false

$user_id

(int|bool) (Optional) ID of a user to check group visibility for.

Default value: false

$context

(string) (Optional) See bp_include_group_by_context() for description.

Default value: 'normal'

Return

(int) ID of parent group.

Source

File: bp-groups/bp-groups-template.php

function bp_get_parent_group_id( $group_id = false, $user_id = false, $context = 'normal' ) {
	if ( false === $group_id ) {
		$group_id = bp_get_current_group_id();
		if ( ! $group_id ) {
			// If we can't resolve the group_id, don't proceed.
			return 0;
		}
	}

	$group     = groups_get_group( $group_id );
	$parent_id = $group->parent_id;

	// If the user is specified, is the parent group visible to that user?
	// @TODO: This could make use of group visibility when available.
	if ( false !== $user_id && ! bp_user_can( $user_id, 'bp_moderate' ) ) {
		$parent_group = groups_get_group( $parent_id );
		if ( ! bp_include_group_by_context( $parent_group, $user_id, $context ) ) {
			$parent_id = 0;
		}
	}

	return (int) $parent_id;
}

Changelog

Changelog
Version Description
BuddyBoss 1.0.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.