/** * Collect counts for available updates * * @return string */ private function wp_get_update_data() { $counts = array('plugins' => 0, 'themes' => 0, 'wordpress' => 0, 'translations' => 0); $update_plugins = get_site_transient('update_plugins'); if (!empty($update_plugins->response)) { $counts['plugins'] = count($update_plugins->response); } $update_themes = get_site_transient('update_themes'); if (!empty($update_themes->response)) { $counts['themes'] = count($update_themes->response); } $update_wordpress = get_core_updates(array('dismissed' => false)); if (!empty($update_wordpress) && !in_array($update_wordpress[0]->response, array('development', 'latest'))) { $counts['wordpress'] = 1; } if (wp_get_translation_updates()) { $counts['translations'] = 1; } return $counts; }
/** * Prepares the list of items for displaying. * * @access public * @since 4.X.0 * @uses WP_List_Table::set_pagination_args() */ public function prepare_items() { global $wp_version; $this->cur_wp_version = preg_replace('/-.*$/', '', $wp_version); $core_updates = (array) get_core_updates(); $plugins = (array) get_plugin_updates(); $themes = (array) get_theme_updates(); $translations = (array) wp_get_translation_updates(); if (!empty($core_updates)) { $this->items[] = array('type' => 'core', 'slug' => 'core', 'data' => $core_updates); } foreach ($plugins as $plugin_file => $plugin_data) { $this->items[] = array('type' => 'plugin', 'slug' => $plugin_file, 'data' => $plugin_data); } foreach ($themes as $stylesheet => $theme) { $this->items[] = array('type' => 'theme', 'slug' => $stylesheet, 'data' => $theme); } if (!empty($translations)) { $this->items[] = array('type' => 'translations', 'slug' => 'translations', 'data' => $translations); } if (!isset($core_updates[0]->response) || 'latest' == $core_updates[0]->response || 'development' == $core_updates[0]->response || version_compare($core_updates[0]->current, $this->cur_wp_version, '=')) { $this->core_update_version = false; } else { $this->core_update_version = $core_updates[0]->current; } if ($this->core_update_version || !empty($plugins) || !empty($themes) || !empty($translations)) { $this->has_available_updates = true; } $columns = $this->get_columns(); $hidden = array(); $sortable = $this->get_sortable_columns(); $this->_column_headers = array($columns, $hidden, $sortable); $this->set_pagination_args(array('total_items' => count($this->items), 'per_page' => count($this->items), 'total_pages' => 1)); }
public function wp_oracle_get_translation_updates() { if (!function_exists('wp_get_translation_updates')) { require_once ABSPATH . 'wp-includes/update.php'; } $updates = wp_get_translation_updates(); if (empty($updates)) { return array('blog' => array('translations' => 'no_updates')); } else { return $updates; } }
/** * 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); }
/** * @since 3.7.0 */ function list_translation_updates() { $updates = wp_get_translation_updates(); if (!$updates) { if ('en_US' != get_locale()) { echo '<h2>' . __('Translations') . '</h2>'; echo '<p>' . __('Your translations are all up to date.') . '</p>'; } return; } $form_action = 'update-core.php?action=do-translation-upgrade'; ?> <h2><?php _e('Translations'); ?> </h2> <form method="post" action="<?php echo esc_url($form_action); ?> " name="upgrade-translations" class="upgrade"> <p><?php _e('New translations are available.'); ?> </p> <?php wp_nonce_field('upgrade-translations'); ?> <p><input class="button" type="submit" value="<?php esc_attr_e('Update Translations'); ?> " name="upgrade" /></p> </form> <?php }
/** * Collect counts and UI strings for available updates * * @since 3.3.0 * * @return array */ function wp_get_update_data() { $counts = array('plugins' => 0, 'themes' => 0, 'wordpress' => 0, 'translations' => 0); if ($plugins = current_user_can('update_plugins')) { $update_plugins = get_site_transient('update_plugins'); if (!empty($update_plugins->response)) { $counts['plugins'] = count($update_plugins->response); } } if ($themes = current_user_can('update_themes')) { $update_themes = get_site_transient('update_themes'); if (!empty($update_themes->response)) { $counts['themes'] = count($update_themes->response); } } if (($core = current_user_can('update_core')) && function_exists('get_core_updates')) { $update_wordpress = get_core_updates(array('dismissed' => false)); if (!empty($update_wordpress) && !in_array($update_wordpress[0]->response, array('development', 'latest')) && current_user_can('update_core')) { $counts['wordpress'] = 1; } } if (($core || $plugins || $themes) && wp_get_translation_updates()) { $counts['translations'] = 1; } $counts['total'] = $counts['plugins'] + $counts['themes'] + $counts['wordpress'] + $counts['translations']; $titles = array(); if ($counts['wordpress']) { $titles['wordpress'] = sprintf(__('%d WordPress Update'), $counts['wordpress']); } if ($counts['plugins']) { $titles['plugins'] = sprintf(_n('%d Plugin Update', '%d Plugin Updates', $counts['plugins']), $counts['plugins']); } if ($counts['themes']) { $titles['themes'] = sprintf(_n('%d Theme Update', '%d Theme Updates', $counts['themes']), $counts['themes']); } if ($counts['translations']) { $titles['translations'] = __('Translation Updates'); } $update_title = $titles ? esc_attr(implode(', ', $titles)) : ''; $update_data = array('counts' => $counts, 'title' => $update_title); /** * Filter the returned array of update data for plugins, themes, and WordPress core. * * @since 3.5.0 * * @param array $update_data { * Fetched update data. * * @type array $counts An array of counts for available plugin, theme, and WordPress updates. * @type string $update_title Titles of available updates. * } * @param array $titles An array of update counts and UI strings for available updates. */ return apply_filters('wp_get_update_data', $update_data, $titles); }
/** * Kicks off a upgrade request for each item in the upgrade "queue" */ static function perform_auto_updates() { $lock_name = 'auto_upgrader.lock'; if (get_site_option($lock_name)) { // Test to see if it was set more than an hour ago, if so, cleanup. if (get_site_option($lock_name) < time() - HOUR_IN_SECONDS) { delete_site_option($lock_name); } else { // The process is already locked return; } } // Lock upgrades for us for half an hour if (!add_site_option($lock_name, microtime(true), HOUR_IN_SECONDS / 2)) { 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, 3); 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 (array_keys($plugin_updates->response) as $plugin) { self::upgrade('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 (array_keys($theme_updates->response) as $theme) { self::upgrade('theme', $theme); } // Force refresh of theme update information wp_clean_themes_cache(); } // Next, Process any core upgrade wp_version_check(); // Check for Core updates $core_update = find_core_auto_update(); if ($core_update) { self::upgrade('core', $core_update); delete_site_transient('update_core'); } // Cleanup, and check for any pending translations wp_version_check(); // check for Core updates wp_update_themes(); // Check for Theme updates wp_update_plugins(); // Check for Plugin updates // Finally, Process any new translations $language_updates = wp_get_translation_updates(); if ($language_updates) { foreach ($language_updates as $update) { self::upgrade('language', $update); } // Clear existing caches wp_clean_plugins_cache(); wp_clean_themes_cache(); delete_site_transient('update_core'); wp_version_check(); // check for Core updates wp_update_themes(); // Check for Theme updates wp_update_plugins(); // Check for Plugin updates } /** * Filter whether to email an update summary to the site administrator. * * @since 3.7.0 * * @param bool Whether or not email should be sent to administrator. Default true. * @param bool|array $core_update An array of core update data, false otherwise. * @param object $theme_updates Object containing theme update properties. * @param object $plugin_updates Object containing plugin update properties. * @param array $language_updates Array containing the Language updates available. * @param array $upgrade_results Array of the upgrade results keyed by upgrade type, and plugin/theme slug. */ if (apply_filters('enable_auto_upgrade_email', true, $core_update, $theme_updates, $plugin_updates, $language_updates, self::$upgrade_results)) { self::send_email(); } // Clear the lock delete_site_option($lock_name); }
function get_upgradable_translations() { if (!function_exists('wp_get_translation_updates')) { include_once ABSPATH . 'wp-includes/update.php'; } if (function_exists('wp_get_translation_updates')) { $translations_object = wp_get_translation_updates(); $translations_object = array_filter($translations_object); } if (isset($translations_object) && !empty($translations_object)) { return true; } else { return false; } }
/** * 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'); }
/** * 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; } $this->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); } } }
/** * 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; }
/** * Get all updates available for all translations * * @return array */ private function get_translation_updates() { $available = $this->get_installed_languages(); $func = function () use($available) { return $available; }; $filters = array('plugins_update_check_locales', 'themes_update_check_locales'); foreach ($filters as $filter) { add_filter($filter, $func); } $this->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. foreach ($filters as $filter) { remove_filter($filter, $func); } $updates = wp_get_translation_updates(); // Retrieves a list of all translations updates available. return $updates; }
function cscircles_options_page() { echo "<div class='wrap'>\n<h2>CS Circles Options</h2>\n<form method='post' action='options.php'>"; settings_fields('cscircles'); do_settings_sections('cscircles'); submit_button(); echo "</form>\n</div>"; $updates = wp_get_translation_updates(); if ($updates) { echo "<p><i>Note:</i> The following translations may need to be updated:<ul>"; foreach ($updates as $u) { echo "<li>"; foreach ($u as $f => $v) { echo "<b>{$f}</b>: {$v}, "; } } echo "</ul></p>"; } }