PHP Class WPDKUsers

## Overview This is a singleton class for manage all WordPress users and adding a several extension for control, checking, login and more. ### User meta See the WPDKUserMeta
Author: =undo= ([email protected])
Show file Open project: wpxtreme/wpdk Class Usage Examples

Public Methods

Method Description
admin_print_styles_users_php ( ) Fires when styles are printed for a specific admin page based on $hook_suffix.
authenticate ( string $email, string $password ) : integer | boolean Try to authenticate an user without log-in in the system. This method is very different by signIn().
avatar ( integer $id_user = null, integer $size = 40 ) : WPDKHTMLTagImg | boolean Return an instance of WPDKHTMLTagImg class
create ( string $first_name, string $last_name, string $email, boolean | string $password = false, boolean $enabled = false, string $role = 'subscriber' ) : integer | WP_Error Create a WordPress user and return the user id on success, WP_Error otherwise.
createWithArgs ( array $args ) : integer | WP_Error Create a WordPress user and return the user id on success, WP_Error otherwise.
deleteUsersMetaWithKey ( string $key ) Delete the user meta with $key from all users.
delete_user ( integer $id_user ) The delete_user action/hook can be used to perform additional actions when a user is deleted.
deleted_user ( integer $id_user ) The deleted_user action/hook can be used to perform additional actions after a user is deleted.
edit_user_profile ( WP_User $profileuser ) Fires after the 'About the User' settings table on the 'Edit User' screen.
edit_user_profile_update ( integer $user_id ) Fires before the page loads on the 'Edit User' screen.
gravatar ( integer $id_user = null, integer $size = 40, string $alt = '', string $default = 'wavatar' ) : string | boolean Return the HTML markup of tag img with the user gravatar. FALSE otherwise.
init ( ) : WPDKUsers Return a singleton instance of WPDKUsers class
logout ( ) Force an user logout when disabled or if in GET you pass wpdk_logout.
personal_options ( WP_User $profileuser ) Fires at the end of the 'Personal Options' settings table on the user editing screen.
personal_options_update ( integer $user_id ) Fires before the page loads on the 'Your Profile' editing screen.
profile_personal_options ( WP_User $profileuser ) Fires after the 'Personal Options' settings table on the 'Your Profile' editing screen.
show_user_profile ( WP_User $profileuser ) Fires after the 'About Yourself' settings table on the 'Your Profile' editing screen.
signIn ( string | integer $user, string $password, boolean $remember = false ) : boolean Do a WordPress Sign in and call filters and action. Return TRUE if success, FALSE for access denied.
signout ( ) Perform signout. This method is an alias of wp_logout()
userWithMetaAndValue ( string $meta_key, string $meta_value ) : integer Return the User id with meta key and meta value.
user_contactmethods ( $contacts ) Filter the user contact methods.
usersWithCaps ( string $find_caps ) : array Return the users list with a capability
wp_authenticate_user ( WP_User | WP_Error $user ) Filter whether the given user can be authenticated with the provided $password.
wp_login ( string $user_login, WP_User $user = null ) Fires after the user has successfully logged in.
wp_login_failed ( string $username ) Fires after a user login has failed.
wp_logout ( ) Fires after a user is logged-out.

Private Methods

Method Description
__construct ( ) : WPDKUsers Return an instance of WPDKUsers class and register the primary hook for manage and enhancer the standard WordPress User.

Method Details

admin_print_styles_users_php() public method

Fires when styles are printed for a specific admin page based on $hook_suffix.

authenticate() public method

Return the user ID on success, FALSE otherwise.
public authenticate ( string $email, string $password ) : integer | boolean
$email string The email address of the user
$password string The user password
return integer | boolean

avatar() public method

Return an instance of WPDKHTMLTagImg class
Since: 1.4.8
public avatar ( integer $id_user = null, integer $size = 40 ) : WPDKHTMLTagImg | boolean
$id_user integer Optional. User ID or null for current user
$size integer Optional. Avatar size. Default `40`
return WPDKHTMLTagImg | boolean

create() public method

Create a WordPress user and return the user id on success, WP_Error otherwise.
Deprecation: since 1.7.3 - Use `createWithArgs` instead
public create ( string $first_name, string $last_name, string $email, boolean | string $password = false, boolean $enabled = false, string $role = 'subscriber' ) : integer | WP_Error
$first_name string First name
$last_name string Last name
$email string Email address
$password boolean | string Optional. Clear password, if set to FALSE a random password is created
$enabled boolean Optional. If FALSE the WPDK user status is set to disable. Default FALSE.
$role string Optional. User role, default 'subscriber'
return integer | WP_Error

createWithArgs() public method

Create a WordPress user and return the user id on success, WP_Error otherwise.
Since: 1.7.3
public createWithArgs ( array $args ) : integer | WP_Error
$args array { An array user data arguments. @type int $ID User ID. If supplied, the user will be updated. @type string $user_pass The plain-text user password. @type string $user_login The user's login username. @type string $user_nicename The URL-friendly user name. @type string $user_url The user URL. @type string $user_email The user email address. @type string $display_name The user's display name. Default is the the user's username. @type string $nickname The user's nickname. Default Default is the the user's username. @type string $first_name The user's first name. For new users, will be used to build $display_name if unspecified. @type stirng $last_name The user's last name. For new users, will be used to build $display_name if unspecified. @type string|bool $rich_editing Whether to enable the rich-editor for the user. False if not empty. @type string $date_registered Date the user registered. Format is 'Y-m-d H:i:s'. @type string $role User's role. @type string $jabber User's Jabber account username. @type string $aim User's AIM account username. @type string $yim User's Yahoo! messenger username. @type bool $enabled Set TRUE to enable user. Default FALSE. }
return integer | WP_Error

deleteUsersMetaWithKey() public static method

Delete the user meta with $key from all users.
Since: 1.5.16
public static deleteUsersMetaWithKey ( string $key )
$key string Meta key to delete.

delete_user() public method

For example, you can delete rows from custom tables created by a plugin. The hook passes one parameter: the user's ID. This hook runs before a user is deleted. The hook deleted_user (notice the "ed") runs after a user is deleted. Choose the appropriate hook for your needs. If you need access to user meta or fields from the user table, use delete_user. User's deleted from Network Site installs may not trigger this hook. Be sure to use the wpmu_delete_user hook for those cases.
public delete_user ( integer $id_user )
$id_user integer User ID

deleted_user() public method

For example, you can delete rows from custom tables created by a plugin. The hook passes one parameter: the user's ID. This hook runs after a user is deleted. The hook delete_user (delete vs deleted) runs before a user is deleted. Choose the appropriate hook for your needs. If you need access to user meta or fields from the user table, use delete_user. User's deleted from Network Site installs may not trigger this hook. Be sure to use the wpmu_delete_user hook for those cases.
public deleted_user ( integer $id_user )
$id_user integer User ID

edit_user_profile() public method

Fires after the 'About the User' settings table on the 'Edit User' screen.
public edit_user_profile ( WP_User $profileuser )
$profileuser WP_User The current WP_User object.

edit_user_profile_update() public method

Fires before the page loads on the 'Edit User' screen.
public edit_user_profile_update ( integer $user_id )
$user_id integer The user ID.

gravatar() public method

Return the HTML markup of tag img with the user gravatar. FALSE otherwise.
public gravatar ( integer $id_user = null, integer $size = 40, string $alt = '', string $default = 'wavatar' ) : string | boolean
$id_user integer Optional. User ID or null for current user
$size integer Optional. Gravatar size. Default `40`
$alt string Optional. Alternate string for alt attribute. Default user display name.
$default string Optional. Gravatar ID for default (not found) gravatar image, Default `wavatar`
return string | boolean

init() public static method

Return a singleton instance of WPDKUsers class
public static init ( ) : WPDKUsers
return WPDKUsers

logout() public method

Force an user logout when disabled or if in GET you pass wpdk_logout.
public logout ( )

personal_options() public method

Fires at the end of the 'Personal Options' settings table on the user editing screen.
public personal_options ( WP_User $profileuser )
$profileuser WP_User The current WP_User object.

personal_options_update() public method

The action only fires if the current user is editing their own profile.
public personal_options_update ( integer $user_id )
$user_id integer The user ID.

profile_personal_options() public method

The action only fires if the current user is editing their own profile.
Since: 2.0.0
public profile_personal_options ( WP_User $profileuser )
$profileuser WP_User The current WP_User object.

show_user_profile() public method

The action only fires if the current user is editing their own profile.
public show_user_profile ( WP_User $profileuser )
$profileuser WP_User The current WP_User object.

signIn() public method

Do a WordPress Sign in and call filters and action. Return TRUE if success, FALSE for access denied.
public signIn ( string | integer $user, string $password, boolean $remember = false ) : boolean
$user string | integer Any user id, user email or user login
$password string Password
$remember boolean Optional. TRUE for set a cookie for next login
return boolean

signout() public method

Perform signout. This method is an alias of wp_logout()
public signout ( )

userWithMetaAndValue() public static method

Return the User id with meta key and meta value.
public static userWithMetaAndValue ( string $meta_key, string $meta_value ) : integer
$meta_key string Meta Key
$meta_value string Meta value
return integer User ID or FALSE

user_contactmethods() public method

Filter the user contact methods.
public user_contactmethods ( $contacts )

usersWithCaps() public static method

Return the users list with a capability
public static usersWithCaps ( string $find_caps ) : array
$find_caps string Single capability
return array

wp_authenticate_user() public method

Filter whether the given user can be authenticated with the provided $password.
public wp_authenticate_user ( WP_User | WP_Error $user )
$user WP_User | WP_Error WP_User or WP_Error object if a previous callback failed authentication.

wp_login() public method

Fires after the user has successfully logged in.
public wp_login ( string $user_login, WP_User $user = null )
$user_login string Username.
$user WP_User WP_User object of the logged-in user.

wp_login_failed() public method

Fires after a user login has failed.
public wp_login_failed ( string $username )
$username string User login.

wp_logout() public method

Fires after a user is logged-out.
public wp_logout ( )