On this page
WP_Application_Passwords::update_application_password( int $user_id, string $uuid, array $update = array() ): true|WP_Error
Updates an application password.
Parameters
$user_idint Required-
User ID.
$uuidstring Required-
The password's UUID.
$updatearray Optional-
Information about the application password to update.
Default:
array()
Return
true|WP_Error True if successful, otherwise a WP_Error instance is returned on error.
Source
File: wp-includes/class-wp-application-passwords.php. View all references
public static function update_application_password( $user_id, $uuid, $update = array() ) {
$passwords = static::get_user_application_passwords( $user_id );
foreach ( $passwords as &$item ) {
if ( $item['uuid'] !== $uuid ) {
continue;
}
if ( ! empty( $update['name'] ) ) {
$update['name'] = sanitize_text_field( $update['name'] );
}
$save = false;
if ( ! empty( $update['name'] ) && $item['name'] !== $update['name'] ) {
$item['name'] = $update['name'];
$save = true;
}
if ( $save ) {
$saved = static::set_user_application_passwords( $user_id, $passwords );
if ( ! $saved ) {
return new WP_Error( 'db_error', __( 'Could not save application password.' ) );
}
}
/**
* Fires when an application password is updated.
*
* @since 5.6.0
*
* @param int $user_id The user ID.
* @param array $item The updated app password details.
* @param array $update The information to update.
*/
do_action( 'wp_update_application_password', $user_id, $item, $update );
return true;
}
return new WP_Error( 'application_password_not_found', __( 'Could not find an application password with that id.' ) );
}
Hooks
- do_action( 'wp_update_application_password',
int $user_id ,array $item ,array $update ) -
Fires when an application password is updated.
Related
Uses
| Uses | Description |
|---|---|
| sanitize_text_field() wp-includes/formatting.php | Sanitizes a string from user input or from the database. |
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| do_action() wp-includes/plugin.php | Calls the callback functions that have been added to an action hook. |
| WP_Error::__construct() wp-includes/class-wp-error.php | Initializes the error. |
Used By
| Used By | Description |
|---|---|
| WP_REST_Application_Passwords_Controller::update_item() wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-controller.php | Updates an application password. |
Changelog
| Version | Description |
|---|---|
| 5.6.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_application_passwords/update_application_password