WP_Application_Passwords::delete_all_application_passwords( int $user_id ): int|WP_Error

In this article

Deletes all application passwords for the given user.

Parameters

$user_idintrequired
User ID.

Return

int|WP_Error The number of passwords that were deleted or a WP_Error on failure.

Source

public static function delete_all_application_passwords( $user_id ) {
	$passwords = static::get_user_application_passwords( $user_id );

	if ( $passwords ) {
		$saved = static::set_user_application_passwords( $user_id, array() );

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

		foreach ( $passwords as $item ) {
			/** This action is documented in wp-includes/class-wp-application-passwords.php */
			do_action( 'wp_delete_application_password', $user_id, $item );
		}

		return count( $passwords );
	}

	return 0;
}

Hooks

do_action( ‘wp_delete_application_password’, int $user_id, array $item )

Fires when an application password is deleted.

Changelog

VersionDescription
5.6.0Introduced.

User Contributed Notes

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