function wpgrade_ajax_upgradestep_install_package() { if (function_exists('set_time_limit')) { set_time_limit(300); } // 5min time limit // @todo replace hardcoded path with tempfile $uploads = wp_upload_dir(); $download_file = $uploads['path'] . '/wpgrade-' . wpgrade::shortname() . '-theme.tmp'; // Default Data Structure // ---------------------- $response = array('status' => 'success', 'data' => array('state' => 'error', 'info' => null, 'html' => wpgrade::coreview('upgrader/unknown-ajax-error' . EXT))); // Process Install // --------------- $theme_data = wp_get_theme(); $theme_name = $theme_data->template; $upgrader = new WPGradeAjaxUpgrader(); // load error pages into memory; if something goes wrong the files // might not even exist anymore $internal_error_view = wpgrade::coreview('upgrader/internal-install-error' . EXT); $error_while_installing = wpgrade::coreview('upgrader/error-while-installing-theme' . EXT); try { if ($upgrader->install($theme_name, $download_file)) { $response['data'] = array('state' => 'success', 'html' => null); } else { // failed to backup file $response['data'] = array('state' => 'error', 'html' => strtr($error_while_installing, array(':error_list' => '<li>' . implode('</li><li>', $upgrader->errors()) . '</li>'))); } } catch (Exception $e) { $response['data'] = array('state' => 'error', 'html' => $internal_error_view); } echo json_encode($response); die; }