wp_authenticate_application_password( WP_User|WP_Error|null $input_user, string $username, string $password ): WP_User|WP_Error|null
- Since
- 5.6.0
- Source
wp-includes/user.php:372
Authenticates the user using an application password.
Parameters
$input_userWP_User|WP_Error|null- WP_User or WP_Error object if a previous callback failed authentication.
$usernamestring- Username for authentication.
$passwordstring- Password for authentication.
Return
WP_User|WP_Error|null- WP_User on success, WP_Error on failure, null if null is passed in and this isn't an API request.
Hooks fired · 6
6 hooks fire while wp_authenticate_application_password() runs, in this order:
- apply_filters( application_password_is_api_request )filterline 398 (+26 into the body)
Filters whether this is an API request that Application Passwords can be used on.
- do_action( application_password_failed_authentication )actionline 444 (+72 into the body)
Fires when an application password failed to authenticate the user.
- do_action( wp_authenticate_application_password_errors )actionline 478 (+106 into the body)
Fires when an application password has been successfully checked as valid.
- do_action( application_password_failed_authentication )actionline 482 (+110 into the body)
Fires when an application password failed to authenticate the user.
- do_action( application_password_did_authenticate )actionline 497 (+125 into the body)
Fires after an application password was used for authentication.
- do_action( application_password_failed_authentication )actionline 508 (+136 into the body)
Fires when an application password failed to authenticate the user.
Uses · 12
- apply_filters()Calls the callback functions that have been added to a filter hook.
- get_user_by()Retrieves user info by a given field.
- is_email()Verifies that an email is valid.
- __()Retrieves the translation of $text.
- wp_is_application_passwords_available()Checks if Application Passwords is globally available.
- wp_is_application_passwords_available_for_user()Checks if Application Passwords is available for a specific user.
- do_action()Calls the callback functions that have been added to an action hook.
- WP_Application_Passwords::is_in_use()Checks if application passwords are being used by the site.
- WP_Error::__construct()Initializes the error.
- WP_Application_Passwords::get_user_application_passwords()Gets a user's application passwords.
- WP_Application_Passwords::check_password()Checks a plaintext application password against a hashed password.
- WP_Application_Passwords::record_application_password_usage()Records that an application password has been used.
Used by · 1
- wp_validate_application_password()Validates the application password credentials passed via Basic Authentication.
Source
function wp_authenticate_application_password( $input_user, $username, #[\SensitiveParameter] $password) { if ( $input_user instanceof WP_User ) { return $input_user; } if ( ! WP_Application_Passwords::is_in_use() ) { return $input_user; } // The 'REST_REQUEST' check here may happen too early for the constant to be available. $is_api_request = ( ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ); /** * Filters whether this is an API request that Application Passwords can be used on. * * By default, Application Passwords is available for the REST API and XML-RPC. * * @since 5.6.0 * * @param bool $is_api_request If this is an acceptable API request. */ $is_api_request = apply_filters( 'application_password_is_api_request', $is_api_request ); if ( ! $is_api_request ) { return $input_user; } $error = null; $user = get_user_by( 'login', $username ); if ( ! $user && is_email( $username ) ) { $user = get_user_by( 'email', $username ); } // If the login name is invalid, short circuit. if ( ! $user ) { if ( is_email( $username ) ) { $error = new WP_Error( 'invalid_email', __( '<strong>Error:</strong> Unknown email address. Check again or try your username.' ) ); } else { $error = new WP_Error( 'invalid_username', __( '<strong>Error:</strong> Unknown username. Check again or try your email address.' ) ); } } elseif ( ! wp_is_application_passwords_available() ) { $error = new WP_Error( 'application_passwords_disabled', __( 'Application passwords are not available.' ) ); } elseif ( ! wp_is_application_passwords_available_for_user( $user ) ) { $error = new WP_Error( 'application_passwords_disabled_for_user', __( 'Application passwords are not available for your account. Please contact the site administrator for assistance.' ) ); } if ( $error ) { /** * Fires when an application password failed to authenticate the user. * * @since 5.6.0 * * @param WP_Error $error The authentication error. */ do_action( 'application_password_failed_authentication', $error ); return $error; } /* * Strips out anything non-alphanumeric. This is so passwords can be used with * or without spaces to indicate the groupings for readability.History
Introduced in 5.6.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/user.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.