GC_Application_Passwords::record_application_password_usage()
最后更新于:2021-11-26 09:14:31
GC_Application_Passwords::record_application_password_usage( int$user_id, string$uuid)Records that an application password has been used.
参数
- $user_id
-
(int) (Required) User ID.
- $uuid
-
(string) (Required) The password’s uuid.
响应
(true|GC_Error) True if the usage was recorded, a GC_Error if an error occurs.
源文件
文件: gc-includes/class-gc-application-passwords.php
public static function record_application_password_usage( $user_id, $uuid ) {
$passwords = static::get_user_application_passwords( $user_id );
foreach ( $passwords as &$password ) {
if ( $password['uuid'] !== $uuid ) {
continue;
}
// Only record activity once a day.
if ( $password['last_used'] + DAY_IN_SECONDS > time() ) {
return true;
}
$password['last_used'] = time();
$password['last_ip'] = $_SERVER['REMOTE_ADDR'];
$saved = static::set_user_application_passwords( $user_id, $passwords );
if ( ! $saved ) {
return new GC_Error( 'db_error', __( 'Could not save application password.' ) );
}
return true;
}
// Specified Application Password not found!
return new GC_Error( 'application_password_not_found', __( 'Could not find an application password with that id.' ) );
}