Exemplo n.º 1
0
 public function pre_init_stats($params)
 {
     include_once ABSPATH . 'wp-includes/update.php';
     include_once ABSPATH . 'wp-admin/includes/update.php';
     $stats = $this->mmb_parse_action_params('pre_init_stats', $params, $this);
     extract($params);
     if ($params['refresh'] == 'transient') {
         global $wp_current_filter;
         $wp_current_filter[] = 'load-update-core.php';
         if (function_exists('wp_clean_update_cache')) {
             wp_clean_update_cache();
         }
         wp_version_check();
         wp_update_themes();
         // THIS IS INTENTIONAL, please do not delete one of the calls to wp_update_plugins(), it is required for
         // some custom plugins (read premium) to work with ManageWP :)
         // the second call is not going to trigger the remote post invoked from the wp_update_plugins call
         wp_update_plugins();
         array_pop($wp_current_filter);
         do_action('load-plugins.php');
     }
     /** @var $wpdb wpdb */
     global $wpdb, $wp_version, $mmb_plugin_dir;
     $stats['worker_version'] = $GLOBALS['MMB_WORKER_VERSION'];
     $stats['worker_revision'] = $GLOBALS['MMB_WORKER_REVISION'];
     $stats['wordpress_version'] = $wp_version;
     $stats['wordpress_locale_pckg'] = get_locale();
     $stats['php_version'] = phpversion();
     $stats['mysql_version'] = $wpdb->db_version();
     $stats['server_functionality'] = $this->get_backup_instance()->getServerInformationForStats();
     $stats['wp_multisite'] = $this->mmb_multisite;
     $stats['network_install'] = $this->network_admin_install;
     $stats['cookies'] = $this->get_stat_cookies();
     $stats['admin_usernames'] = $this->getUserList();
     $stats['site_title'] = get_bloginfo('name');
     $stats['site_tagline'] = get_bloginfo('description');
     $stats['blog_public'] = get_option('blog_public');
     $stats['timezone'] = get_option('timezone_string');
     $stats['timezone_offset'] = get_option('gmt_offset');
     $stats['server_ip'] = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : null;
     $stats['hostname'] = php_uname('n');
     $stats['db_name'] = $this->get_active_db();
     $stats['db_prefix'] = $wpdb->prefix;
     $stats['content_path'] = WP_CONTENT_DIR;
     $stats['worker_path'] = $mmb_plugin_dir;
     $stats['site_home'] = get_option('home');
     $fs = new Symfony_Filesystem_Filesystem();
     if (defined('WP_CONTENT_DIR')) {
         $stats['content_relative_path'] = $fs->makePathRelative(WP_CONTENT_DIR, ABSPATH);
     }
     if (defined('WP_PLUGIN_DIR')) {
         $stats['plugin_relative_path'] = $fs->makePathRelative(WP_PLUGIN_DIR, ABSPATH);
     }
     if (defined('WPMU_PLUGIN_DIR')) {
         $stats['mu_plugin_relative_path'] = $fs->makePathRelative(WPMU_PLUGIN_DIR, ABSPATH);
     }
     if (defined('UPLOADS')) {
         // Uploads is already relative
         $stats['uploads_relative_path'] = UPLOADS;
     }
     if (!function_exists('get_filesystem_method')) {
         include_once ABSPATH . 'wp-admin/includes/file.php';
     }
     $stats['fs_method'] = get_filesystem_method();
     $mmode = get_option('mwp_maintenace_mode');
     if (!empty($mmode) && isset($mmode['active']) && $mmode['active'] == true) {
         $stats['maintenance'] = true;
     }
     $stats['writable'] = $this->is_server_writable();
     return $stats;
 }
Exemplo n.º 2
0
 /**
  * Kicks off the background update process, looping through all pending updates.
  *
  * @since 3.7.0
  */
 public function run()
 {
     global $wpdb, $wp_version;
     if ($this->is_disabled()) {
         return;
     }
     if (!is_main_network() || !is_main_site()) {
         return;
     }
     $lock_name = 'auto_updater.lock';
     // Try to lock
     $lock_result = $wpdb->query($wpdb->prepare("INSERT IGNORE INTO `{$wpdb->options}` ( `option_name`, `option_value`, `autoload` ) VALUES (%s, %s, 'no') /* LOCK */", $lock_name, time()));
     if (!$lock_result) {
         $lock_result = get_option($lock_name);
         // If we couldn't create a lock, and there isn't a lock, bail
         if (!$lock_result) {
             return;
         }
         // Check to see if the lock is still valid
         if ($lock_result > time() - HOUR_IN_SECONDS) {
             return;
         }
     }
     // Update the lock, as by this point we've definitely got a lock, just need to fire the actions
     update_option($lock_name, time());
     // Don't automatically run these thins, as we'll handle it ourselves
     remove_action('upgrader_process_complete', array('Language_Pack_Upgrader', 'async_upgrade'), 20);
     remove_action('upgrader_process_complete', 'wp_version_check');
     remove_action('upgrader_process_complete', 'wp_update_plugins');
     remove_action('upgrader_process_complete', 'wp_update_themes');
     // Next, Plugins
     wp_update_plugins();
     // Check for Plugin updates
     $plugin_updates = get_site_transient('update_plugins');
     if ($plugin_updates && !empty($plugin_updates->response)) {
         foreach ($plugin_updates->response as $plugin) {
             $this->update('plugin', $plugin);
         }
         // Force refresh of plugin update information
         wp_clean_plugins_cache();
     }
     // Next, those themes we all love
     wp_update_themes();
     // Check for Theme updates
     $theme_updates = get_site_transient('update_themes');
     if ($theme_updates && !empty($theme_updates->response)) {
         foreach ($theme_updates->response as $theme) {
             $this->update('theme', (object) $theme);
         }
         // Force refresh of theme update information
         wp_clean_themes_cache();
     }
     // Next, Process any core update
     wp_version_check();
     // Check for Core updates
     $core_update = find_core_auto_update();
     if ($core_update) {
         $this->update('core', $core_update);
     }
     // Clean up, and check for any pending translations
     // (Core_Upgrader checks for core updates)
     $theme_stats = array();
     if (isset($this->update_results['theme'])) {
         foreach ($this->update_results['theme'] as $upgrade) {
             $theme_stats[$upgrade->item->theme] = true === $upgrade->result;
         }
     }
     wp_update_themes($theme_stats);
     // Check for Theme updates
     $plugin_stats = array();
     if (isset($this->update_results['plugin'])) {
         foreach ($this->update_results['plugin'] as $upgrade) {
             $plugin_stats[$upgrade->item->plugin] = true === $upgrade->result;
         }
     }
     wp_update_plugins($plugin_stats);
     // Check for Plugin updates
     // Finally, Process any new translations
     $language_updates = wp_get_translation_updates();
     if ($language_updates) {
         foreach ($language_updates as $update) {
             $this->update('translation', $update);
         }
         // Clear existing caches
         wp_clean_update_cache();
         wp_version_check();
         // check for Core updates
         wp_update_themes();
         // Check for Theme updates
         wp_update_plugins();
         // Check for Plugin updates
     }
     // Send debugging email to all development installs.
     if (!empty($this->update_results)) {
         $development_version = false !== strpos($wp_version, '-');
         /**
          * Filter whether to send a debugging email for each automatic background update.
          *
          * @since 3.7.0
          *
          * @param bool $development_version By default, emails are sent if the
          *                                  install is a development version.
          *                                  Return false to avoid the email.
          */
         if (apply_filters('automatic_updates_send_debug_email', $development_version)) {
             $this->send_debug_email();
         }
         if (!empty($this->update_results['core'])) {
             $this->after_core_update($this->update_results['core'][0]);
         }
         /**
          * Fires after all automatic updates have run.
          *
          * @since 3.8.0
          *
          * @param array $update_results The results of all attempted updates.
          */
         do_action('automatic_updates_complete', $this->update_results);
     }
     // Clear the lock
     delete_option($lock_name);
 }
Exemplo n.º 3
0
 public function doThemeUpdateCheck()
 {
     global $wp_current_filter;
     $wp_current_filter[] = 'load-update-core.php';
     if (function_exists('wp_clean_update_cache')) {
         wp_clean_update_cache();
     }
     wp_update_themes();
     array_pop($wp_current_filter);
     do_action('load-plugins.php');
 }
Exemplo n.º 4
0
 /**
  * Kicks off the background update process, looping through all pending updates.
  *
  * @since 3.7.0
  * @access public
  *
  * @global wpdb   $wpdb
  * @global string $wp_version
  */
 public function run()
 {
     global $wpdb, $wp_version;
     if ($this->is_disabled()) {
         return;
     }
     if (!is_main_network() || !is_main_site()) {
         return;
     }
     if (!$this->create_lock('auto_updater')) {
         return;
     }
     // Don't automatically run these thins, as we'll handle it ourselves
     remove_action('upgrader_process_complete', array('Language_Pack_Upgrader', 'async_upgrade'), 20);
     remove_action('upgrader_process_complete', 'wp_version_check');
     remove_action('upgrader_process_complete', 'wp_update_plugins');
     remove_action('upgrader_process_complete', 'wp_update_themes');
     // Next, Plugins
     wp_update_plugins();
     // Check for Plugin updates
     $plugin_updates = get_site_transient('update_plugins');
     if ($plugin_updates && !empty($plugin_updates->response)) {
         foreach ($plugin_updates->response as $plugin) {
             $this->update('plugin', $plugin);
         }
         // Force refresh of plugin update information
         wp_clean_plugins_cache();
     }
     // Next, those themes we all love
     wp_update_themes();
     // Check for Theme updates
     $theme_updates = get_site_transient('update_themes');
     if ($theme_updates && !empty($theme_updates->response)) {
         foreach ($theme_updates->response as $theme) {
             $this->update('theme', (object) $theme);
         }
         // Force refresh of theme update information
         wp_clean_themes_cache();
     }
     // Next, Process any core update
     wp_version_check();
     // Check for Core updates
     $core_update = find_core_auto_update();
     if ($core_update) {
         $this->update('core', $core_update);
     }
     // Clean up, and check for any pending translations
     // (Core_Upgrader checks for core updates)
     $theme_stats = array();
     if (isset($this->update_results['theme'])) {
         foreach ($this->update_results['theme'] as $upgrade) {
             $theme_stats[$upgrade->item->theme] = true === $upgrade->result;
         }
     }
     wp_update_themes($theme_stats);
     // Check for Theme updates
     $plugin_stats = array();
     if (isset($this->update_results['plugin'])) {
         foreach ($this->update_results['plugin'] as $upgrade) {
             $plugin_stats[$upgrade->item->plugin] = true === $upgrade->result;
         }
     }
     wp_update_plugins($plugin_stats);
     // Check for Plugin updates
     // Finally, Process any new translations
     $language_updates = wp_get_translation_updates();
     if ($language_updates) {
         foreach ($language_updates as $update) {
             $this->update('translation', $update);
         }
         // Clear existing caches
         wp_clean_update_cache();
         wp_version_check();
         // check for Core updates
         wp_update_themes();
         // Check for Theme updates
         wp_update_plugins();
         // Check for Plugin updates
     }
     // Send debugging email to all development installs.
     if (!empty($this->update_results)) {
         $development_version = false !== strpos($wp_version, '-');
         /**
          * Filter whether to send a debugging email for each automatic background update.
          *
          * @since 3.7.0
          *
          * @param bool $development_version By default, emails are sent if the
          *                                  install is a development version.
          *                                  Return false to avoid the email.
          */
         if (apply_filters('automatic_updates_send_debug_email', $development_version)) {
             $this->send_debug_email();
         }
         if (!empty($this->update_results['core'])) {
             $this->after_core_update($this->update_results['core'][0]);
         }
         /**
          * Fires after all automatic updates have run.
          *
          * @since 3.8.0
          *
          * @param array $update_results The results of all attempted updates.
          */
         do_action('automatic_updates_complete', $this->update_results);
     }
     $this->release_lock('auto_updater');
 }
Exemplo n.º 5
0
 /**
  * Update language packs for plugins & themes
  *
  * @return array|bool
  */
 private function update_language_packs()
 {
     if ('en_US' === get_locale()) {
         return false;
     }
     if (!function_exists('wp_clean_update_cache')) {
         require_once ABSPATH . 'wp-includes/update.php';
     }
     if (!class_exists('\\Language_Pack_Upgrader')) {
         require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     }
     if (!class_exists('\\Automatic_Upgrader_Skin')) {
         require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader-skins.php';
     }
     wp_clean_update_cache();
     wp_update_themes();
     wp_update_plugins();
     $upgrader = new \Language_Pack_Upgrader(new \Automatic_Upgrader_Skin());
     return $upgrader->bulk_upgrade();
 }
 /**
  * Bulk upgrade language packs.
  *
  * @since 3.7.0
  * @access public
  *
  * @global WP_Filesystem_Base $wp_filesystem Subclass
  *
  * @param array $language_updates Optional. Language pack updates. Default empty array.
  * @param array $args {
  *     Optional. Other arguments for upgrading multiple language packs. Default empty array
  *
  *     @type bool $clear_update_cache Whether to clear the update cache when done.
  *                                    Default true.
  * }
  * @return array|bool|WP_Error Will return an array of results, or true if there are no updates,
  *                                   false or WP_Error for initial errors.
  */
 public function bulk_upgrade($language_updates = array(), $args = array())
 {
     global $wp_filesystem;
     $defaults = array('clear_update_cache' => true);
     $parsed_args = wp_parse_args($args, $defaults);
     $this->init();
     $this->upgrade_strings();
     if (!$language_updates) {
         $language_updates = wp_get_translation_updates();
     }
     if (empty($language_updates)) {
         $this->skin->header();
         $this->skin->set_result(true);
         $this->skin->feedback('up_to_date');
         $this->skin->bulk_footer();
         $this->skin->footer();
         return true;
     }
     if ('upgrader_process_complete' == current_filter()) {
         $this->skin->feedback('starting_upgrade');
     }
     // Remove any existing upgrade filters from the plugin/theme upgraders #WP29425 & #WP29230
     remove_all_filters('upgrader_pre_install');
     remove_all_filters('upgrader_clear_destination');
     remove_all_filters('upgrader_post_install');
     remove_all_filters('upgrader_source_selection');
     add_filter('upgrader_source_selection', array($this, 'check_package'), 10, 2);
     $this->skin->header();
     // Connect to the Filesystem first.
     $res = $this->fs_connect(array(WP_CONTENT_DIR, WP_LANG_DIR));
     if (!$res) {
         $this->skin->footer();
         return false;
     }
     $results = array();
     $this->update_count = count($language_updates);
     $this->update_current = 0;
     /*
      * The filesystem's mkdir() is not recursive. Make sure WP_LANG_DIR exists,
      * as we then may need to create a /plugins or /themes directory inside of it.
      */
     $remote_destination = $wp_filesystem->find_folder(WP_LANG_DIR);
     if (!$wp_filesystem->exists($remote_destination)) {
         if (!$wp_filesystem->mkdir($remote_destination, FS_CHMOD_DIR)) {
             return new WP_Error('mkdir_failed_lang_dir', $this->strings['mkdir_failed'], $remote_destination);
         }
     }
     foreach ($language_updates as $language_update) {
         $this->skin->language_update = $language_update;
         $destination = WP_LANG_DIR;
         if ('plugin' == $language_update->type) {
             $destination .= '/plugins';
         } elseif ('theme' == $language_update->type) {
             $destination .= '/themes';
         }
         $this->update_current++;
         $options = array('package' => $language_update->package, 'destination' => $destination, 'clear_destination' => false, 'abort_if_destination_exists' => false, 'clear_working' => true, 'is_multi' => true, 'hook_extra' => array('language_update_type' => $language_update->type, 'language_update' => $language_update));
         $result = $this->run($options);
         $results[] = $this->result;
         // Prevent credentials auth screen from displaying multiple times.
         if (false === $result) {
             break;
         }
     }
     $this->skin->bulk_footer();
     $this->skin->footer();
     // Clean up our hooks, in case something else does an upgrade on this connection.
     remove_filter('upgrader_source_selection', array($this, 'check_package'));
     if ($parsed_args['clear_update_cache']) {
         wp_clean_update_cache();
     }
     return $results;
 }
 /**
  * Updates the active translation of core, plugins, and themes.
  *
  * [--dry-run]
  * : Preview which translations would be updated.
  *
  * @subcommand update
  */
 public function update($args, $assoc_args)
 {
     // Ignore updates for the default locale.
     if ('en_US' == get_locale()) {
         \WP_CLI::success("Translations updates are not needed for the 'English (US)' locale.");
         return;
     }
     wp_clean_update_cache();
     // Clear existing update caches.
     wp_version_check();
     // Check for Core translation updates.
     wp_update_themes();
     // Check for Theme translation updates.
     wp_update_plugins();
     // Check for Plugin translation updates.
     $updates = wp_get_translation_updates();
     // Retrieves a list of all translations updates available.
     if (empty($updates)) {
         \WP_CLI::success('Translations are up to date.');
         return;
     }
     // Gets a list of all languages.
     $all_languages = $this->get_all_languages();
     // Formats the updates list.
     foreach ($updates as $update) {
         if ('plugin' == $update->type) {
             $plugin_data = array_shift(get_plugins('/' . $update->slug));
             $name = $plugin_data['Name'];
         } elseif ('theme' == $update->type) {
             $theme_data = wp_get_theme($update->slug);
             $name = $theme_data['Name'];
         } else {
             // Core
             $name = 'WordPress';
         }
         // Gets the translation data.
         $translation = (object) reset(wp_list_filter($all_languages, array('language' => $update->language)));
         $update->Type = ucfirst($update->type);
         $update->Name = $name;
         $update->Version = $update->version;
         $update->Language = $translation->english_name;
     }
     // Only preview which translations would be updated.
     if (\WP_CLI\Utils\get_flag_value($assoc_args, 'dry-run')) {
         \WP_CLI::line(sprintf('Available %d translations updates:', count($updates)));
         \WP_CLI\Utils\format_items('table', $updates, array('Type', 'Name', 'Version', 'Language'));
         return;
     }
     require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     $upgrader = new \Language_Pack_Upgrader(new \Automatic_Upgrader_Skin());
     $results = array();
     // Update translations.
     foreach ($updates as $update) {
         \WP_CLI::line("Updating '{$update->Language}' translation for {$update->Name} {$update->Version}...");
         \WP_CLI::line("Downloading translation from {$update->package}...");
         $result = $upgrader->upgrade($update);
         if ($result) {
             \WP_CLI::line('Translation updated successfully.');
         } else {
             \WP_CLI::line('Translation update failed.');
         }
         $results[] = $result;
     }
     $num_to_update = count($updates);
     $num_updated = count(array_filter($results));
     $line = "Updated {$num_updated}/{$num_to_update} translations.";
     if ($num_to_update == $num_updated) {
         \WP_CLI::success($line);
     } else {
         if ($num_updated > 0) {
             \WP_CLI::warning($line);
         } else {
             \WP_CLI::error($line);
         }
     }
 }