Exemple #1
0
 /**
  * Toggle maintenance mode for the site.
  *
  * Creates/deletes the maintenance file to enable/disable maintenance mode.
  *
  * @since 2.8.0
  * @access public
  *
  * @global WP_Filesystem_Base $wp_filesystem Subclass
  *
  * @param bool $enable True to enable maintenance mode, false to disable.
  */
 public function maintenance_mode($enable = false)
 {
     global $wp_filesystem;
     $file = $wp_filesystem->abspath() . '.maintenance';
     if ($enable) {
         $this->skin->feedback('maintenance_start');
         // Create maintenance file to signal that we are upgrading
         $maintenance_string = '<?php $upgrading = ' . time() . '; ?>';
         $wp_filesystem->delete($file);
         $wp_filesystem->put_contents($file, $maintenance_string, FS_CHMOD_FILE);
     } elseif (!$enable && $wp_filesystem->exists($file)) {
         $this->skin->feedback('maintenance_end');
         $wp_filesystem->delete($file);
     }
 }
 /**
  * Update an item, if appropriate.
  *
  * @since 3.7.0
  *
  * @param string $type The type of update being checked: 'core', 'theme', 'plugin', 'translation'.
  * @param object $item The update offer.
  */
 public function update($type, $item)
 {
     $skin = new Automatic_Upgrader_Skin();
     switch ($type) {
         case 'core':
             // The Core upgrader doesn't use the Upgrader's skin during the actual main part of the upgrade, instead, firing a filter.
             add_filter('update_feedback', array($skin, 'feedback'));
             $upgrader = new Core_Upgrader($skin);
             $context = ABSPATH;
             break;
         case 'plugin':
             $upgrader = new Plugin_Upgrader($skin);
             $context = WP_PLUGIN_DIR;
             // We don't support custom Plugin directories, or updates for WPMU_PLUGIN_DIR
             break;
         case 'theme':
             $upgrader = new Theme_Upgrader($skin);
             $context = get_theme_root($item->theme);
             break;
         case 'translation':
             $upgrader = new Language_Pack_Upgrader($skin);
             $context = WP_CONTENT_DIR;
             // WP_LANG_DIR;
             break;
     }
     // Determine whether we can and should perform this update.
     if (!$this->should_update($type, $item, $context)) {
         return false;
     }
     $upgrader_item = $item;
     switch ($type) {
         case 'core':
             $skin->feedback(__('Updating to WordPress %s'), $item->version);
             $item_name = sprintf(__('WordPress %s'), $item->version);
             break;
         case 'theme':
             $upgrader_item = $item->theme;
             $theme = wp_get_theme($upgrader_item);
             $item_name = $theme->Get('Name');
             $skin->feedback(__('Updating theme: %s'), $item_name);
             break;
         case 'plugin':
             $upgrader_item = $item->plugin;
             $plugin_data = get_plugin_data($context . '/' . $upgrader_item);
             $item_name = $plugin_data['Name'];
             $skin->feedback(__('Updating plugin: %s'), $item_name);
             break;
         case 'translation':
             $language_item_name = $upgrader->get_name_for_update($item);
             $item_name = sprintf(__('Translations for %s'), $language_item_name);
             $skin->feedback(sprintf(__('Updating translations for %1$s (%2$s)&#8230;'), $language_item_name, $item->language));
             break;
     }
     $allow_relaxed_file_ownership = false;
     if ('core' == $type && isset($item->new_files) && !$item->new_files) {
         $allow_relaxed_file_ownership = true;
     }
     // Boom, This sites about to get a whole new splash of paint!
     $upgrade_result = $upgrader->upgrade($upgrader_item, array('clear_update_cache' => false, 'pre_check_md5' => false, 'attempt_rollback' => true, 'allow_relaxed_file_ownership' => $allow_relaxed_file_ownership));
     // If the filesystem is unavailable, false is returned.
     if (false === $upgrade_result) {
         $upgrade_result = new WP_Error('fs_unavailable', __('Could not access filesystem.'));
     }
     // Core doesn't output this, so let's append it so we don't get confused.
     if ('core' == $type) {
         if (is_wp_error($upgrade_result)) {
             $skin->error(__('Installation Failed'), $upgrade_result);
         } else {
             $skin->feedback(__('WordPress updated successfully'));
         }
     }
     $this->update_results[$type][] = (object) array('item' => $item, 'result' => $upgrade_result, 'name' => $item_name, 'messages' => $skin->get_upgrade_messages());
     return $upgrade_result;
 }