GC_Application_Passwords::delete_application_password()

最后更新于:2021-11-26 09:13:55

GC_Application_Passwords::delete_application_password( int$user_id, string$uuid)

Deletes an application password.

参数

$user_id

(int) (Required) User ID.

$uuid

(string) (Required) The password’s uuid.

响应

(true|GC_Error) Whether the password was successfully found and deleted, a GC_Error otherwise.

源文件

文件: gc-includes/class-gc-application-passwords.php

	public static function delete_application_password( $user_id, $uuid ) {
		$passwords = static::get_user_application_passwords( $user_id );

		foreach ( $passwords as $key => $item ) {
			if ( $item['uuid'] === $uuid ) {
				unset( $passwords[ $key ] );
				$saved = static::set_user_application_passwords( $user_id, $passwords );

				if ( ! $saved ) {
					return new GC_Error( 'db_error', __( 'Could not delete application password.' ) );
				}

				/**
				 * Fires when an application password is deleted.
				 *
				 * @since 5.6.0
				 *
				 * @param int   $user_id The user ID.
				 * @param array $item    The data about the application password.
				 */
				do_action( 'gc_delete_application_password', $user_id, $item );

				return true;
			}
		}

		return new GC_Error( 'application_password_not_found', __( 'Could not find an application password with that id.' ) );
	}