[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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

User API: WP_User class

File Size: 912 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().

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.

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.

param: string     $field The field to query against: Accepts 'id', 'ID', 'slug', 'email' or 'login'.
param: string|int $value The field value.
return: object|false Raw user object.

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

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

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

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

__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.

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

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

param: string $key User meta key to unset.

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

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.

param: string $key Property
return: mixed

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

Consults the users and usermeta tables.

param: string $key Property.
return: bool

to_array()   X-Ref
Returns an array representation.

return: array Array representation.

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

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

_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.

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

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

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

param: string $role Role name.

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

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.

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.

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

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.


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

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

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

param: string $cap Capability name.

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


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.

param: string $cap     Capability name.
param: mixed  ...$args Optional further parameters, typically starting with an object ID.
return: bool Whether the user has the given capability, or, if an object ID is passed, whether the user has

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

Prepends 'level_' to level number.

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

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

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.

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.

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

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



Generated : Thu Nov 21 08:20:01 2024 Cross-referenced by PHPXref