public function rollback($plugin, $args = array()) { $defaults = array('clear_update_cache' => true); $parsed_args = wp_parse_args($args, $defaults); $this->init(); $this->upgrade_strings(); // TODO: Add final check to make sure plugin exists if (0) { $this->skin->before(); $this->skin->set_result(false); $this->skin->error('up_to_date'); $this->skin->after(); return false; } $plugin_slug = $this->skin->plugin; $plugin_version = $this->skin->options['version']; $download_endpoint = 'https://downloads.wordpress.org/plugin/'; $url = $download_endpoint . $plugin_slug . '.' . $plugin_version . '.zip'; add_filter('upgrader_pre_install', array($this, 'deactivate_plugin_before_upgrade'), 10, 2); add_filter('upgrader_clear_destination', array($this, 'delete_old_plugin'), 10, 4); $this->run(array('package' => $url, 'destination' => WP_PLUGIN_DIR, 'clear_destination' => true, 'clear_working' => true, 'hook_extra' => array('plugin' => $plugin, 'type' => 'plugin', 'action' => 'update'))); // Cleanup our hooks, in case something else does a upgrade on this connection. remove_filter('upgrader_pre_install', array($this, 'deactivate_plugin_before_upgrade')); remove_filter('upgrader_clear_destination', array($this, 'delete_old_plugin')); if (!$this->result || is_wp_error($this->result)) { return $this->result; } // Force refresh of plugin update information wp_clean_plugins_cache($parsed_args['clear_update_cache']); return true; }
public static function updateFromZip($fileRaw, $updateInfo) { N2Loader::import('libraries.zip.zip_read'); $tmpHandle = tmpfile(); fwrite($tmpHandle, $fileRaw); $metaData = stream_get_meta_data($tmpHandle); $tmpFilename = $metaData['uri']; $_GET['plugins'] = $updateInfo['plugin']; include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; $upgrader = new Plugin_Upgrader(new Plugin_Upgrader_Skin(compact('title', 'nonce', 'url', 'plugin'))); $upgrader->init(); $upgrader->upgrade_strings(); add_filter('upgrader_pre_install', array($upgrader, 'deactivate_plugin_before_upgrade'), 10, 2); add_filter('upgrader_clear_destination', array($upgrader, 'delete_old_plugin'), 10, 4); $upgrader->run(array('package' => $tmpFilename, 'destination' => WP_PLUGIN_DIR, 'clear_destination' => true, 'clear_working' => true, 'hook_extra' => array('plugin' => $updateInfo['plugin'], 'type' => 'plugin', 'action' => 'update'))); // Cleanup our hooks, in case something else does a upgrade on this connection. remove_filter('upgrader_pre_install', array($upgrader, 'deactivate_plugin_before_upgrade')); remove_filter('upgrader_clear_destination', array($upgrader, 'delete_old_plugin')); // Force refresh of plugin update information wp_clean_plugins_cache(true); fclose($tmpHandle); include ABSPATH . 'wp-admin/admin-footer.php'; return true; }
public function languages_page() { // prepare the list of tabs $tabs = array('lang' => __('Languages', 'polylang')); // only if at least one language has been created if ($listlanguages = $this->model->get_languages_list()) { $tabs['strings'] = __('Strings translation', 'polylang'); $tabs['settings'] = __('Settings', 'polylang'); } // allows plugins to add tabs $tabs = apply_filters('pll_settings_tabs', $tabs); switch ($this->active_tab) { case 'lang': // prepare the list table of languages $list_table = new PLL_Table_Languages(); $list_table->prepare_items($listlanguages); break; case 'strings': // get the strings to translate $data = PLL_Admin_Strings::get_strings(); // get the groups foreach ($data as $key => $row) { $groups[] = $row['context']; } $groups = array_unique($groups); $selected = empty($_GET['group']) || !in_array($_GET['group'], $groups) ? -1 : $_GET['group']; $s = empty($_GET['s']) ? '' : wp_unslash($_GET['s']); // filter for search string foreach ($data as $key => $row) { if (-1 != $selected && $row['context'] != $selected || !empty($s) && stripos($row['name'], $s) === false && stripos($row['string'], $s) === false) { unset($data[$key]); } } // load translations foreach ($listlanguages as $language) { // filters by language if requested if (($lg = get_user_meta(get_current_user_id(), 'pll_filter_content', true)) && $language->slug != $lg) { continue; } $mo = new PLL_MO(); $mo->import_from_db($language); foreach ($data as $key => $row) { $data[$key]['translations'][$language->slug] = $mo->translate($row['string']); $data[$key]['row'] = $key; // store the row number for convenience } } // get an array with language slugs as keys, names as values $languages = array_combine(wp_list_pluck($listlanguages, 'slug'), wp_list_pluck($listlanguages, 'name')); $string_table = new PLL_Table_String(compact('languages', 'groups', 'selected')); $string_table->prepare_items($data); break; case 'settings': $post_types = get_post_types(array('public' => true, '_builtin' => false)); $post_types = array_diff($post_types, get_post_types(array('_pll' => true))); $post_types = array_unique(apply_filters('pll_get_post_types', $post_types, true)); $taxonomies = get_taxonomies(array('public' => true, '_builtin' => false)); $taxonomies = array_diff($taxonomies, get_taxonomies(array('_pll' => true))); $taxonomies = array_unique(apply_filters('pll_get_taxonomies', $taxonomies, true)); break; } $action = isset($_REQUEST['pll_action']) ? $_REQUEST['pll_action'] : ''; switch ($action) { case 'add': check_admin_referer('add-lang', '_wpnonce_add-lang'); if ($this->model->add_language($_POST) && 'en_US' != $_POST['locale']) { // attempts to install the language pack require_once ABSPATH . 'wp-admin/includes/translation-install.php'; if (!wp_download_language_pack($_POST['locale'])) { add_settings_error('general', 'pll_download_mo', __('The language was created, but the WordPress language file was not downloaded. Please install it manually.', 'polylang')); } // force checking for themes and plugins translations updates wp_clean_themes_cache(); wp_clean_plugins_cache(); } self::redirect(); // to refresh the page ( possible thanks to the $_GET['noheader']=true ) break; case 'delete': check_admin_referer('delete-lang'); if (!empty($_GET['lang'])) { $this->model->delete_language((int) $_GET['lang']); } self::redirect(); // to refresh the page ( possible thanks to the $_GET['noheader']=true ) break; case 'edit': if (!empty($_GET['lang'])) { $edit_lang = $this->model->get_language((int) $_GET['lang']); } break; case 'update': check_admin_referer('add-lang', '_wpnonce_add-lang'); $error = $this->model->update_language($_POST); self::redirect(); // to refresh the page ( possible thanks to the $_GET['noheader']=true ) break; case 'default-lang': check_admin_referer('default-lang'); if ($lang = $this->model->get_language((int) $_GET['lang'])) { $this->model->update_default_lang($lang->slug); } self::redirect(); // to refresh the page ( possible thanks to the $_GET['noheader']=true ) break; case 'content-default-lang': check_admin_referer('content-default-lang'); if ($nolang = $this->model->get_objects_with_no_lang()) { if (!empty($nolang['posts'])) { $this->model->set_language_in_mass('post', $nolang['posts'], $this->options['default_lang']); } if (!empty($nolang['terms'])) { $this->model->set_language_in_mass('term', $nolang['terms'], $this->options['default_lang']); } } self::redirect(); // to refresh the page ( possible thanks to the $_GET['noheader']=true ) break; case 'string-translation': if (!empty($_POST['submit'])) { check_admin_referer('string-translation', '_wpnonce_string-translation'); $strings = PLL_Admin_Strings::get_strings(); foreach ($this->model->get_languages_list() as $language) { if (empty($_POST['translation'][$language->slug])) { // in case the language filter is active ( thanks to John P. Bloch ) continue; } $mo = new PLL_MO(); $mo->import_from_db($language); foreach ($_POST['translation'][$language->slug] as $key => $translation) { $translation = apply_filters('pll_sanitize_string_translation', $translation, $strings[$key]['name'], $strings[$key]['context']); $mo->add_entry($mo->make_entry($strings[$key]['string'], $translation)); } // clean database ( removes all strings which were registered some day but are no more ) if (!empty($_POST['clean'])) { $new_mo = new PLL_MO(); foreach ($strings as $string) { $new_mo->add_entry($mo->make_entry($string['string'], $mo->translate($string['string']))); } } isset($new_mo) ? $new_mo->export_to_db($language) : $mo->export_to_db($language); } add_settings_error('general', 'pll_strings_translations_updated', __('Translations updated.', 'polylang'), 'updated'); do_action('pll_save_strings_translations'); } // unregisters strings registered through WPML API if ($string_table->current_action() == 'delete' && !empty($_POST['strings']) && function_exists('icl_unregister_string')) { check_admin_referer('string-translation', '_wpnonce_string-translation'); $strings = PLL_Admin_Strings::get_strings(); foreach ($_POST['strings'] as $key) { icl_unregister_string($strings[$key]['context'], $strings[$key]['name']); } } // to refresh the page ( possible thanks to the $_GET['noheader']=true ) $args = array_intersect_key($_REQUEST, array_flip(array('s', 'paged', 'group'))); if (!empty($args['s'])) { $args['s'] = urlencode($args['s']); // searched string needs to be encoded as it comes from $_POST } self::redirect($args); break; case 'activate': check_admin_referer('pll_activate'); $this->modules[$_GET['module']]->activate(); self::redirect(); break; case 'deactivate': check_admin_referer('pll_deactivate'); $this->modules[$_GET['module']]->deactivate(); self::redirect(); break; default: do_action("mlang_action_{$action}"); break; } // displays the page include PLL_SETTINGS_INC . '/view-languages.php'; }
function wp_install_plugins($array) { require_once $this->data['dir'] . '/wp-admin/includes/class-wp-upgrader.php'; global $WPQI_Installer_Skin; $WPQI_Installer_Skin(); foreach ($array as $name) { if (!$name) { continue; } $is_url = preg_match("/^(http|https):\\/\\//i", $name); $url = $is_url ? $name : "https://downloads.wordpress.org/plugin/{$name}.zip"; $upgrader = new Plugin_Upgrader(new WPQI_Installer_Skin()); $upgrader->install($url); activate_plugin($upgrader->plugin_info()); } wp_clean_plugins_cache(); }
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; }
/** * Install a plugin from .org in the background via a cron job (used by * installer - opt in). * @param string $plugin_to_install_id * @param array $plugin_to_install * @since 2.6.0 */ public static function background_installer($plugin_to_install_id, $plugin_to_install) { if (!empty($plugin_to_install['repo-slug'])) { require_once ABSPATH . 'wp-admin/includes/file.php'; require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; require_once ABSPATH . 'wp-admin/includes/plugin.php'; WP_Filesystem(); $skin = new Automatic_Upgrader_Skin(); $upgrader = new WP_Upgrader($skin); $installed_plugins = array_map(array(__CLASS__, 'format_plugin_slug'), array_keys(get_plugins())); $plugin_slug = $plugin_to_install['repo-slug']; $plugin = $plugin_slug . '/' . $plugin_slug . '.php'; $installed = false; $activate = false; // See if the plugin is installed already if (in_array($plugin_to_install['repo-slug'], $installed_plugins)) { $installed = true; $activate = !is_plugin_active($plugin); } // Install this thing! if (!$installed) { // Suppress feedback ob_start(); try { $plugin_information = plugins_api('plugin_information', array('slug' => $plugin_to_install['repo-slug'], 'fields' => array('short_description' => false, 'sections' => false, 'requires' => false, 'rating' => false, 'ratings' => false, 'downloaded' => false, 'last_updated' => false, 'added' => false, 'tags' => false, 'homepage' => false, 'donate_link' => false, 'author_profile' => false, 'author' => false))); if (is_wp_error($plugin_information)) { throw new Exception($plugin_information->get_error_message()); } $package = $plugin_information->download_link; $download = $upgrader->download_package($package); if (is_wp_error($download)) { throw new Exception($download->get_error_message()); } $working_dir = $upgrader->unpack_package($download, true); if (is_wp_error($working_dir)) { throw new Exception($working_dir->get_error_message()); } $result = $upgrader->install_package(array('source' => $working_dir, 'destination' => WP_PLUGIN_DIR, 'clear_destination' => false, 'abort_if_destination_exists' => false, 'clear_working' => true, 'hook_extra' => array('type' => 'plugin', 'action' => 'install'))); if (is_wp_error($result)) { throw new Exception($result->get_error_message()); } $activate = true; } catch (Exception $e) { WC_Admin_Notices::add_custom_notice($plugin_to_install_id . '_install_error', sprintf(__('%1$s could not be installed (%2$s). <a href="%3$s">Please install it manually by clicking here.</a>', 'woocommerce'), $plugin_to_install['name'], $e->getMessage(), esc_url(admin_url('index.php?wc-install-plugin-redirect=' . $plugin_to_install['repo-slug'])))); } // Discard feedback ob_end_clean(); } wp_clean_plugins_cache(); // Activate this thing if ($activate) { try { $result = activate_plugin($plugin); if (is_wp_error($result)) { throw new Exception($result->get_error_message()); } } catch (Exception $e) { WC_Admin_Notices::add_custom_notice($plugin_to_install_id . '_install_error', sprintf(__('%1$s was installed but could not be activated. <a href="%2$s">Please activate it manually by clicking here.</a>', 'woocommerce'), $plugin_to_install['name'], admin_url('plugins.php'))); } } } }
protected function update() { wp_clean_plugins_cache(); ob_start(); wp_update_plugins(); // Check for Plugin updates ob_end_clean(); $update_plugins = get_site_transient('update_plugins'); if (isset($update_plugins->response)) { $plugin_updates_needed = array_keys($update_plugins->response); } else { $plugin_updates_needed = array(); } $update_attempted = false; include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; // unhook this functions that output things before we send our response header. 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_themes'); $result = false; foreach ($this->plugins as $plugin) { if (!in_array($plugin, $plugin_updates_needed)) { $this->log[$plugin][] = __('No update needed', 'jetpack'); continue; } /** * Pre-upgrade action * * @since 3.9.3 * * @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', $plugin, $this->plugins, $update_attempted); $update_attempted = true; // Object created inside the for loop to clean the messages for each plugin $skin = new Automatic_Upgrader_Skin(); // The Automatic_Upgrader_Skin skin shouldn't output anything. $upgrader = new Plugin_Upgrader($skin); $upgrader->init(); // This avoids the plugin to be deactivated. defined('DOING_CRON') or define('DOING_CRON', true); $result = $upgrader->upgrade($plugin); $this->log[$plugin][] = $upgrader->skin->get_upgrade_messages(); } if (!$this->bulk && !$result && $update_attempted) { return new WP_Error('update_fail', __('There was an error updating your plugin', 'jetpack'), 400); } return $this->default_action(); }
/** * Clear existing update caches for plugins, themes, and core. * * @since 4.1.0 */ function wp_clean_update_cache() { if (function_exists('wp_clean_plugins_cache')) { wp_clean_plugins_cache(); } else { delete_site_transient('update_plugins'); } wp_clean_themes_cache(); delete_site_transient('update_core'); }
/** * Manages the user input for the languages pages * * @since 1.9 * * @param string $action */ public function handle_actions($action) { switch ($action) { case 'add': check_admin_referer('add-lang', '_wpnonce_add-lang'); if ($this->model->add_language($_POST) && 'en_US' !== $_POST['locale']) { // attempts to install the language pack require_once ABSPATH . 'wp-admin/includes/translation-install.php'; if (!wp_download_language_pack($_POST['locale'])) { add_settings_error('general', 'pll_download_mo', __('The language was created, but the WordPress language file was not downloaded. Please install it manually.', 'polylang')); } // force checking for themes and plugins translations updates wp_clean_themes_cache(); wp_clean_plugins_cache(); } self::redirect(); // to refresh the page ( possible thanks to the $_GET['noheader']=true ) break; case 'delete': check_admin_referer('delete-lang'); if (!empty($_GET['lang'])) { $this->model->delete_language((int) $_GET['lang']); } self::redirect(); // to refresh the page ( possible thanks to the $_GET['noheader']=true ) break; case 'update': check_admin_referer('add-lang', '_wpnonce_add-lang'); $error = $this->model->update_language($_POST); self::redirect(); // to refresh the page ( possible thanks to the $_GET['noheader']=true ) break; case 'default-lang': check_admin_referer('default-lang'); if ($lang = $this->model->get_language((int) $_GET['lang'])) { $this->model->update_default_lang($lang->slug); } self::redirect(); // to refresh the page ( possible thanks to the $_GET['noheader']=true ) break; case 'content-default-lang': check_admin_referer('content-default-lang'); if ($nolang = $this->model->get_objects_with_no_lang()) { if (!empty($nolang['posts'])) { $this->model->set_language_in_mass('post', $nolang['posts'], $this->options['default_lang']); } if (!empty($nolang['terms'])) { $this->model->set_language_in_mass('term', $nolang['terms'], $this->options['default_lang']); } } self::redirect(); // to refresh the page ( possible thanks to the $_GET['noheader']=true ) break; case 'activate': check_admin_referer('pll_activate'); $this->modules[$_GET['module']]->activate(); self::redirect(); break; case 'deactivate': check_admin_referer('pll_deactivate'); $this->modules[$_GET['module']]->deactivate(); self::redirect(); break; default: /** * Fires when a non default action has been sent to Polylang settings * * @since 1.8 */ do_action("mlang_action_{$action}"); break; } }
protected function update() { include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; // unhook this functions that output things before we send our response header. 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_themes'); foreach ($this->plugins as $plugin) { wp_clean_plugins_cache(); ob_start(); wp_update_plugins(); // Check for Plugin updates ob_end_clean(); // Object created inside the for loop to clean the messages for each plugin $skin = new Automatic_Upgrader_Skin(); // The Automatic_Upgrader_Skin skin shouldn't output anything. $upgrader = new Plugin_Upgrader($skin); $upgrader->init(); $result = $upgrader->upgrade($plugin); $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 $this->default_action(); }
function install_bsf_product($install_id) { global $bsf_product_validate_url, $bsf_support_url; if (!current_user_can('install_plugins')) { wp_die(__('You do not have sufficient permissions to install plugins for this site.', 'bsf')); } $brainstrom_bundled_products = get_option('brainstrom_bundled_products') ? get_option('brainstrom_bundled_products') : array(); $install_product_data = array(); if (!empty($brainstrom_bundled_products)) { foreach ($brainstrom_bundled_products as $keys => $products) { if (strlen($keys) > 1) { foreach ($products as $key => $product) { if ($product->id === $install_id) { $install_product_data = $product; break; } } } else { if ($products->id === $install_id) { $install_product_data = $products; break; } } } } if (empty($install_product_data)) { return false; } if ($install_product_data->type !== 'plugin') { return false; } /* temp */ /*$install_product_data->in_house = 'wp'; $install_product_data->download_url = 'https://downloads.wordpress.org/plugin/redux-framework.3.5.9.zip';*/ $is_wp = isset($install_product_data->in_house) && $install_product_data->in_house === 'wp' ? true : false; if ($is_wp) { $download_path = $install_product_data->download_url; } else { $path = $bsf_product_validate_url; $timezone = date_default_timezone_get(); $call = 'file=' . $install_product_data->download_url . '&hashtime=' . strtotime(date('d-m-Y h:i:s a')) . '&timezone=' . $timezone; $hash = $call; //$parse = parse_url($path); //$download = $parse['scheme'].'://'.$parse['host']; $get_path = 'http://downloads.brainstormforce.com/'; $download_path = rtrim($get_path, '/') . '/download.php?' . $hash . '&base=ignore'; } require_once ABSPATH . '/wp-admin/includes/file.php'; WP_Filesystem(); global $wp_filesystem; require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; $WP_Upgrader = new WP_Upgrader(); $res = $WP_Upgrader->fs_connect(array(WP_CONTENT_DIR)); if (!$res) { wp_die(new WP_Error('Server error', __("Error! Can't connect to filesystem", 'bsf'))); } $Plugin_Upgrader = new Plugin_Upgrader(); $defaults = array('clear_update_cache' => true); $args = array(); $parsed_args = wp_parse_args($args, $defaults); $Plugin_Upgrader->init(); $Plugin_Upgrader->install_strings(); $Plugin_Upgrader->strings['downloading_package'] = __('Downloading package from Server', 'bsf'); $Plugin_Upgrader->strings['remove_old'] = __('Removing old plugin, if exists', 'bsf'); add_filter('upgrader_source_selection', array($Plugin_Upgrader, 'check_package')); $Plugin_Upgrader->run(array('package' => $download_path, 'destination' => WP_PLUGIN_DIR, 'clear_destination' => true, 'clear_working' => true, 'hook_extra' => array('type' => 'plugin', 'action' => 'install'))); remove_filter('upgrader_source_selection', array($Plugin_Upgrader, 'check_package')); if (!$Plugin_Upgrader->result || is_wp_error($Plugin_Upgrader->result)) { return $Plugin_Upgrader->result; } // Force refresh of plugin update information wp_clean_plugins_cache($parsed_args['clear_update_cache']); //return true; $response = array('status' => true, 'type' => 'plugin', 'name' => $install_product_data->name, 'init' => $install_product_data->init); $plugin_abs_path = WP_PLUGIN_DIR . '/' . $install_product_data->init; if (is_file($plugin_abs_path)) { if (!isset($_GET['action']) && !isset($_GET['id'])) { echo '|bsf-plugin-installed|'; } $is_plugin_installed = true; if (!is_plugin_active($install_product_data->init)) { activate_plugin($install_product_data->init); if (is_plugin_active($install_product_data->init)) { if (!isset($_GET['action']) && !isset($_GET['id'])) { echo '|bsf-plugin-activated|'; } } } else { if (!isset($_GET['action']) && !isset($_GET['id'])) { echo '|bsf-plugin-activated|'; } } } return $response; }
/** * Performs the actual installation of each plugin. * * This method also activates the plugin in the automatic flag has been * set to true for the TGMPA class. * * @since 2.2.0 * * @param array $options The installation config options * @return null/array Return early if error, array of installation data on success */ public function run($options) { // Default config options. $defaults = array('package' => '', 'destination' => '', 'clear_destination' => false, 'clear_working' => true, 'is_multi' => false, 'hook_extra' => array()); // Parse default options with config options from $this->bulk_upgrade and extract them. $options = wp_parse_args($options, $defaults); extract($options); // Connect to the Filesystem. $res = $this->fs_connect(array(WP_CONTENT_DIR, $destination)); if (!$res) { return false; } // Return early if there is an error connecting to the Filesystem. if (is_wp_error($res)) { $this->skin->error($res); return $res; } // Call $this->header separately if running multiple times. if (!$is_multi) { $this->skin->header(); } // Set strings before the package is installed. $this->skin->before(); // Download the package (this just returns the filename of the file if the package is a local file). $download = $this->download_package($package); if (is_wp_error($download)) { $this->skin->error($download); $this->skin->after(); return $download; } // Don't accidentally delete a local file. $delete_package = $download != $package; // Unzip file into a temporary working directory. $working_dir = $this->unpack_package($download, $delete_package); if (is_wp_error($working_dir)) { $this->skin->error($working_dir); $this->skin->after(); return $working_dir; } // Install the package into the working directory with all passed config options. $result = $this->install_package(array('source' => $working_dir, 'destination' => $destination, 'clear_destination' => $clear_destination, 'clear_working' => $clear_working, 'hook_extra' => $hook_extra)); // Pass the result of the installation. $this->skin->set_result($result); // Set correct strings based on results. if (is_wp_error($result)) { $this->skin->error($result); $this->skin->feedback('process_failed'); } else { $this->skin->feedback('process_success'); } // Only process the activation of installed plugins if the automatic flag is set to true. if (TGM_Plugin_Activation::$instance->is_automatic) { // Flush plugins cache so we can make sure that the installed plugins list is always up to date. wp_cache_flush(); // Get the installed plugin file and activate it. $plugin_info = $this->plugin_info($package); $activate = activate_plugin($plugin_info); // Re-populate the file path now that the plugin has been installed and activated. TGM_Plugin_Activation::$instance->populate_file_path(); // Set correct strings based on results. if (is_wp_error($activate)) { $this->skin->error($activate); $this->skin->feedback('activation_failed'); } else { $this->skin->feedback('activation_success'); } } // Flush plugins cache so we can make sure that the installed plugins list is always up to date. if ($hook_extra['update']) { // Force refresh of plugin update information wp_clean_plugins_cache(true); } else { wp_cache_flush(); } // Set install footer strings. $this->skin->after(); if (!$is_multi) { $this->skin->footer(); } return $result; }
function upgrade_bsf_product($request_product_id, $bundled_id) { global $bsf_product_validate_url, $bsf_support_url; global $ULT_UPGRADE_AJAX; $ajax = isset($ULT_UPGRADE_AJAX) ? $ULT_UPGRADE_AJAX : false; if (!current_user_can('update_plugins')) { if ($ajax) { return __('You do not have sufficient permissions to update plugins for this site.', 'bsf'); } else { wp_die(__('You do not have sufficient permissions to update plugins for this site.', 'bsf')); } } $brainstrom_users = get_option('brainstrom_users') ? get_option('brainstrom_users') : array(); $brainstrom_products = get_option('brainstrom_products') ? get_option('brainstrom_products') : array(); $brainstrom_bundled_products = get_option('brainstrom_bundled_products') ? get_option('brainstrom_bundled_products') : array(); $plugins = $themes = $mix = array(); if (!empty($brainstrom_products)) { $plugins = isset($brainstrom_products['plugins']) ? $brainstrom_products['plugins'] : array(); $themes = isset($brainstrom_products['themes']) ? $brainstrom_products['themes'] : array(); } $mix = array_merge($plugins, $themes); $bsf_username = $purchase_key = $type = $template = $name = ''; if (!empty($brainstrom_users)) { foreach ($brainstrom_users as $bsf_user) { $bsf_username = $bsf_user['email']; } } $found_in_bsf_products = false; if ($bundled_id !== false) { $product_details_id = $bundled_id; } else { $product_details_id = $request_product_id; } foreach ($mix as $key => $product) { $pid = $product['id']; if ($pid === $product_details_id) { $purchase_key = isset($product['purchase_key']) ? $product['purchase_key'] : NULL; $type = $product['type']; $template = $product['template']; $name = $product['product_name']; $found_in_bsf_products = true; break; } } if ($bundled_id !== false) { if (!empty($brainstrom_bundled_products)) { foreach ($brainstrom_bundled_products as $bps) { foreach ($bps as $key => $bp) { if ($bp->id === $request_product_id) { $type = $bp->type; $template = $bp->init; $name = $bp->name; } } } } } if ($bsf_username === '' || $purchase_key === '' || $request_product_id === '') { if ($ajax) { return __('Not valid to update product', 'bsf'); } else { wp_die('Not valid to update product'); } } $path = $bsf_product_validate_url; $data = array('action' => 'bsf_product_update_request', 'id' => $request_product_id, 'username' => $bsf_username, 'purchase_key' => $purchase_key, 'site_url' => get_site_url(), 'bundled' => $bundled_id); $request = @wp_remote_post($path, array('body' => $data, 'timeout' => '60', 'sslverify' => false)); if (!is_wp_error($request) || wp_remote_retrieve_response_code($request) === 200) { $result = json_decode($request['body']); if (isset($result->error) && !$result->error) { $download_path = $result->update_data->download_url; $timezone = date_default_timezone_get(); $call = 'file=' . $download_path . '&hashtime=' . strtotime(date('d-m-Y h:i:s a')) . '&timezone=' . $timezone; $hash = $call; $parse = parse_url($path); $download = $parse['scheme'] . '://' . $parse['host']; $get_path = 'http://downloads.brainstormforce.com/'; $download_path = rtrim($get_path, '/') . '/download.php?' . $hash . '&base=ignore'; //echo $download_path; //die(); require_once ABSPATH . '/wp-admin/includes/file.php'; WP_Filesystem(); global $wp_filesystem; require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; $WP_Upgrader = new WP_Upgrader(); $res = $WP_Upgrader->fs_connect(array(WP_CONTENT_DIR)); if (!$res) { wp_die(new WP_Error('Server error', __("Error! Can't connect to filesystem", 'bsf'))); } else { $upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade_tmp/bsf_package'; $package_filename = basename($download_path); $plugin_folder = dirname($template); if ($type === 'theme' && $bundled_id === false) { $defaults = array('clear_update_cache' => true); $args = array(); $parsed_args = wp_parse_args($args, $defaults); $Theme_Upgrader = new Theme_Upgrader(); $Theme_Upgrader->init(); $Theme_Upgrader->upgrade_strings(); $Theme_Upgrader->strings['downloading_package'] = __('Downloading package from Server', 'bsf'); add_filter('upgrader_pre_install', array(&$Theme_Upgrader, 'current_before'), 10, 2); add_filter('upgrader_post_install', array(&$Theme_Upgrader, 'current_after'), 10, 2); add_filter('upgrader_clear_destination', array(&$Theme_Upgrader, 'delete_old_theme'), 10, 4); $Theme_Upgrader->run(array('package' => $download_path, 'destination' => get_theme_root($template), 'clear_destination' => true, 'abort_if_destination_exists' => false, 'clear_working' => true, 'hook_extra' => array('theme' => $template, 'type' => 'theme', 'action' => 'update'))); remove_filter('upgrader_pre_install', array(&$Theme_Upgrader, 'current_before')); remove_filter('upgrader_post_install', array(&$Theme_Upgrader, 'current_after')); remove_filter('upgrader_clear_destination', array(&$Theme_Upgrader, 'delete_old_theme')); if (!$Theme_Upgrader->result || is_wp_error($Theme_Upgrader->result)) { return $Theme_Upgrader->result; } wp_clean_themes_cache($parsed_args['clear_update_cache']); $response = array('status' => true, 'type' => 'theme', 'name' => $name); return $response; } elseif ($type === 'plugin') { $is_activated = is_plugin_active($template); $Plugin_Upgrader = new Plugin_Upgrader(); $defaults = array('clear_update_cache' => true); $Plugin_Upgrader->init(); $Plugin_Upgrader->upgrade_strings(); $Plugin_Upgrader->strings['downloading_package'] = __('Downloading package from Server', 'bsf'); add_filter('upgrader_pre_install', array($Plugin_Upgrader, 'deactivate_plugin_before_upgrade'), 10, 2); add_filter('upgrader_clear_destination', array($Plugin_Upgrader, 'delete_old_plugin'), 10, 4); //'source_selection' => array($this, 'source_selection'), //there's a trac ticket to move up the directory for zip's which are made a bit differently, useful for non-.org plugins. $Plugin_Upgrader->run(array('package' => $download_path, 'destination' => WP_PLUGIN_DIR, 'clear_destination' => true, 'clear_working' => true, 'hook_extra' => array('plugin' => $template, 'type' => 'plugin', 'action' => 'update'))); // Cleanup our hooks, in case something else does a upgrade on this connection. remove_filter('upgrader_pre_install', array($Plugin_Upgrader, 'deactivate_plugin_before_upgrade')); remove_filter('upgrader_clear_destination', array($Plugin_Upgrader, 'delete_old_plugin')); if (!$Plugin_Upgrader->result || is_wp_error($Plugin_Upgrader->result)) { return $Plugin_Upgrader->result; } // Force refresh of plugin update information wp_clean_plugins_cache($defaults['clear_update_cache']); if ($is_activated) { activate_plugin($template); } $response = array('status' => true, 'type' => 'plugin', 'name' => $name); return $response; } } } else { if ($ajax) { return $result->message; } else { echo $result->message; } } } else { if ($ajax) { return $request->get_error_message(); } else { echo $request->get_error_message(); } } }
private function activate_plugins() { echo '<h3>' . esc_html__('Activating plugins...', '1and1-wordpress-wizard') . '</h3>'; require_once ABSPATH . '/wp-admin/includes/plugin.php'; wp_clean_plugins_cache(true); $plugins = get_plugins(); $plugin_slugs = wp_list_pluck($this->plugins, 'slug'); foreach ($plugins as $key => $plugin) { $parts = explode('/', $key); if (in_array($parts[0], $plugin_slugs)) { activate_plugin($key); } } }
/** * Manipulate addon. * * @param string $addon Addon to manipulate. * @param string $action Action to execute. * * @return array */ protected static function execute($addon, $action) { // Check capabilities foreach (self::$actions as $do => $capability) { if ($action == $do && !empty($capability) && !current_user_can($capability)) { throw new Exception(__('You do not have sufficient permissions to either add or delete plugins for this site.')); } } // Check if addon should be updated or removed if ('update' == $action || 'uninstall' == $action) { // Get plugin slug $plugin = self::check($addon, false); if (empty($plugin)) { throw new Exception(__('update' == $action ? 'Cannot detect plugin to be updated.' : 'Cannot detect plugin to be removed.', IG_LIBRARY_TEXTDOMAIN)); } } // Check if addon should be removed if ('uninstall' == $action) { $result = delete_plugins(array($plugin)); // Verify uninstallation result if (is_wp_error($result)) { throw new Exception($result->get_error_message()); } } else { // Verify authentication data $authentication = (bool) $_GET['authentication']; $username = isset($_POST['username']) ? $_POST['username'] : ''; $password = isset($_POST['password']) ? $_POST['password'] : ''; if ($authentication && (empty($username) || empty($password))) { // Check if user has customer account saved $customer_account = get_option('ig_customer_account', null); if (is_array($customer_account) && !@empty($customer_account['username']) && !@empty($customer_account['password'])) { $username = $customer_account['username']; $password = $customer_account['password']; } else { throw new Exception(null); } } // Try to authenticate or download addon installation package try { $package = self::download($addon, $authentication, $username, $password, 'authenticate' == $action); } catch (Exception $e) { throw $e; } // Get WordPress's WordPress Filesystem Abstraction object $wp_filesystem = IG_Init_File_System::get_instance(); // Check if addon should be installed or updated if ('authenticate' != $action) { // Verify core and add-on compatibility if (isset($_GET['core']) && ($core = self::get($_GET['core']))) { // Extract downloaded add-on package $tmp_dir = substr($package, 0, -4); $result = unzip_file($package, $tmp_dir); if (is_wp_error($result)) { throw new Exception($result->get_error_message()); } // Find constant definition file if (@is_file("{$tmp_dir}/defines.php")) { include "{$tmp_dir}/defines.php"; } elseif (count($defines = glob("{$tmp_dir}/*/defines.php"))) { include current($defines); } // Get minimum core version required for this add-on if (defined($core_version = strtoupper($addon) . '_CORE_VERSION')) { eval('$core_version = ' . $core_version . ';'); } if ($core_version && version_compare($core_version, $core['Version'], '>')) { // Delete downloaded add-on package and clean-up temporary directory $wp_filesystem->delete($package); $wp_filesystem->delete($tmp_dir, true); // Skip add-on installation throw new Exception(sprintf(__("Cannot install %1\$s v%2\$s.\nThis version requires %3\$s v%4\$s while you are using %5\$s v%6\$s.", IG_LIBRARY_TEXTDOMAIN), $core['Addons'][$addon]->name, $core['Addons'][$addon]->version, $core['Name'], $core_version, $core['Name'], $core['Version'])); } // Verification done, clean-up temporary directory $wp_filesystem->delete($tmp_dir, true); } // Init WordPress Plugin Upgrader class_exists('Plugin_Upgrader') || (include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'); function_exists('screen_icon') || (include_once ABSPATH . 'wp-admin/includes/screen.php'); function_exists('show_message') || (include_once ABSPATH . 'wp-admin/includes/misc.php'); function_exists('get_plugin_data') || (include_once ABSPATH . 'wp-admin/includes/plugin.php'); // Either install or update add-on $upgrader = new Plugin_Upgrader(); if ('install' == $action) { // Install plugin $result = $upgrader->install($package); // Verify installation result if (is_wp_error($result)) { throw new Exception($result->get_error_message()); } } else { // Update plugin add_filter('upgrader_pre_install', array($upgrader, 'deactivate_plugin_before_upgrade'), 10, 2); add_filter('upgrader_clear_destination', array($upgrader, 'delete_old_plugin'), 10, 4); $upgrader->run(array('package' => $package, 'destination' => WP_PLUGIN_DIR, 'clear_destination' => true, 'clear_working' => true, 'hook_extra' => array('plugin' => $plugin, 'type' => 'plugin', 'action' => 'update'))); remove_filter('upgrader_pre_install', array($upgrader, 'deactivate_plugin_before_upgrade')); remove_filter('upgrader_clear_destination', array($upgrader, 'delete_old_plugin')); if (is_wp_error($upgrader->result)) { throw new Exception($upgrader->result->get_error_message()); } // Force refresh of plugin update information if (function_exists('wp_clean_plugins_cache')) { wp_clean_plugins_cache(true); } } // Try to activate plugin try { $result = self::activate($addon, $action); } catch (Exception $e) { throw $e; } // Remove downloaded add-on installation package $wp_filesystem->delete($package); } else { // Check if user want to save customer account if (isset($_POST['remember']) && (bool) $_POST['remember']) { update_option('ig_customer_account', array('username' => $username, 'password' => $password)); } } } // Return data return is_array($result) ? $result : array('success' => true, 'addon' => $addon, 'action' => $action, 'message' => 'authenticate' == $action ? json_decode($wp_filesystem->get_contents($package)) : null); }
/** * 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); }
/** * 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. * @access public * * @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); // Force refresh of plugin update information. wp_clean_plugins_cache($parsed_args['clear_update_cache']); /** This action is documented in wp-admin/includes/class-wp-upgrader.php */ 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')); return $results; }
/** * Flushes the plugins cache on theme switch to prevent stale entries * from remaining in the plugin table. * * @since 2.4.0 */ public function flush_plugins_cache() { wp_clean_plugins_cache(); }
/** * 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'); }
/** * 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); }
/** * Install plugin action. * * @return void */ protected function install_plugin_action() { try { // Get plugin being installed $plugin = isset($_GET['plugin']) ? $_GET['plugin'] : null; if (empty($plugin)) { throw new Exception(__('Missing parameter.', 'ferado')); } // Get sample data XML declaration $xml = $this->_parse_sample_data(); // Get plugin details $plugin = $xml->xpath('//product/extension[@name="' . $plugin . '"]'); $plugin = current($plugin); $state = $this->_get_plugin_state((string) $plugin['name'], (string) $plugin['version']); if ('installed' != $state) { // Generate path to store downloaded plugin package $path = wp_upload_dir(); $path = $path['basedir'] . '/' . $this->id . '-sample-data/' . str_replace(' ', '-', (string) $plugin['name']) . '.zip'; // Download requested plugin package $valid_headers = array('content-type' => array('application/zip', 'application/x-zip', 'application/x-zip-compressed', 'application/octet-stream', 'application/x-compress', 'application/x-compressed', 'multipart/x-zip')); $this->_download((string) $plugin['downloadurl'], $path, $valid_headers); // Init WordPress Plugin Upgrader $upgrader = new Plugin_Upgrader(); if ('update' == $state) { // Get relative path to plugin's main file $plugin = $this->_get_plugin_path((string) $plugin['name']); // Let WordPress upgrade requested plugin add_filter('upgrader_pre_install', array($upgrader, 'deactivate_plugin_before_upgrade'), 10, 2); add_filter('upgrader_clear_destination', array($upgrader, 'delete_old_plugin'), 10, 4); $upgrader->run(array('package' => $path, 'destination' => WP_PLUGIN_DIR, 'clear_destination' => true, 'clear_working' => true, 'hook_extra' => array('plugin' => $plugin, 'type' => 'plugin', 'action' => 'update'))); // Cleanup our hooks, in case something else does a upgrade on this connection. remove_filter('upgrader_pre_install', array($upgrader, 'deactivate_plugin_before_upgrade')); remove_filter('upgrader_clear_destination', array($upgrader, 'delete_old_plugin')); if (!$upgrader->result || is_wp_error($upgrader->result)) { throw new Exception(sprintf(__('Upgrade plugin failed: %s', 'ferado'), $upgrader->result ? $upgrader->result->get_error_message() : __('Unknown reason', 'ferado'))); } // Force refresh of plugin update information if (function_exists('wp_clean_plugins_cache')) { wp_clean_plugins_cache(true); } } else { // Let WordPress install requested plugin $result = $upgrader->install($path); if (!$result || is_wp_error($result)) { throw new Exception(sprintf(__('Plugin installation failed: %s', 'ferado'), $result ? $result->get_error_message() : __('Unknown reason', 'ferado'))); } // Get relative path to plugin's main file $plugin = $this->_get_plugin_path((string) $plugin['name']); // Let WordPress activate the newly installed plugin $result = activate_plugin($plugin, '', is_network_admin(), true); if (is_wp_error($result) && 'unexpected_output' != $result->get_error_code()) { throw new Exception(sprintf(__('Plugin activation failed: %s', 'ferado'), $result->get_error_message())); } } } } catch (Exception $e) { throw $e; } }
/** * Flushes the plugins cache on theme switch to prevent stale entries * from remaining in the plugin table. * * @since 2.4.0 * * @param bool $clear_update_cache Optional. Whether to clear the Plugin updates cache. * Parameter added in v2.5.0. */ public function flush_plugins_cache($clear_update_cache = true) { wp_clean_plugins_cache($clear_update_cache); }
protected function upgrade_plugin() { include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; // clear cache wp_clean_plugins_cache(); ob_start(); wp_update_plugins(); // Check for Plugin updates ob_end_clean(); $skin = new Automatic_Upgrader_Skin(); // The Automatic_Upgrader_Skin skin shouldn't output anything. $upgrader = new Plugin_Upgrader($skin); $upgrader->init(); // unhook this functions that output things before we send our response header. 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_themes'); ob_start(); $result = $upgrader->upgrade($this->plugin); $output = ob_get_contents(); ob_end_clean(); if (false === $result) { return new WP_Error('plugin_up_to_date', __('The Plugin is already up to date.', 'jetpack'), 400); } if (empty($result) && !empty($output)) { return new WP_Error('unknown_error', __('There was an error while trying to upgrade.', 'jetpack'), 500); } if (is_wp_error($result)) { return $result; } return true; }