+ wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
+
+ return true;
+ }
+
+ /**
+ * Bulk upgrade several plugins at once.
+ *
+ * @since 2.8.0
+ * @since 3.7.0 The `$args` parameter was added, making clearing the plugin update cache optional.
+ *
+ * @param array $plugins Array of the basename paths of the plugins' main files.
+ * @param array $args {
+ * Optional. Other arguments for upgrading several plugins at once. Default empty array.
+ *
+ * @type bool $clear_update_cache Whether to clear the plugin updates cache if successful.
+ * Default true.
+ * }
+ *
+ * @return array|false An array of results indexed by plugin file, or false if unable to connect to the filesystem.
+ */
+ public function bulk_upgrade( $plugins, $args = array() ) {
+
+ $defaults = array(
+ 'clear_update_cache' => true,
+ );
+ $parsed_args = wp_parse_args( $args, $defaults );
+
+ $this->init();
+ $this->bulk = true;
+ $this->upgrade_strings();
+
+ $current = get_site_transient( 'update_plugins' );
+
+ add_filter('upgrader_clear_destination', array($this, 'delete_old_plugin'), 10, 4);
+
+ $this->skin->header();
+
+ // Connect to the Filesystem first.
+ $res = $this->fs_connect( array(WP_CONTENT_DIR, WP_PLUGIN_DIR) );
+ if ( ! $res ) {
+ $this->skin->footer();
+ return false;
+ }
+
+ $this->skin->bulk_header();
+
+ // Only start maintenance mode if:
+ // - running Multisite and there are one or more plugins specified, OR
+ // - a plugin with an update available is currently active.
+ // @TODO: For multisite, maintenance mode should only kick in for individual sites if at all possible.
+ $maintenance = ( is_multisite() && ! empty( $plugins ) );
+ foreach ( $plugins as $plugin )
+ $maintenance = $maintenance || ( is_plugin_active( $plugin ) && isset( $current->response[ $plugin] ) );
+ if ( $maintenance )
+ $this->maintenance_mode(true);
+
+ $results = array();
+
+ $this->update_count = count($plugins);
+ $this->update_current = 0;
+ foreach ( $plugins as $plugin ) {
+ $this->update_current++;
+ $this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false, true);
+
+ if ( !isset( $current->response[ $plugin ] ) ) {
+ $this->skin->set_result('up_to_date');
+ $this->skin->before();
+ $this->skin->feedback('up_to_date');
+ $this->skin->after();
+ $results[$plugin] = true;
+ continue;
+ }
+
+ // Get the URL to the zip file
+ $r = $current->response[ $plugin ];
+
+ $this->skin->plugin_active = is_plugin_active($plugin);
+
+ $result = $this->run( array(
+ 'package' => $r->package,
+ 'destination' => WP_PLUGIN_DIR,
+ 'clear_destination' => true,
+ 'clear_working' => true,
+ 'is_multi' => true,
+ 'hook_extra' => array(
+ 'plugin' => $plugin
+ )
+ ) );
+
+ $results[$plugin] = $this->result;
+
+ // Prevent credentials auth screen from displaying multiple times
+ if ( false === $result )
+ break;
+ } //end foreach $plugins
+
+ $this->maintenance_mode(false);
+
+ /**
+ * Fires when the bulk upgrader process is complete.
+ *
+ * @since 3.6.0
+ *
+ * @param Plugin_Upgrader $this Plugin_Upgrader instance. In other contexts, $this, might
+ * be a Theme_Upgrader or Core_Upgrade instance.
+ * @param array $data {
+ * Array of bulk item update data.
+ *
+ * @type string $action Type of action. Default 'update'.
+ * @type string $type Type of update process. Accepts 'plugin', 'theme', or 'core'.
+ * @type bool $bulk Whether the update process is a bulk update. Default true.
+ * @type array $packages Array of plugin, theme, or core packages to update.
+ * }
+ */
+ do_action( 'upgrader_process_complete', $this, array(
+ 'action' => 'update',
+ 'type' => 'plugin',
+ 'bulk' => true,
+ 'plugins' => $plugins,
+ ) );
+
+ $this->skin->bulk_footer();
+
+ $this->skin->footer();
+
+ // Cleanup our hooks, in case something else does a upgrade on this connection.
+ remove_filter('upgrader_clear_destination', array($this, 'delete_old_plugin'));
+
+ // Force refresh of plugin update information
+ wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
+
+ return $results;
+ }
+
+ /**
+ * Check a source package to be sure it contains a plugin.
+ *
+ * This function is added to the {@see 'upgrader_source_selection'} filter by
+ * {@see Plugin_Upgrader::install()}.
+ *
+ * @since 3.3.0
+ *
+ * @global WP_Filesystem_Base $wp_filesystem Subclass
+ *
+ * @param string $source The path to the downloaded package source.
+ * @return string|WP_Error The source as passed, or a {@see WP_Error} object if no plugins were found.
+ */
+ public function check_package($source) {
+ global $wp_filesystem;
+
+ if ( is_wp_error($source) )
+ return $source;
+
+ $working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit(WP_CONTENT_DIR), $source);
+ if ( ! is_dir($working_directory) ) // Sanity check, if the above fails, let's not prevent installation.
+ return $source;
+
+ // Check the folder contains at least 1 valid plugin.
+ $plugins_found = false;
+ $files = glob( $working_directory . '*.php' );
+ if ( $files ) {
+ foreach ( $files as $file ) {
+ $info = get_plugin_data( $file, false, false );
+ if ( ! empty( $info['Name'] ) ) {
+ $plugins_found = true;
+ break;
+ }
+ }
+ }
+
+ if ( ! $plugins_found )
+ return new WP_Error( 'incompatible_archive_no_plugins', $this->strings['incompatible_archive'], __( 'No valid plugins were found.' ) );
+
+ return $source;