bp_group_is_user_banned( BP_Groups_Group|bool $group = false, int $user_id )

Check if a user is banned from a group.


Description Description

If this function is invoked inside the groups template loop, then we check $groups_template->group->is_banned instead of using groups_is_user_banned() and making another SQL query.

In BuddyPress 2.1, to standardize this function, we are defaulting the return value to a boolean. In previous versions, using this function would return either a string of the integer (0 or 1) or null if a result couldn’t be found from the database. If the logged-in user had the ‘bp_moderate’ capability, the return value would be boolean false.


Parameters Parameters

$group

(Optional) Group to check if user is banned.

Default value: false

$user_id

(Required) The user ID to check.


Top ↑

Return Return

(bool) True if user is banned. False if user isn't banned.


Top ↑

Source Source

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

function bp_group_is_user_banned( $group = false, $user_id = 0 ) {
	global $groups_template;

	// Site admins always have access.
	if ( bp_current_user_can( 'bp_moderate' ) ) {
		return false;
	}

	// Check groups loop first
	// @see BP_Groups_Group::get_group_extras().
	if ( ! empty( $groups_template->in_the_loop ) && isset( $groups_template->group->is_banned ) ) {
		$retval = $groups_template->group->is_banned;

	// Not in loop.
	} else {
		// Default to not banned.
		$retval = false;

		if ( empty( $group ) ) {
			$group = $groups_template->group;
		}

		if ( empty( $user_id ) ) {
			$user_id = bp_loggedin_user_id();
		}

		if ( ! empty( $user_id ) && ! empty( $group->id ) ) {
			$retval = groups_is_user_banned( $user_id, $group->id );
		}
	}

	/**
	 * Filters whether current user has been banned from current group in loop.
	 *
	 * @since 1.5.0
	 * @since 2.5.0 Added the `$group` parameter.
	 *
	 * @param bool   $is_invited If user has been from current group.
	 * @param object $group      Group object.
	 */
	return (bool) apply_filters( 'bp_group_is_user_banned', $retval, $group );
}

Top ↑

Changelog Changelog

Changelog
Version Description
1.5.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.