Solution to Being Locked Out of WordPress Admin

It’s safe to say that being locked out of the wp-admin screen is one of the most frustrating but also inconvenient issues you can face. Because not only do you lose access, you also lose the ability to manage the site, publish content, moderate comments, and do other administrative tasks.

Lost access to your #WordPress #admin dashboard? Don't worry, this article has multiple solutions for you to try! Share on X

We know your first reaction to this error is to panic but don’t. Like any error, this one can be resolved as well. And in this article, we will teach you exactly how to do that along with going through all the different scenarios that could lead to this error.

So let’s get started, shall we?

What Caused the Issue

Man leaning on wall

You know most errors can have a couple of causes, and the same goes for this one.

The most common causes being:

  • Error establishing a database connection
  • White Screen of Death
  • Incorrect password issue
  • Loss of admin privileges

For each of these causes, we will present you with the possible solutions, but before that, there are some things you need to take care of.

What to Do Before Fixing the Issue

For everything in life, preparation is key. And when it comes to getting back into the wp-admin dashboard here are the steps you have to do beforehand:

Restore a backup – this shouldn’t really be viewed as a preparatory measure. Instead, it could be thought of as your first attempt at getting into your site. Why? Well because if you know exactly when your problem started, you can try restoring a backup that was created prior and with that remove the issue without much effort.

USB on white surface

Create a backup – So if restoring a backup didn’t work, the next thing you should do is create one. This is something you should be doing regularly, but especially before making any changes to your site, its code, or database just in case any additional issues arise.

Install an FTP client – some of the solutions we will present to you will require the help of an FTP client. Using the FTP client you will be able to access your web server and make the necessary changes and adjustments.

How to Fix the Issue

Error Establishing Database Connection

In the majority of cases, this error is caused by the inability to create a database connection. This could happen for a number of reasons such as problems with the database itself, a bad server, corrupted files, etc.

If that is the case for your site, you will get an error something along the lines of “One or more database tables are unavailable.

Obviously, now, what you need to do is, repair the database. And that can be done in two ways:

1. Adding the following line to the wp-config.php file:

define (‘WP_ALLOW_REPAIR’, true);

2. By following this guide:Error establishing Database connection in WordPress”.

White Screen of Death

Laptop showing white screen

Ahh, the white screen of death. A pretty self-explanatory issue. But in case you are confused, it is a white screen that appears every time you try to log in.

This is caused mostly because of a lack of space on the server (pretty common on shared hosting), a corrupted database, malware, or some other issue.

Regardless, to solve it, you can turn to a solution offered by the WP Reset plugin. That solution is called the Emergency Recovery Script.

WP Reset

The Emergency Recovery Script is a standalone script that will help you get rid of the white screen of death in no time. And the script being standalone means it will always work and is completely independent of any WP files.

The tool provides you with the following options that will have your site up and running again: 

  • disable/enable selected (or all) plugins
  • disable current theme
  • check all core files to see if some are missing or damaged and restore them
  • create a new admin user without logging in
  • repair user privileges
  • edit site and WP address

Besides that, you could also check out this blog post which covers the topic, pretty in-depth “WordPress White screen of death”.

Incorrect Password Issue

Unfortunately, when this is the case, that means you were most probably hacked. And now what you need to do is reset your WordPress password using phpMyAdmin.

Keep in mind that this will be kinda complicated for new users, but it will definitely solve your problem. Some hosting providers can do this for you, but if you want to do it on your own, here’s how:

So to start, open your cPanel (if your host uses it) and scroll down to the Database section where you will find phpMyAdmin.

cPanel up close

Next, log into your phpMyAdmin using your cPanel username and password.

Use an FTP client to open your root directory which is typically called public_html and then open your wp-config.php file. To do this you may need to download and open it in a text editor on your computer.

Once you do open it, look for the define() function named DB_NAME. In most cases, it is located at the top of the file underneath a comment.

Now, go back to phpMyAdmin and select the Databases tab. Next, select the database with the same name as the one you saw in the wp-config.file.

Within that database, you will see a table that has a lot of values with the “wp” prefix. The value that you need is wp_users. Once you find it, click on it. Keep in mind that there might be some letters between “wp” and “users”.

Next, you should see a smaller table with the names of the users on your site. Find the main admin account and click the Edit button next to it.

In the user_pass field will be your password, but you won’t be able to read it, because it’s encrypted in MD5. And since this field only accepts MD5 hashes, you’ll need to generate your new password in the same format.

This can be done using whichever MD5 hash generator you prefer. And all you need to do is enter your password into it, click generate or whatever else the button says, copy that, and paste it in the user_pass field.

Lastly, go to the bottom of the page, and click Save. You should now be able to log in with your new password, in an alphabetic format, not MD5 hash of course.

Loss of Admin Privileges

Stop sign up close

In the case of lost admin privileges, you might be able to login to WordPress but not to access your plugins, themes, etc.

The permissions could have been modified by someone without ill intentions, or they might have changed because of a hack since hackers love to delete your admin privileges.

In case it is a hack, you will have to add a new admin user to the database using phpMyAdmin. And here’s how:

  1. Log into cPanel and open phpMyAdmin
  2. Click on wp_users, then on Insert
  3. Fill out the columns you are presented with, making sure you pick an ID that isn’t in the database and that the user_status is set to 0. Then click Save changes
  4. Navigate to the left side of the screen, click on the wp_usersmeta table, and then on Insert
  5. Fill the columns as follows
    • unmeta_id – leave it blank (it’s generated automatically)
    • user_id – enter the ID number you picked earlier
    • meta_key – enter wp_capabilities.
    • meta_value – enter a:1:{s:13:”administrator”;b:1;}.
  6. Next, click Go and do the steps over again except this time enter the wp_user_level in the meta_key column and 10 in the meta_value column.
  7. Lastly, click Go again, and you’re done creating a new administrator account. You can now login to WordPress using that one.

Note: You need to make sure to insert the meta_value correctly. So it’s best you write it manually instead of copying and pasting it. That way you’ll avoid any errors.

Too Many Login Attempts

Limiting login attempts is a great method of stopping brute force attacks, but it’s also inconvenient since it can lock you out as well if you don’t whitelist your IP.

Since plugins are used in the majority of cases to limit login attempts, the plugin’s creators will probably have the solution for you.

To find it you can simply try googling [plugin name] + “locked out”.

Faulty Plugin(s)

Plugins tab

Another common reason for getting locked out or even experiencing the white screen of death is faulty plugins. Luckily, the solution for this is pretty simple and it also comes as part of the WP Reset plugin.

Simply use its rest plugins option to remove all your plugins. And no, you don’t need access to the WordPress admin dashboard in order to do this. You can make it happen with the help of the already-mentioned Emergency Recovery Script.

ERS plugins option

After you have deactivated the plugins and regained access to the admin dashboard, you can then start reactivating the plugins one by one to find the faulty one(s).

Faulty Theme

Another thing that might be at fault, is your theme. But just like with plugins the solution is simple. Simply deactivate the current one and activate a default WordPress theme.

Here’s how you do it:

  • First, if you don’t have one installed already, download a default WordPress theme, unpack it and upload it to your themes folder.
  • Next, rename the active theme’s directory so it gets deactivated and WordPress automatically switches to the default one.

You can also go the simpler route, and use the WP Reset Emergency Recovery Script for doing this as well.

Parse Error 

PHP code snippet

Last but not least, we have the parse error which is caused by incorrect code and is recognized by the notice “parse error: syntax error”

To fix it you need to:

  1. Open your site in any browser in order to take a closer look at the error message, which will provide you with a full path to the error.
  2. Find the error within the code. If you have recently made some changes to your site’s code, that’s the first place you should look at.
  3. Fix the error using an FTP client and the help of this guide.

Conclusion

Hopefully, this article was worth the read and helped you get back into the WordPress admin dashboard with full permissions.

We really did our best to explain things as clearly as possible, but if anything was left unsaid or not explained clearly enough, feel free to leave questions and feedback in the comments below!