public function install_remote_file($params) { global $wp_filesystem; extract($params); if (!isset($package) || empty($package)) { return array('error' => '<p>No files received. Internal error.</p>'); } if (!$this->is_server_writable()) { return array('error' => 'Failed, please <a target="_blank" href="http://managewp.com/user-guide/faq/my-pluginsthemes-fail-to-update-or-i-receive-a-yellow-ftp-warning">add FTP details</a>'); } if (defined('WP_INSTALLING') && file_exists(ABSPATH . '.maintenance')) { return array('error' => '<p>Site under maintanace.</p>'); } if (!class_exists('WP_Upgrader')) { include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; } /** @handled class */ $upgrader = new WP_Upgrader(mwp_container()->getUpdaterSkin()); $upgrader->init(); $destination = $type == 'themes' ? WP_CONTENT_DIR . '/themes' : WP_PLUGIN_DIR; $clear_destination = isset($clear_destination) ? $clear_destination : false; foreach ($package as $package_url) { $key = basename($package_url); $install_info[$key] = @$upgrader->run(array('package' => $package_url, 'destination' => $destination, 'clear_destination' => $clear_destination, 'clear_working' => true, 'hook_extra' => array())); } if ($activate) { if ($type == 'plugins') { include_once ABSPATH . 'wp-admin/includes/plugin.php'; $all_plugins = get_plugins(); foreach ($all_plugins as $plugin_slug => $plugin) { $plugin_dir = preg_split('/\\//', $plugin_slug); foreach ($install_info as $key => $install) { if (!$install || is_wp_error($install)) { continue; } if ($install['destination_name'] == $plugin_dir[0]) { $install_info[$key]['activated'] = activate_plugin($plugin_slug, '', false); } } } } else { if (count($install_info) == 1) { global $wp_themes; include_once ABSPATH . 'wp-includes/theme.php'; $wp_themes = null; unset($wp_themes); //prevent theme data caching if (function_exists('wp_get_themes')) { $all_themes = wp_get_themes(); foreach ($all_themes as $theme_name => $theme_data) { foreach ($install_info as $key => $install) { if (!$install || is_wp_error($install)) { continue; } if ($theme_data->Template == $install['destination_name']) { $install_info[$key]['activated'] = switch_theme($theme_data->Template, $theme_data->Stylesheet); } } } } else { $all_themes = get_themes(); foreach ($all_themes as $theme_name => $theme_data) { foreach ($install_info as $key => $install) { if (!$install || is_wp_error($install)) { continue; } if ($theme_data['Template'] == $install['destination_name']) { $install_info[$key]['activated'] = switch_theme($theme_data['Template'], $theme_data['Stylesheet']); } } } } } } } // Can generate "E_NOTICE: ob_clean(): failed to delete buffer. No buffer to delete." @ob_clean(); $this->mmb_maintenance_mode(false); if (mwp_container()->getRequestStack()->getMasterRequest()->getProtocol() >= 1) { // WP_Error won't get JSON encoded, so unwrap the error here. foreach ($install_info as $key => $value) { if ($value instanceof WP_Error) { $install_info[$key] = array('error' => $value->get_error_message(), 'code' => $value->get_error_code()); } } } return $install_info; }