WP_Application_Passwords::delete_all_application_passwords( int $user_id )

Deletes all application passwords for the given user.

Parameters

$user_id

(int) (Required) User ID.

Return

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

Source

File: wp-includes/class-wp-application-passwords.php

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;
	}

Changelog

Version Description
5.6.0 Introduced.

© 2003–2021 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_application_passwords/delete_all_application_passwords