最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to make sense of the active_plugins option_value to enable and disable certain plugins from the database?

programmeradmin5浏览0评论

Can anyone explain how to interpret and make sense of the active_plugins option_value string in WordPress. And then use this string/ array to disable and activate specific plugins?

Here is an example:

a:8:{i:0;s:21:"adrotate/adrotate.php";i:1;s:19:"akismet/akismet.php";i:2;s:33:"better-related/better-related.php";i:3;s:17:"clicky/clicky.php";i:4;s:49:"custom-post-permalinks/custom-post-permalinks.php";i:5;s:32:"disqus-comment-system/disqus.php";i:6;s:33:"export-to-text/export-to-text.php";i:7;s:36:"google-sitemap-generator/sitemap.php";}

Can anyone explain how to interpret and make sense of the active_plugins option_value string in WordPress. And then use this string/ array to disable and activate specific plugins?

Here is an example:

a:8:{i:0;s:21:"adrotate/adrotate.php";i:1;s:19:"akismet/akismet.php";i:2;s:33:"better-related/better-related.php";i:3;s:17:"clicky/clicky.php";i:4;s:49:"custom-post-permalinks/custom-post-permalinks.php";i:5;s:32:"disqus-comment-system/disqus.php";i:6;s:33:"export-to-text/export-to-text.php";i:7;s:36:"google-sitemap-generator/sitemap.php";}
Share Improve this question edited Mar 10, 2012 at 16:22 jnthnclrk asked Mar 10, 2012 at 10:09 jnthnclrkjnthnclrk 1,8454 gold badges25 silver badges52 bronze badges 1
  • You can use the find and replace function within the Migrate DB plugin to disable individual plugins. You can't activate a plugin this way. – Andrew Commented Dec 16, 2014 at 12:21
Add a comment  | 

3 Answers 3

Reset to default 8

That's a serialized array.

// Serialized:
a:8:{i:0;s:21:"adrotate/adrotate.php";i:1;s:19:"akismet/akismet.php";i:2;s:33:"better-related/better-related.php";i:3;s:17:"clicky/clicky.php";i:4;s:49:"custom-post-permalinks/custom-post-permalinks.php";i:5;s:32:"disqus-comment-system/disqus.php";i:6;s:33:"export-to-text/export-to-text.php";i:7;s:36:"google-sitemap-generator/sitemap.php";}

// dump:
var_dump( maybe_unserialize('a:8:{i:0;s:21:"adrotate/adrotate.php";i:1;s:19:"akismet/akismet.php";i:2;s:33:"better-related/better-related.php";i:3;s:17:"clicky/clicky.php";i:4;s:49:"custom-post-permalinks/custom-post-permalinks.php";i:5;s:32:"disqus-comment-system/disqus.php";i:6;s:33:"export-to-text/export-to-text.php";i:7;s:36:"google-sitemap-generator/sitemap.php";}') );

// Result
array(8) {
  [0]=>
  string(21) "adrotate/adrotate.php"
  [1]=>
  string(19) "akismet/akismet.php"
  [2]=>
  string(33) "better-related/better-related.php"
  [3]=>
  string(17) "clicky/clicky.php"
  [4]=>
  string(49) "custom-post-permalinks/custom-post-permalinks.php"
  [5]=>
  string(32) "disqus-comment-system/disqus.php"
  [6]=>
  string(33) "export-to-text/export-to-text.php"
  [7]=>
  string(36) "google-sitemap-generator/sitemap.php"
}

Use maybe_unserialize() or unserialize() to transform it back to an array.

It looks very heavy duty in comparison with JSON! Though also not too hard.

Here's mine before modification. I want to disable Google Authenticator to allow myself to log in again. My provider now provides HTTPS for free thankfully, though before this I relied on authenticator as a protection against password sniffing. It's still a very useful feature to have, HTTPS or not. So I intend to reset and re-enable it once my phone has a new token for it.

It looks like "Array, length 5" and for each item "Index, Length, Value". I've highlighted the entry for Authenticator. My modification was to delete this entry, modify the array length to 4 and reduce the index values for all subsequent entries.

Here's the diff showing the change. I've formatted it for easier read here. I wouldn't expect it to work if formatted like this!

I had more than a few times where I could NOT disable plugins on our Wordpress site, and the only avenue was database access. I could read/write to the DB, so I made this python tool to list the plugins in human-readable form; delete them from the list by line number; save the delete plugin entries to a backup file; and create a new PHP string to insert back into the database.

As I drew inspiration partly from this thread, I thought I'd add a link to it here: https://github/Solarbotics/Wordpress_plugin_managment_by_db

发布评论

评论列表(0)

  1. 暂无评论