$update_core = update_core($working_dir, $wp_dir);
$this->mmb_maintenance_mode(false);
if (is_wp_error($update_core)) {
'error' => $this->mmb_get_error($update_core),
public function upgrade_plugins($plugins = false)
if (!$plugins || empty($plugins)) {
'error' => 'No plugin files for upgrade.',
if (!function_exists('wp_update_plugins')) {
include_once ABSPATH.'wp-includes/update.php';
if (class_exists('Plugin_Upgrader')) {
$upgrader = new Plugin_Upgrader(mwp_container()->getUpdaterSkin());
$result = $upgrader->bulk_upgrade(array_keys($plugins));
foreach ($result as $plugin_slug => $plugin_info) {
if (!$plugin_info || is_wp_error($plugin_info)) {
$return[$plugin_slug] = $this->mmb_get_error($plugin_info);
$return[$plugin_slug] = 1;
'additional_updates' => $this->get_additional_plugin_updates($result),
'error' => 'Upgrade failed.',
'error' => 'WordPress update required first.',
private function get_additional_plugin_updates($plugin_upgrades)
if (empty($plugin_upgrades)) {
$additional_updates = array();
if (array_key_exists('woocommerce/woocommerce.php', $plugin_upgrades) && is_plugin_active('woocommerce/woocommerce.php') && $this->has_woocommerce_db_update()) {
$additional_updates['woocommerce/woocommerce.php'] = 1;
return $additional_updates;
private function has_woocommerce_db_update()
$current_db_version = get_option('woocommerce_db_version', null);
$current_wc_version = get_option('woocommerce_version');
if (version_compare($current_wc_version, '3.0.0', '<')) {
$latestUpdate = $this->get_wc_db_latest_update();
return !is_null($current_db_version) && !is_null($latestUpdate) &&
version_compare($current_db_version, $latestUpdate, '<');
private function get_wc_db_latest_update()
$regexp = "{'(\d+\.)(\d+\.)(\d+)'}"; // version in single quote '1.0.0', '2.1.3', '3.1.22' etc
$fileName = WP_PLUGIN_DIR.'/woocommerce/includes/class-wc-install.php';
if (file_exists($fileName)) {
$fileContent = file_get_contents($fileName);
preg_match_all($regexp, $fileContent, $matches);
if (!empty($matches[0])) {
$latestUpdate = trim(end($matches[0]), "'");
public function upgrade_themes($themes = false)
if (!$themes || empty($themes)) {
'error' => 'No theme files for upgrade.',
if (!function_exists('wp_update_themes')) {
include_once ABSPATH.'wp-includes/update.php';
if (class_exists('Theme_Upgrader')) {
$upgrader = new Theme_Upgrader(mwp_container()->getUpdaterSkin());
$result = $upgrader->bulk_upgrade($themes);
foreach ($result as $theme_tmp => $theme_info) {
if (is_wp_error($theme_info) || empty($theme_info)) {
$return[$theme_tmp] = $this->mmb_get_error($theme_info);
'error' => 'Upgrade failed.',
'error' => 'WordPress update required first',
public function upgrade_translations()
include_once ABSPATH.'wp-admin/includes/class-wp-upgrader.php';
if (class_exists('Language_Pack_Upgrader')) {
$upgrader = new Language_Pack_Upgrader(mwp_container()->getUpdaterSkin());
$result = $upgrader->bulk_upgrade();
foreach ($result as $translate_tmp => $translate_info) {
if (is_wp_error($translate_info) || empty($translate_info)) {
$return = $this->mmb_get_error($translate_info);
return array('upgraded' => $return);
'error' => 'Upgrade failed.',
'error' => 'WordPress update required first',
public function get_upgradable_plugins()
$current = $this->mmb_get_transient('update_plugins');
$upgradable_plugins = array();
if (!empty($current->response)) {
if (!function_exists('get_plugin_data')) {
include_once ABSPATH.'wp-admin/includes/plugin.php';
foreach ($current->response as $plugin_path => $plugin_data) {
$data = get_plugin_data(WP_PLUGIN_DIR.'/'.$plugin_path, false, false);
if (strlen($data['Name']) > 0 && strlen($data['Version']) > 0) {
$current->response[$plugin_path]->name = $data['Name'];
$current->response[$plugin_path]->old_version = $data['Version'];
$current->response[$plugin_path]->file = $plugin_path;
unset($current->response[$plugin_path]->upgrade_notice);
$upgradable_plugins[] = $current->response[$plugin_path];
return $upgradable_plugins;
public function get_upgradable_themes()
if (function_exists('wp_get_themes')) {
$all_themes = wp_get_themes();
$upgrade_themes = array();
$current = $this->mmb_get_transient('update_themes');
if (empty($current->response)) {
foreach ((array)$all_themes as $theme_template => $theme_data) {
foreach ($current->response as $current_themes => $theme) {
if ($theme_data->Stylesheet !== $current_themes) {
if (strlen($theme_data->Name) === 0 || strlen($theme_data->Version) === 0) {
$current->response[$current_themes]['name'] = $theme_data->Name;
$current->response[$current_themes]['old_version'] = $theme_data->Version;
$current->response[$current_themes]['theme_tmp'] = $theme_data->Stylesheet;
$upgrade_themes[] = $current->response[$current_themes];
$all_themes = get_themes();
$upgrade_themes = array();
$current = $this->mmb_get_transient('update_themes');
if (!empty($current->response)) {
foreach ((array)$all_themes as $theme_template => $theme_data) {
if (isset($theme_data['Parent Theme']) && !empty($theme_data['Parent Theme'])) {
if (isset($theme_data['Name']) && in_array($theme_data['Name'], $filter)) {
foreach ($current->response as $current_themes => $theme) {
if ($theme_data['Template'] == $current_themes) {
if (strlen($theme_data['Name']) > 0 && strlen($theme_data['Version']) > 0) {
$current->response[$current_themes]['name'] = $theme_data['Name'];
$current->response[$current_themes]['old_version'] = $theme_data['Version'];
$current->response[$current_themes]['theme_tmp'] = $theme_data['Template'];
$upgrade_themes[] = $current->response[$current_themes];
public function get_upgradable_translations()
$transients = array('update_core' => 'core', 'update_plugins' => 'plugins', 'update_themes' => 'themes');
foreach ($transients as $transient => $type) {
$transient = get_site_transient($transient);
if (empty($transient->translations)) {
foreach ($transient->translations as $translation) {
$updates[$type][] = (object)$translation;
public function edit($args)
if ($type == 'plugins') {
$return['plugins'] = $this->edit_plugins($args);
} elseif ($type == 'themes') {
$return['themes'] = $this->edit_themes($args);
public function edit_plugins($args)
foreach ($items as $item) {
switch ($items_edit_action) {
$result = activate_plugin($item['path'], '', $item['networkWide']);
$result = deactivate_plugins(
$result = delete_plugins(
if (is_wp_error($result)) {
'error' => $result->get_error_message(),
} elseif ($result === false) {
'error' => "Failed to perform action.",
$return[$item['name']] = $result;
public function edit_themes($args)
foreach ($items as $item) {
switch ($items_edit_action) {
switch_theme($item['path'], $item['stylesheet']);
$result = delete_theme($item['stylesheet']);
if (is_wp_error($result)) {
'error' => $result->get_error_message(),
} elseif ($result === false) {
'error' => "Failed to perform action.",
$return[$item['name']] = $result;