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

Updated 02/17/2024, Posted 02/14/2024 by James Parsons James Parsons 0 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

Hi, I'm James Parsons! I founded Content Powered, a content marketing agency where I partner with businesses to help them grow through strategic content. With nearly twenty years of SEO and content marketing experience, I've had the joy of helping companies connect with their audiences in meaningful ways. I started my journey by building and growing several successful eCommerce companies solely through content marketing, and I love to share what I've learned along the way. You'll find my thoughts and insights in publications like Search Engine Watch, Search Engine Journal, Forbes, Entrepreneur, and Inc, among others. I've been fortunate to work with wonderful clients ranging from growing businesses to Fortune 500 companies like eBay and Expedia, and helping them shape their content strategies. My focus is on creating optimized content that resonates and converts. I'd love to connect – the best way to contact me is by scheduling a call or by email.