Programmatically installing & activating Wordpress plugins

Update

Today I use a shell loop with wp-cli to install and activate the plugins

Original Answer

For activating, I use some variant of this. suppose I had three plugins i wanted to activate ("cforms", "w3-total-cache", "wordpress-seo"). The convention is that their directory and plugin .php file are the same name:

$wordpress_path = "/path/to/my/wordpress/install";    
require_once( $wordpress_path . "/wp-load.php" ); //not sure if this line is needed
//activate_plugin() is here:
require_once(  $wordpress_path . "/wp-admin/includes/plugin.php");
$plugins = array("cforms",  "w3-total-cache",  "wordpress-seo");
foreach ($plugins as $plugin){
$plugin_path = $wordpress_path."wp-content/plugins/{$plugin}.php";
  activate_plugin($plugin_path);
}

Tags:

Php

Wordpress