Turn on / off WP plugins via url hook

function plugin_switch($pluginname) {
// If these are set then let it do it's job!!! 

if ($_GET['optimize'] == 'activate') {    // Only activate it if plugin isn't active  if (!is_plugin_active('/autoptimize/autoptimize.php') ) { activate_plugins('/autoptimize/autoptimize.php', true);      } }   // If these are set then let it do it's job!!! if ($_GET['optimize'] == 'deactivate') {    // Only activate it if plugin isn't active  if (is_plugin_active('/autoptimize/autoptimize.php') ) { dactivate_plugins('/autoptimize/autoptimize.php', true);      } }

}

add_action( 'admin_init', 'plugin_switch' );