GC_Application_Passwords::update_application_password()
最后更新于:2021-11-26 09:14:49
GC_Application_Passwords::update_application_password( int$user_id, string$uuid, array$update=array())Updates an application password.
参数
- $user_id
-
(int) (Required) User ID.
- $uuid
-
(string) (Required) The password’s uuid.
- $update
-
(array) (Optional) Information about the application password to update.
Default value: array()
响应
(true|GC_Error) True if successful, otherwise a GC_Error instance is returned on error.
源文件
文件: gc-includes/class-gc-application-passwords.php
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 GC_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( 'gc_update_application_password', $user_id, $item, $update );
return true;
}
return new GC_Error( 'application_password_not_found', __( 'Could not find an application password with that id.' ) );
}