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

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";}

Related posts

Leave a Reply

3 comments

  1. 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.

  2. 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.

    active_plugins value before edit

    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!

    diff showing change made

  3. 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.com/Solarbotics/Wordpress_plugin_managment_by_db