bp_user_can( int $user_id, string $capability, array|int $args = array() )

Check whether the specified user has a given capability on a given site.


Description Description


Parameters Parameters

$user_id

(Required)

$capability

(Required) Capability or role name.

$args

(Optional) Array of extra arguments applicable to the capability check.

  • 'site_id'
    (int) Optional. Site ID. Defaults to the BP root blog.
  • 'a,...'
    (mixed) Optional. Extra arguments applicable to the capability check.

Default value: array()


Top ↑

Return Return

(bool) True if the user has the cap for the given parameters.


Top ↑

Source Source

File: bp-core/bp-core-caps.php

function bp_user_can( $user_id, $capability, $args = array() ) {
	$site_id = bp_get_root_blog_id();

	// Get the site ID if set, but don't pass along to user_can().
	if ( isset( $args['site_id'] ) ) {
		$site_id = (int) $args['site_id'];
		unset( $args['site_id'] );
	}

	$switched = is_multisite() ? switch_to_blog( $site_id ) : false;
	$retval   = call_user_func_array( 'user_can', array( $user_id, $capability, $args ) );

	/**
	 * Filters whether or not the specified user has a given capability on a given site.
	 *
	 * @since 2.7.0
	 *
	 * @param bool   $retval     Whether or not the current user has the capability.
	 * @param int    $user_id
	 * @param string $capability The capability being checked for.
	 * @param int    $site_id    Site ID. Defaults to the BP root blog.
	 * @param array  $args       Array of extra arguments passed.
	 */
	$retval = (bool) apply_filters( 'bp_user_can', $retval, $user_id, $capability, $site_id, $args );

	if ( $switched ) {
		restore_current_blog();
	}

	return $retval;
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.7.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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