wp_is_application_passwords_available()
Checks if Application Passwords can be used for the current request.
The purpose of this function is to determine whether the Application Passwords system can be used for authorization in the current request. Note that this check is always performed automatically when a user is authorized via an application password.
By default, "Application Passwords" are allowed (i.e., this function will return true) for all sites using SSL or if the environment type local is enabled.
Hooks from the function
Returns
true|false.
Usage
wp_is_application_passwords_available();
Examples
#1 Example of returning an error on an inappropriate request
Suppose we make a request and in the REST listener we need to check if the request fits the application Password system and if it doesn't, we need to print the corresponding error message.
if ( ! wp_is_application_passwords_available() ) {
return new WP_Error(
'application_passwords_disabled',
__( 'Application passwords are not available.' ),
[ 'status' => 501 ]
);
}
Changelog
| Since 5.6.0 | Introduced. |
wp_is_application_passwords_available() wp is application passwords available code WP 6.9
function wp_is_application_passwords_available() {
/**
* Filters whether Application Passwords is available.
*
* @since 5.6.0
*
* @param bool $available True if available, false otherwise.
*/
return apply_filters( 'wp_is_application_passwords_available', wp_is_application_passwords_supported() );
}