PHP Class Application_Passwords

Since: 0.1-dev
ファイルを表示 Open project: georgestephanis/application-passwords Class Usage Examples

Public Methods

Method Description
add_hooks ( ) Add various hooks.
authenticate ( WP_User $input_user, string $username, string $password ) : mixed Filter the user to authenticate.
chunk_password ( string $raw_password ) : string Sanitize and then split a password into smaller chunks.
create_new_application_password ( integer $user_id, string $name ) : array Generate a new application password.
delete_all_application_passwords ( integer $user_id ) : integer Deletes all application passwords for the given user.
delete_application_password ( integer $user_id, string $slug ) : boolean Delete a specified application password.
get_user_application_passwords ( integer $user_id ) : array Get a users application passwords.
password_unique_slug ( array $item ) : string Generate a unique repeateable slug from the hashed password, name, and when it was created.
rest_add_application_password ( $data ) : array REST API endpoint to add a new application password for a user.
rest_api_auth_handler ( $input_user ) : WP_User | boolean Loosely Based on https://github.com/WP-API/Basic-Auth/blob/master/basic-auth.php
rest_api_init ( ) Handle declaration of REST API endpoints.
rest_delete_all_application_passwords ( $data ) : integer REST API endpoint to delete all of a user's application passwords.
rest_delete_application_password ( $data ) : boolean REST API endpoint to delete a given application password.
rest_edit_user_callback ( $data ) : boolean Whether or not the current user can edit the specified user.
rest_list_application_passwords ( $data ) : array REST API endpoint to list existing application passwords for a user.
rest_test_basic_authorization_header ( ) : WP_Error | array Test whether PHP can see Basic Authorization headers passed to the web server.
set_user_application_passwords ( integer $user_id, array $passwords ) : boolean Set a users application passwords.
show_user_profile ( WP_User $user ) Display the application password section in a users profile.
wp_rest_server_class ( $class ) Prevent caching of unauthenticated status. See comment below.

Method Details

add_hooks() public static method

Add various hooks.
Since: 0.1-dev
public static add_hooks ( )

authenticate() public static method

Filter the user to authenticate.
Since: 0.1-dev
public static authenticate ( WP_User $input_user, string $username, string $password ) : mixed
$input_user WP_User User to authenticate.
$username string User login.
$password string User password.
return mixed

chunk_password() public static method

Sanitize and then split a password into smaller chunks.
Since: 0.1-dev
public static chunk_password ( string $raw_password ) : string
$raw_password string Users raw password.
return string

create_new_application_password() public static method

Generate a new application password.
Since: 0.1-dev
public static create_new_application_password ( integer $user_id, string $name ) : array
$user_id integer User ID.
$name string Password name.
return array The first key in the array is the new password, the second is its row in the table.

delete_all_application_passwords() public static method

Deletes all application passwords for the given user.
Since: 0.1-dev
public static delete_all_application_passwords ( integer $user_id ) : integer
$user_id integer User ID.
return integer The number of passwords that were deleted.

delete_application_password() public static method

Delete a specified application password.
See also: Application_Passwords::password_unique_slug()
Since: 0.1-dev
public static delete_application_password ( integer $user_id, string $slug ) : boolean
$user_id integer User ID.
$slug string The generated slug of the password in question.
return boolean Whether the password was successfully found and deleted.

get_user_application_passwords() public static method

Get a users application passwords.
Since: 0.1-dev
public static get_user_application_passwords ( integer $user_id ) : array
$user_id integer User ID.
return array

password_unique_slug() public static method

Generate a unique repeateable slug from the hashed password, name, and when it was created.
Since: 0.1-dev
public static password_unique_slug ( array $item ) : string
$item array The current item.
return string

rest_add_application_password() public static method

REST API endpoint to add a new application password for a user.
Since: 0.1-dev
public static rest_add_application_password ( $data ) : array
$data
return array

rest_api_auth_handler() public static method

Loosely Based on https://github.com/WP-API/Basic-Auth/blob/master/basic-auth.php
Since: 0.1-dev
public static rest_api_auth_handler ( $input_user ) : WP_User | boolean
$input_user
return WP_User | boolean

rest_api_init() public static method

Handle declaration of REST API endpoints.
Since: 0.1-dev
public static rest_api_init ( )

rest_delete_all_application_passwords() public static method

REST API endpoint to delete all of a user's application passwords.
Since: 0.1-dev
public static rest_delete_all_application_passwords ( $data ) : integer
$data
return integer The number of deleted passwords

rest_delete_application_password() public static method

REST API endpoint to delete a given application password.
Since: 0.1-dev
public static rest_delete_application_password ( $data ) : boolean
$data
return boolean

rest_edit_user_callback() public static method

Whether or not the current user can edit the specified user.
Since: 0.1-dev
public static rest_edit_user_callback ( $data ) : boolean
$data
return boolean

rest_list_application_passwords() public static method

REST API endpoint to list existing application passwords for a user.
Since: 0.1-dev
public static rest_list_application_passwords ( $data ) : array
$data
return array

rest_test_basic_authorization_header() public static method

Test whether PHP can see Basic Authorization headers passed to the web server.
public static rest_test_basic_authorization_header ( ) : WP_Error | array
return WP_Error | array

set_user_application_passwords() public static method

Set a users application passwords.
Since: 0.1-dev
public static set_user_application_passwords ( integer $user_id, array $passwords ) : boolean
$user_id integer User ID.
$passwords array Application passwords.
return boolean

show_user_profile() public static method

This executes during the show_user_security_settings action.
Since: 0.1-dev
public static show_user_profile ( WP_User $user )
$user WP_User WP_User object of the logged-in user.

wp_rest_server_class() public static method

We don't actually care about the wp_rest_server_class filter, it just happens right after the constant we do care about is defined.
Since: 0.1-dev
public static wp_rest_server_class ( $class )