protected function update($version, $locale) { $args = $this->input(); $version = isset($args['version']) ? $args['version'] : false; $locale = isset($args['locale']) ? $args['locale'] : get_locale(); include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; delete_site_transient('update_core'); wp_version_check(array(), true); if ($version) { $update = find_core_update($version, $locale); } else { $update = $this->find_latest_update_offer(); } /** * Pre-upgrade action * * @since 3.9.3 * * @param object|array $update as returned by find_core_update() or find_core_auto_update() */ do_action('jetpack_pre_core_upgrade', $update); $skin = new Automatic_Upgrader_Skin(); $upgrader = new Core_Upgrader($skin); $this->new_version = $upgrader->upgrade($update); $this->log = $upgrader->skin->get_upgrade_messages(); if (is_wp_error($this->new_version)) { return $this->new_version; } return $this->new_version; }
/** * Updates wordpress core to the given version. * * Returns the new version on success, and a Wp_error object on failure * * @param string $version * @return string|object */ function bruteprotect_update_core($version) { $locale = get_locale(); $update = find_core_update($version, $locale); $skin = new Automatic_Upgrader_Skin(); $upgrader = new Core_Upgrader($skin); $results = $upgrader->upgrade($update); return $results; }
private function update($version, $locale) { $args = $this->input(); $version = isset($args['version']) ? $args['version'] : false; $locale = isset($args['locale']) ? $args['locale'] : get_locale(); include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; delete_site_transient('update_core'); wp_version_check(array(), true); if ($version) { $update = find_core_update($version, $locale); } else { $update = $this->find_latest_update_offer(); } $skin = new Automatic_Upgrader_Skin(); $upgrader = new Core_Upgrader($skin); $this->new_version = $upgrader->upgrade($update); $this->log = $upgrader->skin->get_upgrade_messages(); if (is_wp_error($this->new_version)) { return $this->new_version; } return $this->new_version; }
function do_undismiss_core_update() { $version = isset( $_POST['version'] )? $_POST['version'] : false; $locale = isset( $_POST['locale'] )? $_POST['locale'] : 'en_US'; $update = find_core_update( $version, $locale ); if ( !$update ) return; undismiss_core_update( $version, $locale ); wp_redirect( wp_nonce_url('update-core.php?action=upgrade-core', 'upgrade-core') ); }
/** * AJAX handler for updating core. * * @since 4.6.0 * * @see Core_Upgrader */ function wp_ajax_update_core() { check_ajax_referer('updates'); if (!current_user_can('update_core')) { $status['error'] = __('You do not have sufficient permissions to update this site.'); wp_send_json_error($status); } $reinstall = isset($_POST['reinstall']) ? (bool) $_POST['reinstall'] : false; $version = isset($_POST['version']) ? sanitize_text_field(wp_unslash($_POST['version'])) : false; $locale = isset($_POST['locale']) ? sanitize_text_field(wp_unslash($_POST['locale'])) : 'en_US'; $update = find_core_update($version, $locale); if (!$update) { return; } $status = array('update' => 'core', 'redirect' => esc_url(self_admin_url('about.php?updated'))); if ($update->current === $update->version) { wp_send_json_success($status); } include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; if ($reinstall) { $update->response = 'reinstall'; } $upgrader = new WP_Automatic_Updater(); $result = $upgrader->update('core', $update); if (is_array($result) && !empty($result[0])) { wp_send_json_success($status); } else { if (is_wp_error($result)) { $status['error'] = $result->get_error_message(); wp_send_json_error($status); } else { if (false === $result) { // These aren't actual errors. $status['error'] = __('Installation Failed'); wp_send_json_error($status); } } } // An unhandled error occurred. $status['error'] = __('Installation failed.'); wp_send_json_error($status); }
/** * [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; }