protected function install() { foreach ($this->themes as $theme) { $skin = new Jetpack_Automatic_Install_Skin(); $upgrader = new Theme_Upgrader($skin); $link = $this->download_links[$theme]; $result = $upgrader->install($link); if (file_exists($link)) { // Delete if link was tmp local file unlink($link); } if (!$this->bulk && is_wp_error($result)) { return $result; } if (!$result) { $error = $this->log[$theme]['error'] = __('An unknown error occurred during installation', 'jetpack'); } elseif (!self::is_installed_theme($theme)) { $error = $this->log[$theme]['error'] = __('There was an error installing your theme', 'jetpack'); } else { $this->log[$theme][] = $upgrader->skin->get_upgrade_messages(); } } if (!$this->bulk && isset($error)) { return new WP_Error('install_error', $error, 400); } return true; }
protected function install() { foreach ($this->themes as $theme) { /** * Filters whether to use an alternative process for installing a WordPress.com theme. * The alternative process can be executed during the filter. * * The filter can also return an instance of WP_Error; in which case the endpoint response will * contain this error. * * @module json-api * * @since 4.4.2 * * @param bool $use_alternative_install_method Whether to use the alternative method of installing * a WPCom theme. * @param string $theme_slug Theme name (slug). If it is a WPCom theme, * it should be suffixed with `-wpcom`. */ $result = apply_filters('jetpack_wpcom_theme_install', false, $theme); $skin = null; $upgrader = null; $link = null; // If the alternative install method was not used, use the standard method. if (!$result) { $skin = new Jetpack_Automatic_Install_Skin(); $upgrader = new Theme_Upgrader($skin); $link = $this->download_links[$theme]; $result = $upgrader->install($link); } if (file_exists($link)) { // Delete if link was tmp local file unlink($link); } if (!$this->bulk && is_wp_error($result)) { return $result; } if (!$result) { $error = $this->log[$theme]['error'] = __('An unknown error occurred during installation', 'jetpack'); } elseif (!self::is_installed_theme($theme)) { $error = $this->log[$theme]['error'] = __('There was an error installing your theme', 'jetpack'); } elseif ($upgrader) { $this->log[$theme][] = $upgrader->skin->get_upgrade_messages(); } } if (!$this->bulk && isset($error)) { return new WP_Error('install_error', $error, 400); } return true; }
/** * AJAX handler for installing a theme. * * @since 4.X.0 */ function wp_ajax_install_theme() { check_ajax_referer('updates'); if (empty($_POST['slug'])) { wp_send_json_error(array('errorCode' => 'no_theme_specified')); } $status = array('install' => 'theme', 'slug' => sanitize_key($_POST['slug'])); if (!current_user_can('install_themes')) { $status['error'] = __('You do not have sufficient permissions to install themes on this site.'); wp_send_json_error($status); } include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; include_once ABSPATH . 'wp-admin/includes/theme.php'; $api = themes_api('theme_information', array('slug' => $status['slug'], 'fields' => array('sections' => false))); if (is_wp_error($api)) { $status['error'] = $api->get_error_message(); wp_send_json_error($status); } $upgrader = new Theme_Upgrader(new Automatic_Upgrader_Skin()); $result = $upgrader->install($api->download_link); if (defined('WP_DEBUG') && WP_DEBUG) { $status['debug'] = $upgrader->skin->get_upgrade_messages(); } if (is_wp_error($result)) { $status['error'] = $result->get_error_message(); wp_send_json_error($status); } else { if (is_null($result)) { global $wp_filesystem; $status['errorCode'] = 'unable_to_connect_to_filesystem'; $status['error'] = __('Unable to connect to the filesystem. Please confirm your credentials.'); // Pass through the error from WP_Filesystem if one was raised. if ($wp_filesystem instanceof WP_Filesystem_Base && is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) { $status['error'] = $wp_filesystem->errors->get_error_message(); } wp_send_json_error($status); } } // Never switch to theme (unlike plugin activation). // See WP_Theme_Install_List_Table::_get_theme_status() if we wanted to check on post-install status. wp_send_json_success($status); }
function install() { $args = $this->input(); if (isset($args['zip'][0]['id'])) { $attachment_id = $args['zip'][0]['id']; $local_file = get_attached_file($attachment_id); if (!$local_file) { return new WP_Error('local-file-does-not-exist'); } $skin = new Jetpack_Automatic_Install_Skin(); $upgrader = new Theme_Upgrader($skin); $pre_install_list = wp_get_themes(); $result = $upgrader->install($local_file); // clean up. wp_delete_attachment($attachment_id, true); if (is_wp_error($result)) { return $result; } $after_install_list = wp_get_themes(); $plugin = array_values(array_diff(array_keys($after_install_list), array_keys($pre_install_list))); if (!$result) { $error_code = $upgrader->skin->get_main_error_code(); $message = $upgrader->skin->get_main_error_message(); if (empty($message)) { $message = __('An unknown error occurred during installation', 'jetpack'); } if ('download_failed' === $error_code) { $error_code = 'no_package'; } return new WP_Error($error_code, $message, 400); } if (empty($plugin)) { return new WP_Error('theme_already_installed'); } $this->themes = $plugin; $this->log[$plugin[0]] = $upgrader->skin->get_upgrade_messages(); return true; } return new WP_Error('no_theme_installed'); }
/** * Ajax handler for installing a theme. * * @since 4.6.0 * * @see Theme_Upgrader */ function wp_ajax_install_theme() { check_ajax_referer('updates'); if (empty($_POST['slug'])) { wp_send_json_error(array('slug' => '', 'errorCode' => 'no_theme_specified', 'errorMessage' => __('No theme specified.'))); } $slug = sanitize_key(wp_unslash($_POST['slug'])); $status = array('install' => 'theme', 'slug' => $slug); if (!current_user_can('install_themes')) { $status['errorMessage'] = __('Sorry, you are not allowed to install themes on this site.'); wp_send_json_error($status); } include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; include_once ABSPATH . 'wp-admin/includes/theme.php'; $api = themes_api('theme_information', array('slug' => $slug, 'fields' => array('sections' => false))); if (is_wp_error($api)) { $status['errorMessage'] = $api->get_error_message(); wp_send_json_error($status); } $skin = new WP_Ajax_Upgrader_Skin(); $upgrader = new Theme_Upgrader($skin); $result = $upgrader->install($api->download_link); if (defined('WP_DEBUG') && WP_DEBUG) { $status['debug'] = $skin->get_upgrade_messages(); } if (is_wp_error($result)) { $status['errorCode'] = $result->get_error_code(); $status['errorMessage'] = $result->get_error_message(); wp_send_json_error($status); } elseif (is_wp_error($skin->result)) { $status['errorCode'] = $skin->result->get_error_code(); $status['errorMessage'] = $skin->result->get_error_message(); wp_send_json_error($status); } elseif ($skin->get_errors()->get_error_code()) { $status['errorMessage'] = $skin->get_error_messages(); wp_send_json_error($status); } elseif (is_null($result)) { global $wp_filesystem; $status['errorCode'] = 'unable_to_connect_to_filesystem'; $status['errorMessage'] = __('Unable to connect to the filesystem. Please confirm your credentials.'); // Pass through the error from WP_Filesystem if one was raised. if ($wp_filesystem instanceof WP_Filesystem_Base && is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) { $status['errorMessage'] = esc_html($wp_filesystem->errors->get_error_message()); } wp_send_json_error($status); } $status['themeName'] = wp_get_theme($slug)->get('Name'); if (current_user_can('switch_themes')) { if (is_multisite()) { $status['activateUrl'] = add_query_arg(array('action' => 'enable', '_wpnonce' => wp_create_nonce('enable-theme_' . $slug), 'theme' => $slug), network_admin_url('themes.php')); } else { $status['activateUrl'] = add_query_arg(array('action' => 'activate', '_wpnonce' => wp_create_nonce('switch-theme_' . $slug), 'stylesheet' => $slug), admin_url('themes.php')); } } if (!is_multisite() && current_user_can('edit_theme_options') && current_user_can('customize')) { $status['customizeUrl'] = add_query_arg(array('return' => urlencode(network_admin_url('theme-install.php', 'relative'))), wp_customize_url($slug)); } /* * See WP_Theme_Install_List_Table::_get_theme_status() if we wanted to check * on post-install status. */ wp_send_json_success($status); }
static function install_theme() { check_ajax_referer(self::AJAX_NONCE, 'nonce'); $theme_id = $_REQUEST['themeId']; $theme = wp_get_theme($theme_id); if (!$theme->exists()) { include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; include_once ABSPATH . 'wp-admin/includes/theme-install.php'; $theme_info = themes_api('theme_information', array('slug' => $theme_id, 'fields' => array('sections' => false, 'tags' => false))); error_log(print_r($theme_info, true)); if (is_wp_error($theme_info)) { wp_send_json_error('Could not look up theme ' . $theme_id . ': ' . $theme_info->get_error_message()); die; } else { $upgrader = new Theme_Upgrader(new Automatic_Upgrader_Skin()); $install_response = $upgrader->install($theme_info->download_link); if (is_wp_error($install_response)) { wp_send_json_error('Could not install theme: ' . $install_response->get_error_message()); die; } elseif (!$install_response) { wp_send_json_error('Could not install theme (unspecified server error)'); die; } } } wp_send_json_success($theme_id); }
/** * Install a new plugin. * * @since 4.0.0 * @param int $pid The project ID. * @param string $error Output parameter. Holds error message. * @param bool $die_on_error If set to false the function will return * false instead of die(). * @return bool True on success. */ public function install_project($pid, &$error = false, $die_on_error = true) { if ($this->is_project_installed($pid)) { if ($die_on_error) { wp_send_json_error(array('message' => __('Already installed', 'wdpmudev'))); } else { return false; } } $project = WPMUDEV_Dashboard::$site->get_project_infos($pid); // Make sure Upfront is available before an upfront theme is installed. if ($project->need_upfront && !$this->is_upfront_installed()) { $this->install_project($this->id_upfront, $error, false); } // For plugins_api.. include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; ob_start(); // Save on a bit of bandwidth. $api = plugins_api('plugin_information', array('slug' => 'wpmudev_install-' . $pid, 'fields' => array('sections' => false))); if (is_wp_error($api)) { if ($die_on_error) { wp_send_json_error(array('message' => __('No data found', 'wpmudev'))); } else { return false; } } $skin = new Automatic_Upgrader_Skin(); /* * Set before the update: * WP will refresh local cache via action-hook before the install() * method is finished. That refresh call must scan the FS again. */ $this->flush_fs_cache = true; $this->flush_info_cache = true; switch ($project->type) { case 'plugin': $upgrader = new Plugin_Upgrader($skin); $upgrader->install($api->download_link); break; case 'theme': $upgrader = new Theme_Upgrader($skin); $upgrader->install($api->download_link); break; } $details = ob_get_clean(); if (is_wp_error($skin->result)) { $error = $skin->result->get_error_message(); $this->refresh_local_projects('remote'); return false; } // API call to inform wpmudev site about the change. $this->refresh_local_projects('remote'); // Fetch latest project details. $project = WPMUDEV_Dashboard::$site->get_project_infos($pid); if (!$project->is_installed && !$error) { $error = __('Installation failed. Maybe wrong folder permissions.', 'wpmudev'); } return $project->is_installed; }
function wp_install_themes($array) { require_once $this->data['dir'] . '/wp-admin/includes/class-wp-upgrader.php'; global $WPQI_Installer_Skin; $WPQI_Installer_Skin(); $first = true; foreach ($array as $name) { if (!$name) { continue; } $is_url = preg_match("/^(http|https):\\/\\//i", $name); $url = $is_url ? $name : "https://downloads.wordpress.org/theme/{$name}.zip"; $upgrader = new Theme_Upgrader(new WPQI_Installer_Skin()); $upgrader->install($url); if ($first) { switch_theme($name); $first = false; } } wp_clean_themes_cache(); }
private function install_theme($theme_slug) { include_once ABSPATH . 'wp-admin/includes/theme-install.php'; //for themes_api.. $api = themes_api('theme_information', array('slug' => $theme_slug, 'fields' => array('sections' => false, 'tags' => false))); if (is_wp_error($api)) { wp_die($api); } wp_enqueue_script('customize-loader'); $title = sprintf(esc_html__('Installing theme: %s', '1and1-wordpress-wizard'), $api->name . ' ' . $api->version); include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; //for theme installer include_once 'theme-installer-skin.php'; //for the 1&1 installer skin $installer = new Theme_Upgrader(new One_And_One_Theme_Installer_Skin(array('title' => $title, 'theme' => $theme_slug))); $installer->install($api->download_link); }
function install_theme($name, $values) { include_once ABSPATH . 'wp-admin/includes/theme-install.php'; //for themes_api.. if ($values['url']) { $download_link = $values['url']; } else { $api = themes_api('theme_information', array('slug' => $theme, 'fields' => array('sections' => false))); //Save on a bit of bandwidth. if (is_wp_error($api)) { return WP_Error(__('Failed to contact theme API', 'ls-installer'), $api); } $download_link = $api->download_link; } $title = sprintf(__('Installing Theme: %s', 'ls-installer'), $values['label']); $theme = $name; $type = 'web'; //Install theme type, From Web or an Upload. $upgrader = new Theme_Upgrader(new LSInstaller_Theme_Installer_Skin(compact('title', 'theme', 'api'))); $upgrader->install($download_link); return $upgrader->result; }
/** * [doInstallUpdate description] * @param [type] $update_id [description] * @param [type] $build_url [description] * @param [type] $package_url [description] * @return [type] [description] */ public function doInstallUpdate($update_row) { global $wp_filesystem; /* // Parse Update ID $update_keys = array('type', 'element', 'version', 'locale'); $update_vals = explode( ':', $update_row->update_id ); $update_rule = new wbSiteManager_Params( array_combine(array_intersect_key($update_keys, $update_vals), array_intersect_key($update_vals, $update_keys)) ); if( empty($update_rule->type) ){ $this->out('Invalid Update ID: ' . $update_id); return false; } $this->out('Processing Update ID: '. $update_id); */ // Switch Type $this->out('Processing Update ID: ' . $update_row->update_id); switch ($update_row->type) { case 'core': // Load Update Record $remoteUrl = 'update-core.php?action=do-core-upgrade'; $reinstall = false; if ($update_row->version == $update_row->installed_version) { $reinstall = true; $remoteUrl = 'update-core.php?action=do-core-reinstall'; } $update = find_core_update($update_row->version, $update_row->get('locale', 'en_US')); if (!$update) { $this->out(' - Failed to Load Update'); return false; } if ($reinstall) { $update->response = 'reinstall'; } // Confirm Write Access $allow_relaxed_file_ownership = isset($update->new_files) && !$update->new_files; if (false === ($credentials = request_filesystem_credentials($remoteUrl, '', false, ABSPATH, array('version', 'locale'), $allow_relaxed_file_ownership))) { $this->out(' - Invalid File Permission'); return false; } if (!WP_Filesystem($credentials, ABSPATH, $allow_relaxed_file_ownership)) { $this->out(' - Failed to load File Permissions'); return false; } if ($wp_filesystem->errors->get_error_code()) { foreach ($wp_filesystem->errors->get_error_messages() as $message) { $this->out(' - File Error: ' . $message); } return false; } // Run Update $upgrader_skin = new wbSiteManager_WP_Upgrader_Skin(array(), $this); $upgrader = new Core_Upgrader($upgrader_skin); $result = $upgrader->upgrade($update, array('allow_relaxed_file_ownership' => $allow_relaxed_file_ownership)); $response_html = explode("\n", strip_tags(ob_get_clean())); ob_end_clean(); if (is_wp_error($result)) { if ($result->get_error_data() && is_string($result->get_error_data())) { $message = $result->get_error_message() . ': ' . $result->get_error_data(); } else { $message = $result->get_error_message(); } $this->out(' - Update Error: ' . $message); if ('up_to_date' != $result->get_error_code()) { $this->out(' - Insallation Failed'); } return false; } // Clear Cache set_site_transient('update_core', null); break; case 'plugin': // Install vs Upgrade if ($install) { // Get Plugins API $plugin_api = plugins_api('plugin_information', array('slug' => $update_row->extension_id, 'fields' => array('short_description' => false, 'sections' => false, 'requires' => false, 'rating' => false, 'ratings' => false, 'downloaded' => false, 'last_updated' => false, 'added' => false, 'tags' => false, 'compatibility' => false, 'homepage' => false, 'donate_link' => false))); // Load Plugin Updater $upgrader = new Plugin_Upgrader(new wbSiteManager_Plugin_Upgrader_Skin(array('title' => 'Install Plugin: ' . $update_row->extension_id . ' v' . $update_row->version, 'nonce' => 'install-plugin_' . $update_row->extension_id, 'url' => 'update.php?action=install-plugin&plugin=' . urlencode($update_row->extension_id), 'plugin' => $update_row->extension_id, 'api' => $api), $this)); $upgrader->install($plugin_api->download_link); } else { // Load Plugin Updater $upgrader = new Plugin_Upgrader(new wbSiteManager_Plugin_Upgrader_Skin(array('title' => 'Upgrade Plugin: ' . $update_row->extension_id . ' v' . $update_row->version, 'nonce' => 'upgrade-plugin_' . $update_row->extension_id, 'url' => 'update.php?action=upgrade-plugin&plugin=' . urlencode($update_row->extension_id), 'plugin' => $update_row->extension_id), $this)); $upgrader->upgrade($update_row->extension_id); } // Process Result if (empty($upgrader->result)) { $this->out(' - Installation Failed'); return false; } // Clear Cache // set_site_transient( 'update_core', null ); break; case 'theme': // Install vs Upgrade if ($install) { // Load API $api = themes_api('theme_information', array('slug' => $update_row->extension_id, 'fields' => array('sections' => false, 'tags' => false))); // Load Theme Updater $upgrader = new Theme_Upgrader(new wbSiteManager_Theme_Upgrader_Skin(array('title' => 'Install Theme: ' . $update_row->extension_id, 'nonce' => 'install-theme_' . $update_row->extension_id, 'url' => 'update.php?action=install-theme&theme=' . urlencode($update_row->extension_id), 'theme' => $update_row->extension_id, 'api' => $api), $this)); $upgrader->install($api->download_link); } else { // Load Theme Updater $upgrader = new Theme_Upgrader(new wbSiteManager_Theme_Upgrader_Skin(array('title' => 'Upgrade Theme: ' . $update_row->extension_id, 'nonce' => 'upgrade-theme_' . $update_row->extension_id, 'url' => 'update.php?action=upgrade-theme&theme=' . urlencode($update_row->extension_id), 'theme' => $update_row->extension_id), $this)); $upgrader->upgrade($update_row->extension_id); } // Process Result if (empty($upgrader->result)) { $this->out(' - Installation Failed'); return false; } // Clear Cache // set_site_transient( 'update_core', null ); break; } // Complete $this->out(' - Update Success'); return true; }
private function install_themes($themes) { require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; require_once ABSPATH . 'wp-admin/includes/file.php'; require_once ABSPATH . 'wp-admin/includes/plugin.php'; require_once ABSPATH . 'wp-admin/includes/theme.php'; require_once $GLOBALS['ithemes_sync_path'] . '/upgrader-skin.php'; $upgrader = new Theme_Upgrader(new Ithemes_Sync_Upgrader_Skin()); $results = array(); foreach ((array) $themes as $theme) { Ithemes_Sync_Functions::set_time_limit(300); if (preg_match('{^(http|https|ftp)://}i', $theme)) { $result = $upgrader->install($theme); } else { $api = themes_api('theme_information', array('slug' => $theme, 'fields' => array('sections' => false, 'tags' => false))); if (is_wp_error($api)) { $result = $api; } else { $result = $upgrader->install($api->download_link); } } if (is_wp_error($result)) { $results[$theme]['error'] = array('error_code' => $result->get_error_code(), 'error_details' => $result->get_error_message()); } else { $results[$theme]['result'] = $result; $theme_info = $upgrader->theme_info(); $results[$theme]['name'] = $theme_info->get('Name'); $results[$theme]['version'] = $theme_info->get('Version'); if (is_object($theme_info) && is_callable(array($theme_info, 'get_stylesheet'))) { $results[$theme]['slug'] = basename($theme_info->get_stylesheet()); } else { if (isset($upgrader->result) && !empty($upgrader->result['destination_name'])) { $results[$theme]['slug'] = $upgrader->result['destination_name']; } } if (true === $result) { $results[$theme]['success'] = true; } } } Ithemes_Sync_Functions::refresh_theme_updates(); return $results; }
/** * Install remote plugin or theme. * @param $type * * @return bool */ public function install($type) { if (isset($_POST['option_page']) && 'github_updater_install' == $_POST['option_page']) { if (empty($_POST['github_updater_branch'])) { $_POST['github_updater_branch'] = 'master'; } /* * Exit early if no repo entered. */ if (empty($_POST['github_updater_repo'])) { echo '<h3>'; _e('A repository URI is required.', 'github-updater'); echo '</h3>'; return false; } /* * Transform URI to owner/repo */ $headers = Base::parse_header_uri($_POST['github_updater_repo']); $_POST['github_updater_repo'] = $headers['owner_repo']; self::$install = Settings::sanitize($_POST); self::$install['repo'] = $headers['repo']; /* * Create GitHub endpoint. * Save Access Token if present. * Check for GitHub Self-Hosted. */ if ('github' === self::$install['github_updater_api']) { if ('github.com' === $headers['host'] || empty($headers['host'])) { $github_base = 'https://api.github.com'; $headers['host'] = 'github.com'; } else { $github_base = $headers['base_uri'] . '/api/v3'; } self::$install['download_link'] = $github_base . '/repos/' . self::$install['github_updater_repo'] . '/zipball/' . self::$install['github_updater_branch']; /* * If asset is entered install it. */ if (false !== stristr($headers['path'], 'releases/download')) { self::$install['download_link'] = $headers['uri']; } if (!empty(self::$install['github_access_token'])) { self::$install['download_link'] = add_query_arg('access_token', self::$install['github_access_token'], self::$install['download_link']); parent::$options[self::$install['repo']] = self::$install['github_access_token']; } elseif (!empty(parent::$options['github_access_token']) && ('github.com' === $headers['host'] || empty($headers['host']))) { self::$install['download_link'] = add_query_arg('access_token', parent::$options['github_access_token'], self::$install['download_link']); } } /* * Create Bitbucket endpoint and instantiate class Bitbucket_API. * Save private setting if present. * Ensures `maybe_authenticate_http()` is available. */ if ('bitbucket' === self::$install['github_updater_api']) { self::$install['download_link'] = 'https://bitbucket.org/' . self::$install['github_updater_repo'] . '/get/' . self::$install['github_updater_branch'] . '.zip'; if (isset(self::$install['is_private'])) { parent::$options[self::$install['repo']] = 1; } new Bitbucket_API((object) $type); } /* * Create GitLab endpoint. * Check for GitLab Self-Hosted. */ if ('gitlab' === self::$install['github_updater_api']) { if ('gitlab.com' === $headers['host'] || empty($headers['host'])) { $gitlab_base = 'https://gitlab.com'; $headers['host'] = 'gitlab.com'; } else { $gitlab_base = $headers['base_uri']; } self::$install['download_link'] = implode('/', array($gitlab_base, self::$install['github_updater_repo'], 'repository/archive.zip')); self::$install['download_link'] = add_query_arg('ref', self::$install['github_updater_branch'], self::$install['download_link']); if (!empty(self::$install['gitlab_private_token'])) { self::$install['download_link'] = add_query_arg('private_token', self::$install['gitlab_private_token'], self::$install['download_link']); if ('gitlab.com' === $headers['host']) { parent::$options['gitlab_private_token'] = self::$install['gitlab_private_token']; } else { parent::$options['gitlab_enterprise_token'] = self::$install['gitlab_private_token']; } } elseif (!empty(parent::$options['gitlab_private_token'])) { self::$install['download_link'] = add_query_arg('private_token', parent::$options['gitlab_private_token'], self::$install['download_link']); } } parent::$options['github_updater_install_repo'] = self::$install['repo']; if (defined('GITHUB_UPDATER_EXTENDED_NAMING') && GITHUB_UPDATER_EXTENDED_NAMING && 'plugin' === $type) { parent::$options['github_updater_install_repo'] = implode('-', array(self::$install['github_updater_api'], $headers['owner'], self::$install['repo'])); } update_site_option('github_updater', parent::$options); $url = self::$install['download_link']; $nonce = wp_nonce_url($url); if ('plugin' === $type) { $plugin = self::$install['repo']; /* * Create a new instance of Plugin_Upgrader. */ $upgrader = new \Plugin_Upgrader($skin = new \Plugin_Installer_Skin(compact('type', 'title', 'url', 'nonce', 'plugin', 'api'))); } if ('theme' === $type) { $theme = self::$install['repo']; /* * Create a new instance of Theme_Upgrader. */ $upgrader = new \Theme_Upgrader($skin = new \Theme_Installer_Skin(compact('type', 'title', 'url', 'nonce', 'theme', 'api'))); } /* * Perform the action and install the plugin from the $source urldecode(). * Flush cache so we can make sure that the installed plugins/themes list is always up to date. */ $upgrader->install($url); wp_cache_flush(); } if (!isset($_POST['option_page']) || !('github_updater_install' === $_POST['option_page'])) { $this->create_form($type); } }
/** * Install a new WPMU DEV plugin. * * @since 4.0.0 * @param int $pid The project ID. * @return bool True on success. */ public function install($pid) { $this->clear_error(); if ($this->is_project_installed($pid)) { $this->set_error($pid, 'INS.01', __('Already installed', 'wpmudev')); return false; } $project = WPMUDEV_Dashboard::$site->get_project_infos($pid); // Make sure Upfront is available before an upfront theme or plugin is installed. if ($project->need_upfront && !WPMUDEV_Dashboard::$site->is_upfront_installed()) { $this->install(WPMUDEV_Dashboard::$site->id_upfront); } // For plugins_api.. include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; ob_start(); // Save on a bit of bandwidth. $api = plugins_api('plugin_information', array('slug' => 'wpmudev_install-' . $pid, 'fields' => array('sections' => false))); if (is_wp_error($api)) { $this->set_error($pid, 'INS.02', __('No data found', 'wpmudev')); return false; } $skin = new Automatic_Upgrader_Skin(); /* * Set before the update: * WP will refresh local cache via action-hook before the install() * method is finished. That refresh call must scan the FS again. */ WPMUDEV_Dashboard::$site->clear_local_file_cache(); switch ($project->type) { case 'plugin': $upgrader = new Plugin_Upgrader($skin); $upgrader->install($api->download_link); break; case 'theme': $upgrader = new Theme_Upgrader($skin); $upgrader->install($api->download_link); break; } $details = ob_get_clean(); if (is_wp_error($skin->result)) { WPMUDEV_Dashboard::$site->schedule_shutdown_refresh(); $this->set_error($pid, 'INS.03', $skin->result->get_error_message()); return false; } // API call to inform wpmudev site about the change, as it's a single we can let it do that at the end to avoid multiple pings WPMUDEV_Dashboard::$site->schedule_shutdown_refresh(); // Fetch latest project details. $project = WPMUDEV_Dashboard::$site->get_project_infos($pid); if (!$project->is_installed) { $this->set_error($pid, 'INS.04', __('Maybe wrong folder permissions', 'wpmudev')); } return $project->is_installed; }
/** * * @TODO document * */ function theme_upgrade($type, $file, $path, $uploader, $checked, $dash) { $this->wp_libs(); if (!$checked) { $this->check_creds('extend', PL_EXTEND_THEMES_DIR); } global $wp_filesystem; $active = basename(get_stylesheet_directory()) === $file ? true : false; if ($active) { switch_theme(basename(get_template_directory()), basename(get_template_directory())); } $skin = new PageLines_Upgrader_Skin(); $upgrader = new Theme_Upgrader($skin); $wp_filesystem->delete(trailingslashit(PL_EXTEND_THEMES_DIR) . $file, true, false); @$upgrader->install($this->make_url($type, $file)); if ($active) { switch_theme(basename(get_template_directory()), $file); } // Output $text = '&extend_text=theme_upgrade#your_themes'; $message = __('Theme Upgraded.', 'pagelines'); $url = PL_ADMIN_STORE_SLUG; if ($dash) { $url = PL_MAIN_DASH; $this->remove_update($path); } $this->page_reload($url, null, $message); }
/** * Display the plugin install page */ function display_install_page() { check_admin_referer('siteorigin-install-theme'); require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; // Need for upgrade classes $slug = !empty($_GET['install_theme']) ? $_GET['install_theme'] : false; $version = !empty($_GET['theme_version']) ? $_GET['theme_version'] : false; if (empty($slug) || empty($version)) { wp_die(__('Error installing theme', 'siteorigin-installer')); } ?> <div class="wrap"> <?php // This is where we actually install the theme $theme_url = 'https://wordpress.org/themes/download/' . urlencode($slug) . '.' . urlencode($version) . '.zip'; $title = sprintf(__('Installing Theme: %s'), $slug . ' ' . $version); $nonce = 'install-theme_' . $slug; $url = 'update.php?action=install-theme&theme=' . urlencode($slug); $type = 'web'; //Install theme type, From Web or an Upload. $upgrader = new Theme_Upgrader(new Theme_Installer_Skin(compact('title', 'url', 'nonce', 'plugin', 'api', 'type'))); $upgrader->install($theme_url); ?> </div> <?php }
/** * Install the theme. * * @since 1.0.0 * * @return true|null|WP_Error */ public function install() { if (!current_user_can('install_themes')) { return new WP_Error('unauthorized', esc_html__('You do not have sufficient permissions to install themes on this site.', 'audiotheme-agent')); } $upgrader = new Theme_Upgrader(new Automatic_Upgrader_Skin()); $result = $upgrader->install($this->get_download_url()); if (true === $result) { $this->set_installed(true)->set_installed_version($this->get_current_version()); } return $result; }
wp_die(__('You do not have sufficient permissions to install themes on this site.')); } check_admin_referer('theme-upload'); $file_upload = new File_Upload_Upgrader('themezip', 'package'); wp_enqueue_script('customize-loader'); $title = __('Upload Theme'); $parent_file = 'themes.php'; $submenu_file = 'theme-install.php'; require_once ABSPATH . 'wp-admin/admin-header.php'; $title = sprintf(__('Installing Theme from uploaded file: %s'), esc_html(basename($file_upload->filename))); $nonce = 'theme-upload'; $url = add_query_arg(array('package' => $file_upload->id), 'update.php?action=upload-theme'); $type = 'upload'; //Install plugin type, From Web or an Upload. $upgrader = new Theme_Upgrader(new Theme_Installer_Skin(compact('type', 'title', 'nonce', 'url'))); $result = $upgrader->install($file_upload->package); if ($result || is_wp_error($result)) { $file_upload->cleanup(); } include ABSPATH . 'wp-admin/admin-footer.php'; } else { /** * Fires when a custom plugin or theme update request is received. * * The dynamic portion of the hook name, `$action`, refers to the action * provided in the request for wp-admin/update.php. Can be used to * provide custom update functionality for themes and plugins. * * @since 2.8.0 */ do_action("update-custom_{$action}");
/** * Install a theme * * @param mixed $theme * @param array $args * @return array|bool */ function _wprp_install_theme($theme, $args = array()) { if (defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS) { return new WP_Error('disallow-file-mods', __("File modification is disabled with the DISALLOW_FILE_MODS constant.", 'wpremote')); } if (wp_get_theme($theme)->exists()) { return new WP_Error('theme-installed', __('Theme is already installed.')); } include_once ABSPATH . 'wp-admin/includes/admin.php'; include_once ABSPATH . 'wp-admin/includes/upgrade.php'; include_once ABSPATH . 'wp-includes/update.php'; require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; require_once WPRP_PLUGIN_PATH . 'inc/class-wprp-theme-upgrader-skin.php'; // Access the themes_api() helper function include_once ABSPATH . 'wp-admin/includes/theme-install.php'; $api_args = array('slug' => $theme, 'fields' => array('sections' => false)); $api = themes_api('theme_information', $api_args); if (is_wp_error($api)) { return $api; } $skin = new WPRP_Theme_Upgrader_Skin(); $upgrader = new Theme_Upgrader($skin); // The best way to get a download link for a specific version :( // Fortunately, we can depend on a relatively consistent naming pattern if (!empty($args['version']) && 'stable' != $args['version']) { $api->download_link = str_replace($api->version . '.zip', $args['version'] . '.zip', $api->download_link); } $result = $upgrader->install($api->download_link); if (is_wp_error($result)) { return $result; } else { if (!$result) { return new WP_Error('unknown-install-error', __('Unknown error installing theme.', 'wpremote')); } } return array('status' => 'success'); }