[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

User API: WP_User class

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

Defines 1 class

WP_User:: (28 methods):
  __construct()
  init()
  get_data_by()
  __isset()
  __get()
  __set()
  __unset()
  exists()
  get()
  has_prop()
  to_array()
  __call()
  _init_caps()
  get_role_caps()
  add_role()
  remove_role()
  set_role()
  level_reduction()
  update_user_level_from_caps()
  add_cap()
  remove_cap()
  remove_all_caps()
  has_cap()
  translate_level_to_cap()
  for_blog()
  for_site()
  get_site_id()
  get_caps_data()


Class: WP_User  - X-Ref

Core class used to implement the WP_User object.

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

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
Returns only the main user fields.

since: 3.3.0
since: 4.4.0 Added 'ID' as an alias of 'id' for the `$field` parameter.
return: object|false Raw user object.
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.

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

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

since: 3.3.0
return: mixed Value of the given user meta key (if set). If `$key` is 'id', the user ID.
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
Determines whether the user exists in the database.

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

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

Retrieves from the users and usermeta table.

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

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

Consults the users and usermeta tables.

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

to_array()   X-Ref
Returns an array representation.

since: 3.5.0
return: array Array representation.

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

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

_init_caps( $cap_key = '' )   X-Ref
Sets 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
used.

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.

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

add_role( $role )   X-Ref
Adds 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
Removes role from user.

since: 2.0.0
param: string $role Role name.

set_role( $role )   X-Ref
Sets 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
Chooses 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
value.

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

update_user_level_from_caps()   X-Ref
Updates 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
Adds 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
Removes capability from user.

since: 2.0.0
param: string $cap Capability name.

remove_all_caps()   X-Ref
Removes 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.

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

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

Prepends 'level_' to level number.

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

for_blog( $blog_id = '' )   X-Ref
Sets 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.

since: 4.9.0
return: int Site ID.

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

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



Generated: Fri Apr 19 01:00:02 2024 Cross-referenced by PHPXref 0.7.1