WP_Application_Passwords::record_application_password_usage( int $user_id, string $uuid ): true|WP_Error

In this article

Records that an application password has been used.

Parameters

$user_idintrequired
User ID.
$uuidstringrequired
The password’s UUID.

Return

true|WP_Error True if the usage was recorded, a WP_Error if an error occurs.

Source

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 WP_Error( 'db_error', __( 'Could not save application password.' ) );
		}

		return true;
	}

	// Specified application password not found!
	return new WP_Error( 'application_password_not_found', __( 'Could not find an application password with that id.' ) );
}

Changelog

VersionDescription
5.6.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.