[ Index ]

PHP Cross Reference of WordPress




/wp-includes/ -> class-wp-user.php (summary)

User API: WP_User class

File Size: 882 lines (22 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

WP_User:: (28 methods):

Class: WP_User  - X-Ref

Core class used to implement the WP_User object.

__construct( $id = 0, $name = '', $site_id = '' )   X-Ref

Retrieves the userdata and passes it to WP_User::init().

since: 2.0.0
param: int|string|stdClass|WP_User $id      User's ID, a WP_User object, or a user object from the DB.
param: string                      $name    Optional. User's username
param: int                         $site_id Optional Site ID, defaults to current site.

init( $data, $site_id = '' )   X-Ref
Sets up object properties, including capabilities.

since: 3.3.0
param: object $data    User DB row object.
param: int    $site_id Optional. The site ID to initialize for.

get_data_by( $field, $value )   X-Ref
Return only the main user fields

return: object|false Raw user object
since: 3.3.0
since: 4.4.0 Added 'ID' as an alias of 'id' for the `$field` parameter.
param: string     $field The field to query against: 'id', 'ID', 'slug', 'email' or 'login'.
param: string|int $value The field value

__isset( $key )   X-Ref
Magic method for checking the existence of a certain custom field.

return: bool Whether the given user meta key is set.
since: 3.3.0
param: string $key User meta key to check if set.

__get( $key )   X-Ref
Magic method for accessing custom fields.

return: mixed Value of the given user meta key (if set). If `$key` is 'id', the user ID.
since: 3.3.0
param: string $key User meta key to retrieve.

__set( $key, $value )   X-Ref
Magic method for setting custom user fields.

This method does not update custom fields in the database. It only stores
the value on the WP_User instance.

since: 3.3.0
param: string $key   User meta key.
param: mixed  $value User meta value.

__unset( $key )   X-Ref
Magic method for unsetting a certain custom field.

since: 4.4.0
param: string $key User meta key to unset.

exists()   X-Ref
Determine whether the user exists in the database.

return: bool True if user exists in the database, false if not.
since: 3.4.0

get( $key )   X-Ref
Retrieve the value of a property or meta key.

Retrieves from the users and usermeta table.

return: mixed
since: 3.3.0
param: string $key Property

has_prop( $key )   X-Ref
Determine whether a property or meta key is set

Consults the users and usermeta tables.

return: bool
since: 3.3.0
param: string $key Property

to_array()   X-Ref
Return an array representation.

return: array Array representation.
since: 3.5.0

__call( $name, $arguments )   X-Ref
Makes private/protected methods readable for backward compatibility.

return: mixed|false Return value of the callback, false otherwise.
since: 4.3.0
param: string $name      Method to call.
param: array  $arguments Arguments to pass when calling.

_init_caps( $cap_key = '' )   X-Ref
Set up capability object properties.

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

since: 2.1.0
param: string $cap_key Optional capability key

get_role_caps()   X-Ref
Retrieves all of the capabilities of the user's roles, and merges them with
individual user capabilities.

All of the capabilities of the user's roles are merged with the user's individual
capabilities. This means that the user can be denied specific capabilities that
their role might have, but the user is specifically denied.

return: bool[] Array of key/value pairs where keys represent a capability name
since: 2.0.0

add_role( $role )   X-Ref
Add role to user.

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

since: 2.0.0
param: string $role Role name.

remove_role( $role )   X-Ref
Remove role from user.

since: 2.0.0
param: string $role Role name.

set_role( $role )   X-Ref
Set the role of the user.

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
param: string $role Role name.

level_reduction( $max, $item )   X-Ref
Choose the maximum level the user has.

Will compare the level from the $item parameter against the $max
parameter. If the item is incorrect, then just the $max parameter value
will be returned.

Used to get the max level based on the capabilities the user has. This
is also based on roles, so if the user is assigned the Administrator role
then the capability 'level_10' will exist and the user will get that

return: int Max Level.
since: 2.0.0
param: int    $max  Max level of user.
param: string $item Level capability name.

update_user_level_from_caps()   X-Ref
Update the maximum user level for the user.

Updates the 'user_level' user metadata (includes prefix that is the
database table prefix) with the maximum user level. Gets the value from
the all of the capabilities that the user has.

since: 2.0.0

add_cap( $cap, $grant = true )   X-Ref
Add capability and grant or deny access to capability.

since: 2.0.0
param: string $cap   Capability name.
param: bool   $grant Whether to grant capability to user.

remove_cap( $cap )   X-Ref
Remove capability from user.

since: 2.0.0
param: string $cap Capability name.

remove_all_caps()   X-Ref
Remove all of the capabilities of the user.

since: 2.1.0

has_cap( $cap, ...$args )   X-Ref
Returns whether the user has the specified capability.

This function also accepts an ID of an object to check against if the capability is a meta capability. Meta
capabilities such as `edit_post` and `edit_user` are capabilities used by the `map_meta_cap()` function to
map to primitive capabilities that a user or role has, such as `edit_posts` and `edit_others_posts`.

Example usage:

$user->has_cap( 'edit_posts' );
$user->has_cap( 'edit_post', $post->ID );
$user->has_cap( 'edit_post_meta', $post->ID, $meta_key );

While checking against a role in place of a capability is supported in part, this practice is discouraged as it
may produce unreliable results.

return: bool Whether the user has the given capability, or, if an object ID is passed, whether the user has
since: 2.0.0
since: 5.3.0 Formalized the existing and already documented `...$args` parameter
param: string $cap     Capability name.
param: mixed  ...$args Optional further parameters, typically starting with an object ID.

translate_level_to_cap( $level )   X-Ref
Convert numeric level to level capability name.

Prepends 'level_' to level number.

return: string
since: 2.0.0
param: int $level Level number, 1 to 10.

for_blog( $blog_id = '' )   X-Ref
Set the site to operate on. Defaults to the current site.

since: 3.0.0
param: int $blog_id Optional. Site ID, defaults to current site.

for_site( $site_id = '' )   X-Ref
Sets the site to operate on. Defaults to the current site.

since: 4.9.0
param: int $site_id Site ID to initialize user capabilities for. Default is the current site.

get_site_id()   X-Ref
Gets the ID of the site for which the user's capabilities are currently initialized.

return: int Site ID.
since: 4.9.0

get_caps_data()   X-Ref
Gets the available user capabilities data.

return: bool[] List of capabilities keyed by the capability name,
since: 4.9.0

Generated: Fri Nov 27 01:00:04 2020 Cross-referenced by PHPXref 0.7.1