BackPress User class.

since 2.0.0
package BackPress
subpackage User

 Methods

BP_User()

BP_User($id, $name = ''

Parameters

$id

$name

PHP4 Constructor - Sets up the object properties.

__construct(integer|string $id, integer $name = '') : \BP_User

Retrieves the userdata and then assigns all of the data keys to direct properties of the object. Calls BP_User::_init_caps() after setting up the object's user data properties.

since 2.0.0
access public

Parameters

$id

integerstring

User's ID or username

$name

integer

Optional. User's username

Returns

\BP_User

Setup capability object properties.

_init_caps() 

Will set the value for the 'cap_key' property to current database table prefix, followed by 'capabilities'. Will then check to see if the property matching the 'cap_key' exists and is an array. If so, it will be used.

since 2.1.0
access protected

Add capability and grant or deny access to capability.

add_cap(string $cap, boolean $grant = true
since 2.0.0
access public

Parameters

$cap

string

Capability name.

$grant

boolean

Whether to grant capability to user.

Add role to user.

add_role(string $role) 

Updates the user's meta data option with capabilities and roles.

since 2.0.0
access public

Parameters

$role

string

Role name.

Retrieve all of the role capabilities and merge with individual capabilities.

get_role_caps() 

All of the capabilities of the roles the user belongs to are merged with the users individual roles. This also means that the user can be denied specific roles that their role might have, but the specific user isn't granted permission to.

since 2.0.0
uses
access public

Whether user has capability or role name.

has_cap(string|integer $cap) : boolean

This is useful for looking up whether the user has a specific role assigned to the user. The second optional parameter can also be used to check for capabilities against a specfic post.

since 2.0.0
access public

Parameters

$cap

stringinteger

Capability or role name to search.

Returns

booleanTrue, if user has capability; false, if user does not have capability.

Remove all of the capabilities of the user.

remove_all_caps() 
since 2.1.0
access public

Remove capability from user.

remove_cap(string $cap) 
since 2.0.0
access public

Parameters

$cap

string

Capability name.

Remove role from user.

remove_role(string $role) 
since 2.0.0
access public

Parameters

$role

string

Role name.

Set the role of the user.

set_role(string $role) 

This will remove the previous roles of the user and assign the user the new one. You can set the role to an empty string and it will remove all of the roles from the user.

since 2.0.0
access public

Parameters

$role

string

Role name.

Convert numeric level to level capability name.

translate_level_to_cap(integer $level) : string

Prepends 'level_' to level number.

since 2.0.0
access public

Parameters

$level

integer

Level number, 1 to 10.

Returns

string

update_user()

update_user() 

 Properties

 

The user's ID.

$ID : integer

Default

0
since 2.1.0
access public
 

All capabilities the user has, including individual and role based.

$allcaps : array

Default

array()
since 2.0.0
access public
 

User metadata option name.

$cap_key : string

Default

since 2.0.0
access public
 

The individual capabilities the user has been given.

$caps : array

Default

array()
since 2.0.0
access public
 

User data container.

$data : array

Default

This will be set as properties of the object.

since 2.0.0
access private
 

First name of the user.

$first_name : string

Default

''

Created to prevent notices.

since 2.7.0
access public
 

The deprecated user's ID.

$id : integer

Default

0
since 2.0.0
access public
deprecated Use BP_User::$ID
see
 

Last name of the user.

$last_name : string

Default

''

Created to prevent notices.

since 2.7.0
access public
 

The roles the user is part of.

$roles : array

Default

array()
since 2.0.0
access public