WordPress deactivate a plugin via database?

2019-03-14 08:02发布

I have a wordpress script, wp-supercache, that I need to disable (as its cached on a nasty error), however, the error is causing the wp-admin redirect to fail, which means I can't get into the site to disable the plugin.

Any advice? I can access the database via cpanel.

标签: php wordpress
10条回答
Juvenile、少年°
2楼-- · 2019-03-14 08:51

To disable a specific plugin, you have to remove it from the serialized string that stores the list of all plugins - that's set in the option_value column of the wp_options table as discussed by @TimDurden. The specific format change you have to make is, taken shamelessly from teh Internet:

a:4:{
    i:0;s:19:"akismet/akismet.php";
    i:1;s:36:"google-sitemap-generator/sitemap.php";
    i:2;s:55:"google-syntax-highlighter/google_syntax_highlighter.php";
    i:3;s:29:"wp-swfobject/wp-swfobject.php";
}

That first set of characters - a:4 - designates an array and its length. Note also that each line in the list of plugins has an index. So:

  1. Decrement the index (from 4 to 3 in this case)
  2. In each line, decrement the number after the i:
  3. Remove the specific plugin you want to disable.

Update the value in the db using the new string you constructed from these steps:

update wp_options set option_value=<new value> where option_id=<id of this option>

Note that your table name might not be wp_options - you might have a prefix to add.

查看更多
爷的心禁止访问
3楼-- · 2019-03-14 08:52

You only need to rename the folder in /wp-content/plugins/ and the plugin will be automatically de-activated. Once it is de-activated, you will be able to login.

查看更多
Animai°情兽
4楼-- · 2019-03-14 08:53

Late answer,but answering as it will be useful to someone in the future. All the plugins are stored in the wp_options table in a serialized manner. U can edit this field manually. Or if you unserialize it using a function like in php using unserialize(), you will get an array. just modify it to remove the plugin you want to remove from that array, and serialize it back. then update the table. Thats it. If you want to know more about it here is a good article. It explains all about this.

查看更多
聊天终结者
5楼-- · 2019-03-14 08:53

Using this code you can activate your plugin from the functions.php:

function activate_plugin_via_php() {
    $active_plugins = get_option( 'active_plugins' );
    array_push($active_plugins, 'unyson/unyson.php'); /* Here just replace unyson plugin directory and plugin file*/
    update_option( 'active_plugins', $active_plugins );
}
add_action( 'init', 'activate_plugin_via_php' );
查看更多
登录 后发表回答