How to Prevent a WP Website Lockout With "Critical Errors"

James Parsons by James Parsons Updated Feb 17th, 2024 2 Comments

WordPress will lock you out of your site if one of your plugins has a critical error. This makes it tough to fix the issue. You'll need to get FTP access to disable the plugin(s) responsible, and depending on your server setup, this may be fairly complicated. In some organizations, you'll need to go through several chains of command to get the site working again.

I put together this script to temporarily disable all WordPress plugins in the event of an emergency, which will help you regain access to your /wp-admin/ dashboard.

This requires the admin to be currently signed into WordPress in order for this to work. This is perfect for situations where a plugin update just broke your site and it's displaying the classic error:

"There has been a critical error on this website. Please check your site admin email inbox for instructions.
Learn more about troubleshooting WordPress."

If your site breaks and you see this warning after updating a plugin, you can load this script and all plugins will be disabled, then you can start re-enabling them one by one until you find the culprit.

Simply upload this to your WordPress folder and name it something that you'll remember. You can also set a password on this file in-case somebody happens to stumble across it:

<?php
$secret_password = 'YourSecretPassword';

require_once('wp-load.php');

if (!isset($_GET['password']) || $_GET['password'] !== $secret_password) {
die('Access denied: Incorrect or no password provided.');
}

update_option('active_plugins', array());

echo 'All plugins have been disabled.';

Let's say you name it "disable-plugins.php". When you visit it, you would add the password to it, like this:

yourdomain.com/disable-plugins.php?YourSecretPassword

You should get a message that all plugins have been disabled, and your access to your WordPress site is restored.

If you don't have FTP access, you can upload this PHP file with a plugin like File Manager for WordPress.

It may not come in handy right away, but when you're locked out of your site, you'll be happy you had this handy little script! Please let me know what you think in the comments.

Related Code Snippets

Written by James Parsons

James Parsons is the founder and CEO of Content Powered, a premier content marketing agency that leverages nearly two decades of his experience in content marketing to drive business growth. Renowned for founding and scaling multi-million dollar eCommerce businesses through strategic content marketing, James has become a trusted voice in the industry, sharing his insights in Search Engine Watch, Search Engine Journal, Forbes, Entrepreneur, Inc, and other leading publications. His background encompasses key roles across various agencies, contributing to the content strategies of major brands like eBay and Expedia. James's expertise spans SEO, conversion rate optimization, and effective content strategies, making him a pivotal figure in the industry.