One of the Most Frustrating issues in WordPress is when you’re the actual Admin of your Website and you’re not able to log in to your Account. Your Website will show an error “Sorry, you are not allowed to access this page”. This Issue Happens due to many reasons such as a forgotten username and password, the active user account may get deleted, the Admin rights of the user getting removed, A User Account being deleted by security plugins (or) your site may have been hacked. This Issue needs to be fixed immediately to avoid further problems.
The Easiest Way to Fix this Issue is to add a Temporary Admin User through FTP. This Temporary Admin User is used to log in to your account temporarily. After Logging in to your Account with this new temporary admin account, You need to Change the Admin Rights to the Original User Account. And then Log in to your WordPress admin panel with that Original Account. You must remove admin rights from the temporary admin account and delete the temporary admin account. And also remove the code also. If you’re new to WordPress, don’t worry follow our steps carefully. We provided a Step by Step Tutorial for Adding Admin User in WordPress through FTP or File Manager.
Steps for How to Create/Add an Admin User in WordPress using FTP or cPanel File Manager?
Method 1: Add a New Admin User Using an FTP Client
Step 1: You can also use FTP Clients Like FileZilla, WinSCP or Cyberduck to access the WordPress Files with your FTP Hostname, Username, Password, and Port Numbers.
Step 2: After Successfully Connecting, Navigate to the Root directory of your existing Worpdress Installation and Look for the public_html folder.
Usually, the Path Should look like this /public_html/wp-content/themes/current-theme/
Step 3: Now Open the Public_Html Folder & Double Click on the wp-content & Look for the Themes Folder and Double Click on it.
Step 4: Just locate the Currently Active Theme Folder (The folder of the theme that you’re currently using on your website) and double-click on it.
Step 5: Now You need to look for the functions.php file in the theme folder, and Right Click on it and select Edit to edit the Functions.php file.
*Important Note – For safety Purposes, Make Sure to back up the Functions.php file before editing. Because if something goes wrong after editing, We can use the backup file to bring it back to normal.
Step 6: You need to copy and paste the following Code into the Functions.php file.
Here I’m providing you with two codes, you can try them one by one and check which one works for you.
function create_admin_account(){ $user = 'Username'; $pass = 'Password'; $email = 'email id'; //if a username with the email ID does not exist, create a new user account if ( !username_exists( $user ) && !email_exists( $email ) ) { $user_id = wp_create_user( $user, $pass, $email ); $user = new WP_User( $user_id ); //Set the new user as a Admin $user->set_role( 'administrator' ); } } add_action('init','create_admin_account');
(or)
function wpb_admin_account(){ $user = 'Username'; $pass = 'Password'; $email = 'email id'; if ( !username_exists( $user ) && !email_exists( $email ) ) { $user_id = wp_create_user( $user, $pass, $email ); $user = new WP_User( $user_id ); $user->set_role( 'administrator' ); } } add_action('init','wpb_admin_account');
This Step is the Most Important Step and you need to follow it carefully.
Step 7: Now You Need to Replace the Username, Password, Email ID with your own details and Save the File.
*Important Note – The Username, Password, and Email ID that you enter should be Unique otherwise the code may not work.
Step 8: Now Goto to your WordPress Admin and Log in with your Newly Created User Credentials.
*Important Note – After logging into your account, you must remove the added code from the “functions.php” file because leaving the code as it is will be a huge potential security risk.
Method 2: Add a New Admin User Using Web Hosting’s File Manager
Step 1: Go to your Website Hosting Site. Log in to your Account. You’ll be redirected to your hosting dashboard.
Step 2: If Your Hosting Provider provides a File Manager Option, click on the File Manager option to Open. If not, look for the C-Panel Section.
Step 3: On the C-Panel Dashboard, look for the File Manager Option and click on it. A New File Manager Window will open.
Step 4: You need to find the location of your theme folder as mentioned in the previous method. You can follow the Same Steps.
Step 5: Go to /public_html/wp-content/themes/current-theme/ and search for functions.php and right-click on it and press the Edit Button.
Step 6: You need to copy and paste the same Code mentioned in the 1st method into the Functions.php file.
Here I’m providing you with two codes, you can try them one by one and check which one works for you.
function create_admin_account(){ $user = 'Username'; $pass = 'Password'; $email = 'email id'; //if a username with the email ID does not exist, create a new user account if ( !username_exists( $user ) && !email_exists( $email ) ) { $user_id = wp_create_user( $user, $pass, $email ); $user = new WP_User( $user_id ); //Set the new user as a Admin $user->set_role( 'administrator' ); } } add_action('init','create_admin_account');
(or)
function wpb_admin_account(){ $user = 'Username'; $pass = 'Password'; $email = 'email id'; if ( !username_exists( $user ) && !email_exists( $email ) ) { $user_id = wp_create_user( $user, $pass, $email ); $user = new WP_User( $user_id ); $user->set_role( 'administrator' ); } } add_action('init','wpb_admin_account');
Step 7: You need to Replace the Username, Password, and Email ID with your details and save the file.
Step 8: Go to your WordPress Admin and Log in with your Newly Created User Credentials.
You Can Follow these Optional Steps If you want
Step 9: Navigate to the Users Section and click the Add New Button to create a New User, and give the Administrator Role, and Press Update Profile.
Step 10: You need to Log out from the Site and again Log in with your New User that you created from the WordPress Users Section.
Step 11: Go to the Users Section and Remove the Admin rights for the user that you’ve created through the functions.php file and delete the User.
Some Other Solutions You May Consider
1. Reinstall WordPress Core
You Can Reinstall WordPress Core Files by Going to Dashboard > Updates > clicking “Reinstall Version 6.x.x” Button. This will reinstall WordPress again and fix the Corrupt files.
2. Delete the old .htaccess file and create a new .htaccess file
In WordPress, the files can get easily corrupted. One of the most important file which gets easily corrupted is the .htaccess File. This is due to plugin conflicts or no access due to wrong file permissions. Delete the Older .htaccess file and now WordPress automatically generates a new default .htaccess file. Make Sure that File Permissions for Folders and Files are correct.
The Default File Permissions Values are
Files: 644
Folders: 755
*Important Note – Always set these Values to all Folders and Files.
3. Deactivate all WordPress plugins
Sometimes, a faulty plugin or plugin conflicts may be the cause of the issue. So it’s better to deactivate all plugins to check the root cause of a problem. You Can Deactivate all plugins via FTP or Web Hosting File Manager Options. You can follow these steps to deactivate all plugins at once.
Go to /public_html/wp-content/ and rename the plugins folder to Pluginschecking.
Now, go to your website and check if it works, then rename the folder to Plugins and start reactivating plugins one by one to find the corrupt/conflicting plugin.
That’s All About this Post.
Give Your Reviews / Reactions about this Post and Leave Comments, Ask Your Doubts, We are here to Help You!