Sometimes people forget their WordPress admin credentials and email as well so there is no way for them to reset the password to come back in the admin. Following is a little code that you can either add in the functions.php file or set a script in Scripts Organizer and select the PHP option in it.
<?php
// create admin user programmatically
function dp_create_user()
{
// pass this as a parameter in your site URL like if your site is dplugins.com then pass it like this dplugins.com/?dp_create_user=yes
if ($_GET['dp_create_user'] == "yes") {
$random_password = 'admin123_99'; // password
$user_email = "test@dplugins.com"; // email
$user_name = 'dplugins'; // username
$user_id = wp_create_user($user_name, $random_password, $user_email); // this will create a new user
wp_update_user([
'ID' => $user_id,
'role' => 'administrator', // this will set user role to administrator
]);
}
}
add_action('wp_head', 'dp_create_user', 9999999999);
// create admin user programmatically
?>
Open Scripts Organizer
Hit Add new.
Trigger Location: Everywhere
Script Location: PHP