WP_Application_Passwords::record_application_password_usage() WordPress Method

The WP_Application_Passwords::record_application_password_usage() method is used to record when an application password is used. This is used to help security auditing and to track application password usage.

WP_Application_Passwords::record_application_password_usage( int $user_id, string $uuid ) #

Records that an application password has been used.


Parameters

$user_id

(int)(Required)User ID.

$uuid

(string)(Required)The password's UUID.


Top ↑

Return

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


Top ↑

Source

File: wp-includes/class-wp-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 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.' ) );
	}


Top ↑

Changelog

Changelog
VersionDescription
5.6.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.