WordPress: Activating a Plugin Manually

A client came to me recently with a broken site problem they simply couldn’t fix. They had de-activated a plugin that was so heavily ingrained into the site that all site functionality had ceased to work, meaning they could not access the site via the Dashboard (domain.com/wp-admin) to reactivate it.

Fortunately, there are a few options available to you in this instance.

1. Attempt to reactivate using functions.php

The first thing you may try is adding a function to your theme’s functions.php via FTP.

// Add this code to your theme's functions.php
    function activate_plugin_manually() {
        $active_plugins = get_option( 'active_plugins' );
        array_push($active_plugins, 'plugin-directory/filename.php'); /* Replace the plugin-directory and filename.php to match your main plugin file */
        update_option( 'active_plugins', $active_plugins );    
    }
    add_action( 'init', 'activate_plugin_manually' );

This will attempt to reactivate the plugin when the site loads.

2. Add your plugin to the WordPress “Must Use” folder.

Many people don’t realise that the mu-plugins folder is not a multi-user or multi-site folder, and in fact a “Must Use” folder. Plugins in this folder are loaded before all other plugins, so the simple fix in this case is to move the plugin out of your plugins folder and into wp-content/mu-plugins. If this folder doesn’t exist, create it with the permissions 755 and all files 644.

3. Activate your plugin via PHPMyAdmin

This method is by far the most complicated since you will need to find the name and value in your wp_options table of your database.

Locate the row with the option_name of “active_plugins” and you will see the value looks something like the following:

a:4:{
    i:0;s:25:"nameofplugin/filename.php";
    i:1;s:26:"nameofplugin/filename2.php";
    i:2;s:26:"nameofplugin/filename3.php";
    i:3;s:26:"nameofplugin/filename4.php";
}

To activate your plugin, you will need to add your plugin to the array of values, like so:
a:5:{
    i:0;s:25:"nameofplugin/filename.php";
    i:1;s:26:"nameofplugin/filename2.php";
    i:2;s:26:"nameofplugin/filename3.php";
    i:3;s:26:"nameofplugin/filename4.php";
    i:4;s:39:"nameofplugin/this-is-the-new-plugin.php";
}

HOWEVER… There are three things that are VERY important to note here:

1. The initial a:4 value has been increased to a:5 (the number of plugins)
2. The i:4 value must be increased from the previous row (the order in which the plugins load)
3. The s:39 is the number of characters in that filename string (count the number of characters in the line)

Hopefully, one of these methods will solve your problem.