Last active
January 30, 2024 00:27
-
-
Save yogasukma/4f0bc6eda6407a9c86e779a38e6bac2d to your computer and use it in GitHub Desktop.
generate app pass for login user
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!is_user_logged_in() ) { | |
echo "<a href='" . wp_login_url('/') . "'>login</a>"; | |
} else { | |
$user_id = get_current_user_id(); // get user id | |
$app_name = 'app_' . date("y-m-d-H-i-s"); // create random app name | |
$app_pass = WP_Application_Passwords::create_new_application_password( $user_id, array( 'name' => $app_name ) ); // generate pass | |
$chunks = str_split($app_pass[0], 4); // Split string into chunks of 4 characters | |
$result = implode(" ", $chunks); // Join chunks with space between them | |
echo $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment