WP_Application_Passwords::update_application_password()
Updates an application password.
Метод класса: WP_Application_Passwords{}
Хуки из метода
Возвращает
true|WP_Error
. True if successful, otherwise a WP_Error instance is returned on error.
Использование
$result = WP_Application_Passwords::update_application_password( $user_id, $uuid, $update );
- $user_id(int) (обязательный)
- User ID.
- $uuid(строка) (обязательный)
- The password's UUID.
- $update(массив)
Information about the application password to update.
По умолчанию: array()
-
uuid(строка)
The unique identifier for the application password. -
app_id(строка)
A UUID provided by the application to uniquely identify it. -
name(строка)
The name of the application password. -
password(строка)
A one-way hash of the password. -
created(int)
Unix timestamp of when the password was created. -
last_used(int|null)
The Unix timestamp of the GMT date the application password was last used. - last_ip(строка|null)
The IP address the application password was last used by.
-
Список изменений
С версии 5.6.0 | Введена. |
Код WP_Application_Passwords::update_application_password() WP Application Passwords::update application password WP 6.7.2
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 application password details. * * @type string $uuid The unique identifier for the application password. * @type string $app_id A UUID provided by the application to uniquely identify it. * @type string $name The name of the application password. * @type string $password A one-way hash of the password. * @type int $created Unix timestamp of when the password was created. * @type int|null $last_used The Unix timestamp of the GMT date the application password was last used. * @type string|null $last_ip The IP address the application password was last used by. * } * @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.' ) ); }