public function update_plugin($plugin_slug, $tag = 'master')
{
$plugin = null;
$is_plugin_active = false;
foreach ((array) Plugin::instance()->get_plugin_configs() as $config_entry) {
if ($config_entry->repo === $plugin_slug) {
$plugin = $config_entry;
break;
}
}
if (!$plugin) {
throw new \Exception('Plugin not found or not updatable with GitHub Updater: ' . $plugin_slug);
}
if (is_plugin_active($plugin->slug)) {
$is_plugin_active = true;
}
$this->get_remote_repo_meta($plugin);
$updates_transient = get_site_transient('update_plugins');
$update = array('slug' => $plugin->repo, 'plugin' => $plugin->slug, 'new_version' => null, 'url' => $plugin->uri, 'package' => $this->repo_api->construct_download_link(false, $tag));
$updates_transient->response[$plugin->slug] = (object) $update;
set_site_transient('update_plugins', $updates_transient);
$upgrader = new \Plugin_Upgrader($this->upgrader_skin);
$upgrader->upgrade($plugin->slug);
if ($is_plugin_active) {
$activate = is_multisite() ? activate_plugin($plugin->slug, null, true) : activate_plugin($plugin->slug);
if (!$activate) {
$this->upgrader_skin->messages[] = 'Plugin reactivated successfully.';
}
}
}