Activate and deactivate plugins from the database in WordPress

Enabling or disabling plugins directly in the database can be very useful, for example, if something happens to you like it did to me—I mistakenly deactivated a plugin, the website broke down, and a cold sweat ran down my back as I stared in horror at the white screen of death.

Although I had a database backup, I didn’t want to lose several hours of work, so I decided to activate the plugin directly in the database before restoring it.

How to do it? Access your database through phpMyAdmin and in the “wp_options” table (wp may have been replaced with another prefix), click edit and within the “option_name” column, look for the field “active_plugins“.

In this field, you may find code like this:

a:6:{i:0;s:39:"column-shortcodes/column-shortcodes.php";i:1;s:33:"essential-grid/essential-grid.php";i:2;s:45:"footer-pop-up-banner/footer-pop-up-banner.php";i:3;s:27:"js_composer/js_composer.php";i:4;s:39:"taxonomy-metadata/taxonomy-metadata.php";i:5;s:14:"types/wpcf.php";}

Let’s understand what each part means:

  • a:6 means we have 6 active plugins.
  • i:0; each plugin is preceded by i: and sequential numbers starting at zero.
  • s:39 the s means it’s a string of 39 characters, because “column-shortcodes/column-shortcodes.php” has 39 characters—no mystery there.
  • The order is not random. If there’s a “parent” plugin like WooCommerce, it must appear before its extensions (dependent plugins). If this order isn’t correct, the site won’t work.

If you want to deactivate all plugins at once, this is how the field appears with no active plugins (you can also leave it blank and it will regenerate automatically when refreshed):

a:0:{}

I had a problem after deactivating Visual Composer, a “parent” plugin, while other dependent plugins were still active. To activate only that plugin, the code was:

a:1:{i:0;s:27:"js_composer/js_composer.php";}

Once the problematic plugin is activated, we can access the WordPress admin and enable any remaining plugins. If you’re unsure what code to use, a trick is to use another website: deactivate all plugins and activate just the one you need, then copy and paste the generated code into your own database.

And always remember to back up your database. The easiest way is by using the WP Migrate plugin, and to optimize the database, the Optimize Database plugin—both are free.

Leave a Reply

Your email address will not be published. Required fields are marked *