Skip to content
This repository was archived by the owner on Jul 1, 2025. It is now read-only.

Latest commit

 

History

History
416 lines (213 loc) · 10 KB

File metadata and controls

416 lines (213 loc) · 10 KB

User

WP_User wrapper class. This class wrap a WP_User object and give them some helpers and some features like get_avatar_url, accessor like get_login, get_page_url, etc...

Example

	$user = new \WPS\User($wp_user);
$avatarUrl = $user->avatar_url;

Author : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com

Constructor

Construct the object using the passed wp_user

Parameters

Name Type Description Status Default
$wp_user { WP_User } The wordpress user object to encapsulate required

Example

	$wpsUser = new \WPS\User($wp_user);

Author : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com

Public

Public properties

$id

The user id

Type : { Integer }

Public

Default : null

$login

The user login

Type : { String }

Public

Default : null

$password

The user password

Type : { String }

Public

Default : null

$nicename

The user nicename

Type : { String }

Public

Default : null

$email

The user email

Type : { String }

Public

Default : null

$firstname

The user firstname

Type : { String }

Public

Default : null

$lastname

The user lastname

Type : { String }

Public

Default : null

$url

The user website url

Type : { String }

Public

Default : null

$registered

The user registration datetime

Type : { String }

Public

Default : null

$activation_key

The user activation key

Type : { String }

Public

Default : null

$status

The user status

Type : { String }

Public

Default : null

$display_name

The user display name

Type : { String }

Public

Default : null

$capabilities

The user capabilities

Type : { Array }

Public

Default : []

$all_capabilities

All the user capabilities

Type : { Array }

Public

Default : []

$roles

The user roles

Type : { Array }

Public

Default : []

Public methods

__get

Properties accessor

Author : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com

Public

get_page_url

Get the page url of the author

Return { String } The page url of the author

Example

	$pageUrl = $user->page_url;

Author : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com

Public

get_avatar_url

Get the avatar url for this user

Return { String } The avatar url

Example

	$avatarUrl = $user->avatar_url;

Author : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com

Public

avatar_url

Get the avatar url for this user using some arguments like size

Parameters

Name Type Description Status Default
$size { Integer } The size wanted for the avatar optional 96
$default { String } The default avatar to return if none exists optional "gravatar_default"

Return { String } The avatar url

Example

	

Author : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com

Public

exists

Determine whether the user exists in the database. It actually tests !empty(ID), which will normally indicate that the user record was in the database at some stage. It does not access the database.

Return { Boolean } true if user exists, false otherwise.

Author : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com

Public

get

Retrieve the value of a property or meta key from the users and usermeta tables.

Parameters

Name Type Description Status Default
$key { String } property required

Return { Mixed } String of the property filtered if single value, or array if value is stored as a serialized array

Author : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com

Public

has_prop

Determine whether a property or meta key is set from the users and usermeta tables.

Parameters

Name Type Description Status Default
$key { String } property required

Return { Boolean } true if user has property, false otherwise

Author : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com

Public

add_role

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

Parameters

Name Type Description Status Default
$role { String } Role name required

Author : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com

Public

remove_role

Remove role from user.

Parameters

Name Type Description Status Default
$role { String } Role name required

Author : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com

Public

set_role

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.

Parameters

Name Type Description Status Default
$role { String } Role name required

Author : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com

Public

add_cap

Add capability and grant or deny access to capability.

Parameters

Name Type Description Status Default
$cap { String } Capability name required
$grant { Boolean } whether to grant capability to user. Default to true. required

Author : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com

Public

remove_cap

Remove capability from user

Parameters

Name Type Description Status Default
$cap { String } Capability name required

Author : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com

Public

remove_all_caps

Remove all of the capabilities of the user.

Author : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com

Public

has_cap

Whether user has capability or role name.

Parameters

Name Type Description Status Default
$cap { String } capability or role name to search required

Return { Boolean } true if user has capability, false if they do not have the capability

Author : Olivier Bossel olivier.bossel@gmail.com https://olivierbossel.com

Public