WordPress is a free content management system (CMS) that allows users to create and manage websites easily. Especially for beginners, WordPress is the Best Option to begin with. You don’t even need coding knowledge to use WordPress. As per Stats, WordPress is the most popular CMS in the world right now. Even Some Statistics reveal that nearly 40% of websites on the internet are built using WordPress. It offers a lot of good features like free themes, free plugins. Even though WordPress is a great content management system (CMS), on some occasions it can cause errors and issues that break your site. You need to fix these Issues As Soon as possible to avoid losing the traffic.
If your Website shows an error “Sorry, you are not allowed to access this page”. Then the Issue is 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. During this error, you will not be able to log in to your Account, even though you are the original admin of the website.This Issue needs to be fixed immediately to avoid further problems.If you’re new to WordPress, don’t worry, follow our steps carefully. We provided a Step by Step Tutorial for Adding an Admin User in WordPress through FTP or File Manager.
How to Fix “Sorry, You are not allowed to access this page” Error in WordPress?
Method 1: Adding Admin User Using Funtions.php
Step 1: Go to your Website Hosting Site. Log into your Account and Open the C-Panel and Access the File Manager.
(or)
Step 1:You can use the FTP Clients Like FileZilla to access the WordPress Files with your FTP Hostname, Username, Password, and Port Numbers.
Step 2:Navigate to your WordPress installation Directory and look for the public_html folder.
Step 3: Open the Public_Html Folder & Double Click on the wp-content & Double Click on the Themes Folder. Just locate the Theme Folder (The folder of the theme that you’re currently using on your website) and double-click on it.
Step 4: 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 File Before Editing. Because if something goes wrong after editing, we can use the backup file to bring it back to normal.
Step 5: Now 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 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 6: 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 7: Now go 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: Adding Admin User to the Database using PHP
Step 1: Go to your Website Hosting Site. Log in to your Account and Open the C-Panel, and Access the File Manager. (or) You can use the FTP to access the WordPress files.
Step 2: Go to the Root directory of your existing WordPress installation and look for the public_html folder.
Step 3:Open the Public_HtmlFolder & Double Click on the wp-content and Create a New Folder and Name the Folder as mu-plugins. If the folder already exists, then follow the next steps.
Step 4:Now, open the mu-plugins folder. Create a New File and name the files as per your wish. You can name the file as Adding Admin User.php
The Filename that you create should end with .php extension.
<?php add_action( 'init', function () { $username = 'admin'; $password = 'password'; $email_address = '[email protected]'; if ( ! username_exists( $username ) ) { $user_id = wp_create_user( $username, $password, $email_address ); $user = new WP_User( $user_id ); $user->set_role( 'administrator' ); } } );
Step 5: Replace the Username, Password, and 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 6: Now, Go to your WordPress Admin Panel and Log in with the New Admin Account and After logging into your account, you need to delete the Adding Admin User.php file that you’ve created.
You Can Follow these Optional Steps If you want
Step 9: Navigate to the UsersSection and click the Add New Button to Create a New User give the Administrator Role, and Press Update Profile.
Step 10: Now log out from the Site and 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.
Method 3: Adding Admin User Via MySQL (phpMyAdmin)
Step 1:Goto your Website Hosting Site. Log into your Account & Open the C-Panel.
Step 2:On your C-Panel, navigate to the Database Section and click on the phpMyAdmin to open the phpMyAdmin Interface.
Step 3:You need to click on your WordPress site’s database from the databases list that is available on your Left Side Pane.
Step 4:Now, all tables of your WordPress Database will be displayed. Look for the wp_users and click on it, and select the Insert Option to Add the New Admin User.
Step 5: Now You Need to fill in the Details in the following fields, which are given below.
(ID,user_login,user_pass,user_nicename,user_email,user_URL,user_registered,user_status,display_name)
Step 6: On theuser_pass field,you need to select the MD5option in the function menu.
Step 7: On the user_status, you need to enter 0 as the value.
Step 8: You need to Scroll Down and press the GoButton after entering the details in the required fields.
Step 9: You need to look for the wp_usermeta Table on your Database and Just Click on it.
Step 10: Now, you also need to fill in the Details in the following fields, which are given below.
(user_id,meta_key,meta_value)
Step 11:On the meta_key Field,you should enter wp_capabilities in this field.
Step 12: For the meta_value Field,you need to enter “a:1:{s:13:”administrator”;s:1:”1″;}”in the field.
a:1:{s:13:"administrator";s:1:"1";}
*Important Note – Enter the Value without quotation marks.
Step 9: Now you need to click on the Go Button to complete the Admin User Creation Process.
Step 10: Now, Login to your WordPress Admin Account With the New Username and Password.
Step 11: After logging into your account, navigate to Users, and you need to delete the User that you’ve created.
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!