Auto-Revoke Expired Application Passwords

Last updated 1 month ago

PHP
function revoke_expired_application_passwords() {
    $passwords = WP_Application_Passwords::get_application_passwords(get_current_user_id());

    foreach ($passwords as $password) {
        // Check if password has expired (optional: adjust expiration condition)
        if (time() > strtotime($password->expiration_date)) {
            WP_Application_Passwords::revoke_application_password($password->id);
            error_log("Revoked expired application password for user {$password->user_id}.");
        }
    }
}

add_action('wp_footer', 'revoke_expired_application_passwords');

All code snippets are licensed GPLv2 or later unless otherwise stated.