Hooks into WP_Automatic_Updater
 static function init()
 {
     if (is_null(self::$instance)) {
         self::$instance = new Jetpack_Autoupdate();
     }
     return self::$instance;
 }
 protected function format_plugin($plugin_file, $plugin_data)
 {
     $plugin = array();
     $plugin['id'] = preg_replace("/(.+)\\.php\$/", "\$1", $plugin_file);
     $plugin['slug'] = Jetpack_Autoupdate::get_plugin_slug($plugin_file);
     $plugin['active'] = Jetpack::is_plugin_active($plugin_file);
     $plugin['name'] = $plugin_data['Name'];
     $plugin['plugin_url'] = $plugin_data['PluginURI'];
     $plugin['version'] = $plugin_data['Version'];
     $plugin['description'] = $plugin_data['Description'];
     $plugin['author'] = $plugin_data['Author'];
     $plugin['author_url'] = $plugin_data['AuthorURI'];
     $plugin['network'] = $plugin_data['Network'];
     $plugin['update'] = $this->get_plugin_updates($plugin_file);
     $plugin['next_autoupdate'] = date('Y-m-d H:i:s', wp_next_scheduled('wp_maybe_auto_update'));
     $autoupdate = in_array($plugin_file, Jetpack_Options::get_option('autoupdate_plugins', array()));
     $plugin['autoupdate'] = $autoupdate;
     $autoupdate_translation = in_array($plugin_file, Jetpack_Options::get_option('autoupdate_plugins_translations', array()));
     $plugin['autoupdate_translation'] = $autoupdate || $autoupdate_translation;
     $plugin['uninstallable'] = is_uninstallable_plugin($plugin_file);
     if (!empty($this->log[$plugin_file])) {
         $plugin['log'] = $this->log[$plugin_file];
     }
     return $plugin;
 }
Esempio n. 3
0
 /**
  * Prepare actions according to screen and post type.
  *
  * @since 3.8.2
  *
  * @uses Jetpack_Autoupdate::get_possible_failures()
  *
  * @param object $screen
  */
 function prepare_jitms($screen)
 {
     if (!current_user_can('jetpack_manage_modules')) {
         return;
     }
     global $pagenow;
     // Only show auto update JITM if auto updates are allowed in this installation
     $possible_reasons_for_failure = Jetpack_Autoupdate::get_possible_failures();
     self::$auto_updates_allowed = empty($possible_reasons_for_failure);
     if ('media-new.php' == $pagenow && !Jetpack::is_module_active('photon')) {
         add_action('admin_enqueue_scripts', array($this, 'jitm_enqueue_files'));
         add_action('post-plupload-upload-ui', array($this, 'photon_msg'));
     } elseif ('post-new.php' == $pagenow && in_array($screen->post_type, array('post', 'page'))) {
         add_action('admin_enqueue_scripts', array($this, 'jitm_enqueue_files'));
         add_action('admin_notices', array($this, 'editor_msg'));
     } elseif (self::$auto_updates_allowed) {
         if ('update-core.php' == $pagenow && !Jetpack::is_module_active('manage')) {
             add_action('admin_enqueue_scripts', array($this, 'jitm_enqueue_files'));
             add_action('admin_notices', array($this, 'manage_msg'));
         } elseif ('plugins.php' == $pagenow) {
             if (isset($_GET['activate']) && 'true' === $_GET['activate'] || isset($_GET['activate-multi']) && 'true' === $_GET['activate-multi']) {
                 add_action('admin_enqueue_scripts', array($this, 'jitm_enqueue_files'));
                 add_action('pre_current_active_plugins', array($this, 'manage_pi_msg'));
             } else {
                 // Save plugins that are activated. This is used when one or more plugins are activated to know
                 // what was activated and use it in Jetpack_JITM::manage_pi_msg() before deleting the option.
                 $wp_list_table = _get_list_table('WP_Plugins_List_Table');
                 $action = $wp_list_table->current_action();
                 if ($action && ('activate' == $action || 'activate-selected' == $action)) {
                     update_option('jetpack_temp_active_plugins_before', get_option('active_plugins', array()));
                 }
             }
         }
     }
 }
 protected function result()
 {
     add_action('automatic_updates_complete', array($this, 'get_update_results'), 100, 1);
     wp_maybe_auto_update();
     $result['log'] = $this->update_results;
     if (empty($result['log'])) {
         $possible_reasons_for_failure = Jetpack_Autoupdate::get_possible_failures();
         if ($possible_reasons_for_failure) {
             $result['log']['error'] = $possible_reasons_for_failure;
         }
     }
     return $result;
 }
 function update_translations()
 {
     include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     // Clear the cache.
     wp_clean_plugins_cache();
     ob_start();
     wp_update_plugins();
     // Check for Plugin updates
     ob_end_clean();
     $available_updates = get_site_transient('update_plugins');
     if (!isset($available_updates->translations) || empty($available_updates->translations)) {
         return new WP_Error('nothing_to_translate');
     }
     $update_attempted = false;
     $result = false;
     foreach ($this->plugins as $plugin) {
         $this->slug = Jetpack_Autoupdate::get_plugin_slug($plugin);
         $translation = array_filter($available_updates->translations, array($this, 'get_translation'));
         if (empty($translation)) {
             $this->log[$plugin][] = __('No update needed', 'jetpack');
             continue;
         }
         /**
          * Pre-upgrade action
          *
          * @since 4.4
          *
          * @param array $plugin Plugin data
          * @param array $plugin Array of plugin objects
          * @param bool $updated_attempted false for the first update, true subsequently
          */
         do_action('jetpack_pre_plugin_upgrade_translations', $plugin, $this->plugins, $update_attempted);
         $update_attempted = true;
         $skin = new Automatic_Upgrader_Skin();
         $upgrader = new Language_Pack_Upgrader($skin);
         $upgrader->init();
         $result = $upgrader->upgrade((object) $translation[0]);
         $this->log[$plugin] = $upgrader->skin->get_upgrade_messages();
     }
     if (!$this->bulk && !$result) {
         return new WP_Error('update_fail', __('There was an error updating your plugin', 'jetpack'), 400);
     }
     return true;
 }