Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
Cool. But is it possible to edit the array and disable and activate specific plugins? –  jnthnclrk Mar 10 '12 at 16:21
1  
Assuming you know the plugin's "slug" (eg. something retrieved with plugin_basename yes. You should take a look at the core functions activate_plugin and deactivate_plugins and see how they work to get an idea how to accomplish what you want here. –  chrisguitarguy Mar 10 '12 at 17:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.