[ Index ] |
PHP Cross Reference of WordPress |
[Source view] [Print] [Project Stats]
User API: WP_User class
File Size: | 907 lines (23 kb) |
Included or required: | 0 times |
Referenced: | 0 times |
Includes or requires: | 0 files |
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()
__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. since: 2.0.0 |
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. since: 3.3.0 |
get_data_by( $field, $value ) X-Ref |
Returns only the main user fields. 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. since: 3.3.0 since: 4.4.0 Added 'ID' as an alias of 'id' for the `$field` parameter. |
__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. param: string $key User meta key to check if set. since: 3.3.0 |
__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. param: string $key User meta key to retrieve. since: 3.3.0 |
__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. since: 3.3.0 |
__unset( $key ) X-Ref |
Magic method for unsetting a certain custom field. param: string $key User meta key to unset. since: 4.4.0 |
exists() X-Ref |
Determines 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 |
Retrieves the value of a property or meta key. Retrieves from the users and usermeta table. return: mixed param: string $key Property since: 3.3.0 |
has_prop( $key ) X-Ref |
Determines whether a property or meta key is set. Consults the users and usermeta tables. return: bool param: string $key Property. since: 3.3.0 |
to_array() X-Ref |
Returns 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. param: string $name Method to call. param: array $arguments Arguments to pass when calling. since: 4.3.0 |
_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 since: 2.1.0 |
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 |
Adds role to user. Updates the user's meta data option with capabilities and roles. param: string $role Role name. since: 2.0.0 |
remove_role( $role ) X-Ref |
Removes role from user. param: string $role Role name. since: 2.0.0 |
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. since: 2.0.0 |
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. return: int Max Level. param: int $max Max level of user. param: string $item Level capability name. since: 2.0.0 |
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. param: string $cap Capability name. param: bool $grant Whether to grant capability to user. since: 2.0.0 |
remove_cap( $cap ) X-Ref |
Removes capability from user. param: string $cap Capability name. since: 2.0.0 |
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. 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. since: 2.0.0 since: 5.3.0 Formalized the existing and already documented `...$args` parameter |
translate_level_to_cap( $level ) X-Ref |
Converts numeric level to level capability name. Prepends 'level_' to level number. return: string param: int $level Level number, 1 to 10. since: 2.0.0 |
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. since: 3.0.0 |
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. since: 4.9.0 |
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: Thu Nov 21 01:00:03 2024 | Cross-referenced by PHPXref 0.7.1 |