25Nov
How to Create a New Admin User in WordPress When You've Forgotten Your Password
Hamid Rezazadeh |25 Nov, 2024
|
WordPress admin,
Forgot password,
Create admin user,
WordPress access,
PHP script WordPress,
WordPress hosting,
Recover WordPress access,
Add admin WordPress,
Create new user WordPress,
WordPress admin login | wordpress | 0 Comments |
View Counts (1910)
|Return|
0 ( 0 reviews)
|
Many WordPress users face the issue of forgetting their password and are unable to access the website's admin area. While WordPress offers password recovery options on the login page, there are times when users may encounter problems, such as not receiving the recovery email or having limited access to their email. In such cases, one of the simplest and most effective solutions is to create a new admin user through your hosting panel and database.
In this article, we will introduce a useful PHP file that allows you to create a new admin user with full access without needing to log into the WordPress dashboard. All you need is access to your hosting panel to execute this script and resolve your access issue.
Steps to Use the Script for Creating a New Admin User: Using the PHP file explained below, you can create a new admin account with a default username and password. Follow the steps below:
-
Access WordPress Files via Hosting Panel First, log into your hosting control panel (cPanel or any other tool) and navigate to your WordPress site's files. These files are usually located in the public_html
directory.
-
Create a New PHP File Create a new PHP file in the root of your WordPress installation (the location where wp-config.php
and index.php
are located). You can name this file create-admin.php
.
-
Insert the Script Code Copy and paste the following code into the create-admin.php
file. This code will create a new admin user with the username and password set to "aryaportal"
< ? php
// Load WordPress
require_once('wp-load.php');
require_once('wp-includes/pluggable.php');
// Default username and password
$username = 'aryaportal';
$password = 'aryaportal';
$email = '[email protected]';
// Check if the user already exists
if (!username_exists($username) && !email_exists($email)) {
// Create the user
$user_id = wp_create_user($username, $password, $email);
// Get the user object
$user = new WP_User($user_id);
// Set the role to administrator
$user->set_role('administrator');
echo 'Admin user created successfully.';
} else {
echo 'User already exists.';
}
?>
4. Run the File in Your Browser After saving the file, open your browser and type your website address followed by the name of the PHP file. For example, if your domain is example.com
, enter the following URL in your browser:
http://example.com/create-admin.php
Once the file is executed, a new admin user will be created, and a success message will be displayed.
5. Delete the File After Use It is crucial to delete the create-admin.php
file from your hosting panel after successfully running the script. This is a necessary security measure to prevent unauthorized access to your website.
Conclusion: This method is one of the fastest and most effective ways to regain access to your WordPress dashboard. By accessing your hosting panel and running this simple script, you can create a new admin user and immediately log in to your dashboard. It’s always recommended to back up your email and password, and consider this method as a temporary emergency solution.
To download the PHP script, see the attachments section at the bottom of this page.
About the Author
Attachments
Related
If you use WordPress content management system to manage your site and WooCommerce to sell your prod...
Read More >