0

I am looking for a way to activate a plugin via a SQL query. I am aware you can login and hit "activate" on the particular plugin, but I would like to automate the activation as part of a release process.

I came across this question which makes me think that it may not be possible as the activate plugins are stored in wp_options in a specific format.

I am using a heavily-modified version of WordPress 3.3.1.

1
  • 1
    What specific format are you talking about? The data has been serialized, that's it.
    – tfrommen
    Commented Oct 1, 2013 at 15:15

1 Answer 1

1

If your goal is automated plugin activation you don't have to do it via SQL. You could, of course, but why not use functionality that comes with WordPress?

As I mentioned in my comment, the data has been serialized so you just have to

  • unserialize the data,
  • add your plugin,
  • re-serialize the data,
  • and update the option.

Here is a code snippet for that:

$active_plugins = unserialize(get_option('active_plugins'));
if ($active_plugins && is_array($active_plugins)) {
    $active_plugins[] = 'PLUGIN-DIR/PLUGIN-FILE.php'; // as in 'akismet/akismet.php'
    update_option('active_plugins', serialize($active_plugins));
} else {
    // something went wrong...
}
3
  • How does your solution help to figure out a way to activate a WordPress plugin via a SQL query.? Commented Oct 1, 2013 at 16:49
  • @EugeneManuilov It does not. However, despite the title reads activate ... via SQL, the question itself asks for an automated plugin activation - and that is exactly what my answer provides... That being said, you're right in that I could/should indicate this in my answer.
    – tfrommen
    Commented Oct 1, 2013 at 17:45
  • that's better now ;) Commented Oct 1, 2013 at 17:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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