function tearDown() { remove_filter('extra_theme_headers', array($this, '_theme_data_extra_headers')); wp_clean_themes_cache(); unset($GLOBALS['wp_themes']); parent::tearDown(); }
/** * @param Theme_Upgrader $upgrader * @param array $extra */ public function hooks_theme_install_or_update($upgrader, $extra) { if (!isset($extra['type']) || 'theme' !== $extra['type']) { return; } if ('install' === $extra['action']) { $slug = $upgrader->theme_info(); if (!$slug) { return; } wp_clean_themes_cache(); $theme = wp_get_theme($slug); $name = $theme->name; $version = $theme->version; aal_insert_log(array('action' => 'installed', 'object_type' => 'Theme', 'object_name' => $name, 'object_subtype' => $version)); } if ('update' === $extra['action']) { if (isset($extra['bulk']) && true == $extra['bulk']) { $slugs = $extra['themes']; } else { $slugs = array($upgrader->skin->theme); } foreach ($slugs as $slug) { $theme = wp_get_theme($slug); $stylesheet = $theme['Stylesheet Dir'] . '/style.css'; $theme_data = get_file_data($stylesheet, array('Version' => 'Version')); $name = $theme['Name']; $version = $theme_data['Version']; aal_insert_log(array('action' => 'updated', 'object_type' => 'Theme', 'object_name' => $name, 'object_subtype' => $version)); } } }
public function rollback($theme, $args = array()) { $defaults = array('clear_update_cache' => true); $parsed_args = wp_parse_args($args, $defaults); $this->init(); $this->upgrade_strings(); if (0) { $this->skin->before(); $this->skin->set_result(false); $this->skin->error('up_to_date'); $this->skin->after(); return false; } $theme_slug = $this->skin->theme; $theme_version = $this->skin->options['version']; $download_endpoint = 'https://downloads.wordpress.org/theme/'; $url = $download_endpoint . $theme_slug . '.' . $theme_version . '.zip'; add_filter('upgrader_pre_install', array($this, 'current_before'), 10, 2); add_filter('upgrader_post_install', array($this, 'current_after'), 10, 2); add_filter('upgrader_clear_destination', array($this, 'delete_old_theme'), 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. $this->run(array('package' => $url, 'destination' => get_theme_root(), 'clear_destination' => true, 'clear_working' => true, 'hook_extra' => array('theme' => $theme, 'type' => 'theme', 'action' => 'update'))); remove_filter('upgrader_pre_install', array($this, 'current_before')); remove_filter('upgrader_post_install', array($this, 'current_after')); remove_filter('upgrader_clear_destination', array($this, 'delete_old_theme')); if (!$this->result || is_wp_error($this->result)) { return $this->result; } // Force refresh of theme update information wp_clean_themes_cache($parsed_args['clear_update_cache']); return true; }
function tearDown() { $GLOBALS['wp_theme_directories'] = $this->orig_theme_dir; remove_filter('theme_root', array(&$this, '_theme_root')); wp_clean_themes_cache(); unset($GLOBALS['wp_themes']); parent::tearDown(); }
function tearDown() { global $wp_theme_directories; $wp_theme_directories = $this->wp_theme_directories; remove_filter('extra_theme_headers', array($this, '_theme_data_extra_headers')); wp_clean_themes_cache(); unset($GLOBALS['wp_themes']); parent::tearDown(); }
public function tearDown() { $GLOBALS['wp_theme_directories'] = $this->orig_theme_dir; remove_filter('theme_root', array($this, 'filter_theme_root')); remove_filter('stylesheet_root', array($this, 'filter_theme_root')); remove_filter('template_root', array($this, 'filter_theme_root')); wp_clean_themes_cache(); unset($GLOBALS['wp_themes']); unset($GLOBALS['l10n']); unset($GLOBALS['l10n_unloaded']); parent::tearDown(); }
/** * Log plugin installations * * @action transition_post_status */ public static function callback_upgrader_process_complete($upgrader, $extra) { $logs = array(); $success = !is_wp_error($upgrader->skin->result); $error = null; if (!$success) { $errors = $upgrader->skin->result->errors; list($error) = reset($errors); } // This would have failed down the road anyway if (!isset($extra['type'])) { return false; } $type = $extra['type']; $action = $extra['action']; if (!in_array($type, array('plugin', 'theme'))) { return; } if ('install' === $action) { if ('plugin' === $type) { $path = $upgrader->plugin_info(); if (!$path) { return; } $data = get_plugin_data($upgrader->skin->result['local_destination'] . '/' . $path); $slug = $upgrader->result['destination_name']; $name = $data['Name']; $version = $data['Version']; } else { // theme $slug = $upgrader->theme_info(); if (!$slug) { return; } wp_clean_themes_cache(); $theme = wp_get_theme($slug); $name = $theme->name; $version = $theme->version; } $action = 'installed'; $message = _x('Installed %1$s: %2$s %3$s', 'Plugin/theme installation. 1: Type (plugin/theme), 2: Plugin/theme name, 3: Plugin/theme version', 'stream'); $logs[] = compact('slug', 'name', 'version', 'message', 'action'); } elseif ('update' === $action) { $action = 'updated'; $message = _x('Updated %1$s: %2$s %3$s', 'Plugin/theme update. 1: Type (plugin/theme), 2: Plugin/theme name, 3: Plugin/theme version', 'stream'); if ('plugin' === $type) { if (isset($extra['bulk']) && true == $extra['bulk']) { $slugs = $extra['plugins']; } else { $slugs = array($upgrader->skin->plugin); } $_plugins = self::get_plugins(); foreach ($slugs as $slug) { $plugin_data = get_plugin_data(WP_PLUGIN_DIR . '/' . $slug); $name = $plugin_data['Name']; $version = $plugin_data['Version']; $old_version = $_plugins[$slug]['Version']; $logs[] = compact('slug', 'name', 'old_version', 'version', 'message', 'action'); } } else { // theme if (isset($extra['bulk']) && true == $extra['bulk']) { $slugs = $extra['themes']; } else { $slugs = array($upgrader->skin->theme); } foreach ($slugs as $slug) { $theme = wp_get_theme($slug); $stylesheet = $theme['Stylesheet Dir'] . '/style.css'; $theme_data = get_file_data($stylesheet, array('Version' => 'Version')); $name = $theme['Name']; $old_version = $theme['Version']; $version = $theme_data['Version']; $logs[] = compact('slug', 'name', 'old_version', 'version', 'message', 'action'); } } } else { return false; } $context = $type . 's'; foreach ($logs as $log) { $name = isset($log['name']) ? $log['name'] : null; $version = isset($log['version']) ? $log['version'] : null; $slug = isset($log['slug']) ? $log['slug'] : null; $old_version = isset($log['old_version']) ? $log['old_version'] : null; $message = isset($log['message']) ? $log['message'] : null; $action = isset($log['action']) ? $log['action'] : null; self::log($message, compact('type', 'name', 'version', 'slug', 'success', 'error', 'old_version'), null, $context, $action); } }
/** * 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); }
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_themes($array) { require_once $this->data['dir'] . '/wp-admin/includes/class-wp-upgrader.php'; global $WPQI_Installer_Skin; $WPQI_Installer_Skin(); $first = true; foreach ($array as $name) { if (!$name) { continue; } $is_url = preg_match("/^(http|https):\\/\\//i", $name); $url = $is_url ? $name : "https://downloads.wordpress.org/theme/{$name}.zip"; $upgrader = new Theme_Upgrader(new WPQI_Installer_Skin()); $upgrader->install($url); if ($first) { switch_theme($name); $first = false; } } wp_clean_themes_cache(); }
/** * Get theme details **/ function get_selected_theme($theme_name, $newsletter_id = false) { global $wp_theme_directories; $added = 0; if (!in_array($this->template_custom_directory, $wp_theme_directories)) { $added = 1; register_theme_directory($this->template_custom_directory); } if (!in_array($this->template_directory, $wp_theme_directories)) { $added = 1; register_theme_directory($this->template_directory); } //cheating message fix if ($added) { wp_clean_themes_cache(); } $theme = wp_get_theme($theme_name); if ($theme->exists()) { $template = $this->get_theme_dir_url($theme, $theme_name); //load theme options if ($this->loaded_theme_options != $template['dir']) { $this->loaded_theme_options = $template['dir']; if (file_exists($template['dir'] . 'functions.php')) { include $template['dir'] . 'functions.php'; } elseif (file_exists($template['dir'] . 'index.php')) { include $template['dir'] . 'index.php'; } } $styles = $this->get_contents_elements($template['dir'], 0); $return = array('url' => $template['url'], 'dir' => $template['dir'], 'Stylesheet' => $theme['Stylesheet'], 'Template' => $theme['Template'], 'Status' => $theme['Status'], 'Style' => $styles['default_style'] . $styles['style']); return $return; } else { if ($theme_name != 'iletter') { if ($newsletter_id) { global $wpdb; $query = $wpdb->prepare("UPDATE {$this->tb_prefix}enewsletter_newsletters\r\r\n SET template = %s\r\r\n WHERE newsletter_id = %d", 'iletter', $newsletter_id); $wpdb->query($query); } return $this->get_selected_theme('iletter'); } } return false; }
function upgrade_bsf_product($request_product_id, $bundled_id) { global $bsf_product_validate_url, $bsf_support_url; if (!current_user_can('update_plugins')) { 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 = $product['purchase_key']; $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 $bp) { if ($bp->id === $request_product_id) { $type = $bp->type; $template = $bp->init; $name = $bp->name; } } } } if ($bsf_username === '' || $purchase_key === '' || $request_product_id === '') { wp_die('Not valid to update product'); } $path = base64_decode($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 = base64_encode($call); $parse = parse_url($path); $download = $parse['scheme'] . '://' . $parse['host']; $get_path = 'http://downloads.brainstormforce.com/'; $download_path = rtrim($get_path, '/') . '/download.php?hash=' . $hash; //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' => false, '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') { $Plugin_Upgrader = new Plugin_Upgrader(); $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); $Plugin_Upgrader->run(array('package' => $download_path, 'destination' => WP_PLUGIN_DIR, 'abort_if_destination_exists' => false, 'clear_destination' => false, 'clear_working' => true, 'hook_extra' => array('plugin' => $plugin_folder))); // 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; } if (is_dir($wp_filesystem->wp_content_dir() . 'upgrade_tmp/bsf_package')) { $wp_filesystem->delete($wp_filesystem->wp_content_dir() . 'upgrade_tmp/bsf_package', true); } // Force refresh of plugin update information delete_site_transient('update_plugins'); wp_cache_delete('plugins', 'plugins'); $response = array('status' => true, 'type' => 'plugin', 'name' => $name); return $response; } } } else { echo $result->message; } } }
/** * 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; } }
function current_after($return, $theme) { if (is_wp_error($return)) { return $return; } $theme = isset($theme['theme']) ? $theme['theme'] : ''; if ($theme != get_stylesheet()) { // If not current return $return; } // Ensure stylesheet name hasn't changed after the upgrade: if ($theme == get_stylesheet() && $theme != $this->result['destination_name']) { wp_clean_themes_cache(); $stylesheet = $this->result['destination_name']; switch_theme($stylesheet); } //Time to remove maintenance mode if (!$this->bulk) { $this->maintenance_mode(false); } return $return; }
function bulk_upgrade($themes) { $this->init(); $this->bulk = true; $this->upgrade_strings(); $current = get_site_transient('update_themes'); add_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2); add_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2); add_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4); $this->skin->header(); // Connect to the Filesystem first. $res = $this->fs_connect(array(WP_CONTENT_DIR)); if (!$res) { $this->skin->footer(); return false; } $this->skin->bulk_header(); // Only start maintenance mode if running in Multisite OR the theme is in use $maintenance = is_multisite(); // @TODO: This should only kick in for individual sites if at all possible. foreach ($themes as $theme) { $maintenance = $maintenance || $theme == get_stylesheet() || $theme == get_template(); } if ($maintenance) { $this->maintenance_mode(true); } $results = array(); $this->update_count = count($themes); $this->update_current = 0; foreach ($themes as $theme) { $this->update_current++; if (!isset($current->response[$theme])) { $this->skin->set_result(false); $this->skin->before(); $this->skin->error('up_to_date'); $this->skin->after(); $results[$theme] = false; continue; } $this->skin->theme_info = $this->theme_info($theme); // Get the URL to the zip file $r = $current->response[$theme]; $options = array('package' => $r['package'], 'destination' => WP_CONTENT_DIR . '/themes', 'clear_destination' => true, 'clear_working' => true, 'hook_extra' => array('theme' => $theme)); $result = $this->run($options); $results[$theme] = $this->result; // Prevent credentials auth screen from displaying multiple times if (false === $result) { break; } } //end foreach $plugins $this->maintenance_mode(false); $this->skin->bulk_footer(); $this->skin->footer(); // Cleanup our hooks, in case something else does a upgrade on this connection. remove_filter('upgrader_pre_install', array(&$this, 'current_before'), 10, 2); remove_filter('upgrader_post_install', array(&$this, 'current_after'), 10, 2); remove_filter('upgrader_clear_destination', array(&$this, 'delete_old_theme'), 10, 4); // Force refresh of theme update information wp_clean_themes_cache(); return $results; }
function bulk_upgrade($extensions, $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_themes'); add_filter('upgrader_pre_install', array($this, 'current_before'), 10, 2); add_filter('upgrader_post_install', array($this, 'current_after'), 10, 2); add_filter('upgrader_clear_destination', array($this, 'delete_old_theme'), 10, 4); $this->skin->header(); // Connect to the Filesystem first. $res = $this->fs_connect(array(WP_CONTENT_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 themes specified, OR // - a theme with an update available is currently in use. // @TODO: For multisite, maintenance mode should only kick in for individual sites if at all possible. $maintenance = is_multisite() && !empty($extensions); foreach ($extensions as $extension) { $maintenance = $maintenance || $extension == get_stylesheet() || $extension == get_template(); } if ($maintenance) { $this->maintenance_mode(true); } $results = array(); $this->update_count = count($extensions); $this->update_current = 0; foreach ($extensions as $extension) { $this->update_current++; $this->skin->theme_info = $this->theme_info($extension); if (!isset($current->extensions[$extension])) { $this->skin->set_result(true); $this->skin->before(); $this->skin->feedback('up_to_date'); $this->skin->after(); $results[$extension] = true; continue; } // Get the URL to the zip file $r = $current->extensions[$extension]; $result = $this->run(array('package' => $r['package'], 'destination' => get_theme_root($extension), 'clear_destination' => true, 'clear_working' => true, 'hook_extra' => array('theme' => $extension))); $results[$extension] = $this->result; // Prevent credentials auth screen from displaying multiple times if (false === $result) { break; } } //end foreach $plugins $this->maintenance_mode(false); do_action('upgrader_process_complete', $this, array('action' => 'update', 'type' => 'theme', 'bulk' => true, 'themes' => $extensions)); $this->skin->bulk_footer(); $this->skin->footer(); // Cleanup our hooks, in case something else does a upgrade on this connection. remove_filter('upgrader_pre_install', array($this, 'current_before')); remove_filter('upgrader_post_install', array($this, 'current_after')); remove_filter('upgrader_clear_destination', array($this, 'delete_old_theme')); // Refresh the Theme Update information wp_clean_themes_cache($parsed_args['clear_update_cache']); return $results; }
/** * Callback function for the update plugin page above. This page uses the filesystem api to install a plugin * * @access public * @since 1.0.0 * @see get_option() * @see wp_remote_post() * @see is_wp_error() * @see wp_remote_retrieve_response_code() * @see wp_remote_retrieve_body() * @see current_user_can() * @see wp_verify_nonce() * @see wp_nonce_url() * @see WP_Filesystem * @see WP_Filesystem::wp_plugins_dir() * @see request_filesystem_credentials() * @see trailingslashit() * @see unzip_file() * @see wp_cache_set() * @see activate_plugin() * @return void */ public function mp_core_install_plugin() { //If this product is licensed if (!empty($this->_args['plugin_licensed']) && $this->_args['plugin_licensed']) { //get validity of license saved $license_valid = get_option($this->plugin_name_slug . '_license_status_valid'); //if license saved is incorrrect if (!$license_valid) { //output incorrect license message echo "The license entered is not valid"; //output form to try license //stop the rest of this page from showing return true; } $api_params = array('api' => 'true', 'slug' => $this->plugin_name_slug, 'author' => NULL, 'license_key' => $this->_args['plugin_license'], 'old_license_key' => get_option($this->plugin_name_slug . '_license_key'), 'site_activating' => get_bloginfo('wpurl')); $request = wp_remote_post($this->_args['plugin_api_url'] . '/repo/' . $this->plugin_name_slug, array('method' => 'POST', 'timeout' => 15, 'sslverify' => false, 'body' => $api_params)); // make sure the response was successful if (is_wp_error($request) || 200 != wp_remote_retrieve_response_code($request)) { $failed = true; } //JSON Decode response and store the plugin download link in $this->_args['plugin_download_link'] $request = json_decode(wp_remote_retrieve_body($request)); //Set the plugin download link to be the package URL from the response $this->_args['plugin_download_link'] = $request->package; } //Make sure this user has the cpability to install plugins: if (!current_user_can('install_plugins')) { die('<p>' . __('You don\'t have permission to do this. Contact the system administrator for assistance.', 'mp_core') . '</p>'); } //Make sure the action is set to install-plugin if ($_GET['action'] != 'install-plugin') { die('<p>' . __('Oops! Something went wrong', 'mp_core') . '</p>'); } //Get the nonce previously set $nonce = $_REQUEST['_wpnonce']; //Check that nonce to ensure the user wants to do this if (!wp_verify_nonce($nonce, 'install-plugin')) { die('<p>' . __('Security Check', 'mp_core') . '</p>'); } //Set the method for the wp filesystem $method = ''; // Normally you leave this an empty string and it figures it out by itself, but you can override the filesystem method here //Get credentials for wp filesystem $url = wp_nonce_url('options-general.php?page=mp_core_install_plugin_page_' . $this->plugin_name_slug . '&action=install-plugin&plugin=' . $this->plugin_name_slug, 'install-plugin_' . $this->plugin_name_slug); if (false === ($creds = request_filesystem_credentials($url, $method, false, false))) { // if we get here, then we don't have credentials yet, // but have just produced a form for the user to fill in, // so stop processing for now return true; // stop the normal page form from displaying } //Now we have some credentials, try to get the wp_filesystem running if (!WP_Filesystem($creds)) { // our credentials were no good, ask the user for them again request_filesystem_credentials($url, $method, true, false); return true; } //By this point, the $wp_filesystem global should be working, so let's use it get our plugin global $wp_filesystem; //If we are installing a theme if ($this->_args['plugin_is_theme']) { //Get the plugins directory and name the temp plugin file $upload_dir = $wp_filesystem->wp_themes_dir(); } else { //Get the plugins directory and name the temp plugin file $upload_dir = $wp_filesystem->wp_plugins_dir(); } $filename = trailingslashit($upload_dir) . 'temp.zip'; //if 'allow_url_fopen' is available, do it the right way using the WP Filesystem api if (ini_get('allow_url_fopen')) { //Download the plugin file defined in the passed in array $saved_file = $wp_filesystem->get_contents(esc_url_raw(add_query_arg(array('site_activating' => get_bloginfo('wpurl')), $this->_args['plugin_download_link']))); //Save the contents into a temp.zip file (string stored in $filename) $wp_filesystem->put_contents($filename, $saved_file, FS_CHMOD_FILE); } else { echo __('Oops! Your Web Host is badly configured! Let your web host know they need to have "allow_url_fopen" turned on.', 'mp_core'); // Initializing curl $ch = curl_init(); //Return Transfer curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //File to fetch curl_setopt($ch, CURLOPT_URL, $this->_args['plugin_download_link']); //Open/Create new file $file = fopen($upload_dir . "temp.zip", 'w'); //Put contents of plugin_download_link in this new file curl_setopt($ch, CURLOPT_FILE, $file); #output curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects //Set User Agent curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5'); //set user agent // Getting results $result = curl_exec($ch); // Getting jSON result string curl_close($ch); fclose($file); //If we are unable to find the file, let the user know. This will also fail if a license is incorrect - but it should be caught further up the page if (!$result) { die; } } //Unzip the temp zip file unzip_file($filename, trailingslashit($upload_dir) . '/'); //Delete the temp zipped file $wp_filesystem->rmdir($filename); //If we are installing a theme if ($this->_args['plugin_is_theme']) { //Set themes cache to NULL so wp_get_themes will get the new theme we just installed wp_clean_themes_cache(true); $installed_themes = wp_get_themes(); //Loop through each installed theme foreach ($installed_themes as $theme_slug => $theme) { echo $theme['headers:WP_Theme:private']['Name']; echo $theme['plugin_name']; //If this theme is the theme we're hoping to install if ($theme['headers:WP_Theme:private']['Name'] == $theme['plugin_name']) { //Switch to the theme we just installed switch_theme($theme_slug); //Stop looping break; } } //Display a successfully installed message echo '<p>' . __('Successfully Installed ', 'mp_core') . $this->_args['plugin_name'] . '</p>'; } else { //Set plugin cache to NULL so activate_plugin->validate_plugin->get_plugins will check again for new plugins wp_cache_set('plugins', NULL, 'plugins'); //Activate plugin $result = activate_plugin(trailingslashit($upload_dir) . $this->plugin_name_slug . '/' . $this->_args['plugin_filename']); //If there was a problem installing the plugin if (is_wp_error($result)) { //Display an error message echo '<p>' . __('Error Installing ', 'mp_core') . $this->_args['plugin_name'] . '</p>'; echo '<p>' . $result->get_error_message() . '</p>'; } else { //Display a successfully installed message echo '<p>' . __('Successfully Installed ', 'mp_core') . $this->_args['plugin_name'] . '</p>'; } } if (!empty($this->_args['plugin_success_link'])) { //Javascript for redirection echo '<script type="text/javascript">'; echo "window.location = '" . $this->_args['plugin_success_link'] . "';"; echo '</script>'; echo '</div>'; } }
/** * Theme install of update * * @since 0.1.0 * * @param Theme_Upgrader $upgrader * @param array $extra */ public function theme_install_or_update($upgrader, $extra) { // Bail if not a theme if (!isset($extra['type']) || 'theme' !== $extra['type']) { return; } // Install if ('install' === $extra['action']) { // Bail if no theme found $slug = $upgrader->theme_info(); if (empty($slug)) { return; } wp_clean_themes_cache(); $theme = wp_get_theme($slug); $name = $theme->name; $version = $theme->version; // Insert activity wp_insert_user_activity(array('object_type' => $this->object_type, 'object_subtype' => $version, 'object_name' => $name, 'action' => 'install')); // Update } elseif ('update' === $extra['action']) { // Get theme slugs if (isset($extra['bulk']) && true == $extra['bulk']) { $slugs = $extra['themes']; } else { $slugs = array($upgrader->skin->theme); } // Activity for each theme foreach ($slugs as $slug) { $theme = wp_get_theme($slug); $stylesheet = $theme['Stylesheet Dir'] . '/style.css'; $theme_data = get_file_data($stylesheet, array('Version' => 'Version')); $name = $theme['Name']; $version = $theme_data['Version']; // Insert activity wp_insert_user_activity(array('object_type' => $this->object_type, 'object_subtype' => $version, 'object_name' => $name, 'action' => 'update')); } } }
function bizzthemes_framework_update_head() { global $wp_filesystem, $themeid; if (isset($_REQUEST['page']) && $_REQUEST['page'] == 'bizz-update') { // Setup Filesystem $method = get_filesystem_method(); // Get ftp credentials or use WP filesystem if (isset($_POST['bizz_ftp_cred'])) { $cred = unserialize(base64_decode($_POST['bizz_ftp_cred'])); $filesystem = WP_Filesystem($cred); } else { $filesystem = WP_Filesystem(); } // Filesystem preventing downloads if ($filesystem == false && $_POST['upgrade'] != 'Proceed') { function bizzthemes_framework_update_filesystem_warning() { $method = get_filesystem_method(); echo "<div id='filesystem-warning' class='updated fade'><p>Failed: Filesystem preventing downloads. (" . $method . ")</p></div>"; } add_action('admin_notices', 'bizzthemes_framework_update_filesystem_warning'); return; } // Upgrade if (isset($_REQUEST['bizz_update_save']) && $_REQUEST['bizz_update_save'] == 'save') { if (isset($_REQUEST['bizz_update_theme'])) { delete_transient('remote_f_version_' . $themeid); delete_transient('remote_t_version_' . $themeid); $temp_file_addr = download_url('http://www.bizzthemes.com/files/' . strtolower($themeid) . '.zip'); $to = $wp_filesystem->wp_content_dir() . "/themes/"; } elseif (isset($_REQUEST['bizz_update_frame'])) { delete_transient('remote_f_version_' . $themeid); $temp_file_addr = download_url('http://www.bizzthemes.com/framework/lib_frame.zip'); $to = $wp_filesystem->wp_content_dir() . "/themes/" . get_option('template') . "/lib_frame/"; } // Error with upgade if (is_wp_error($temp_file_addr)) { $error = $temp_file_addr->get_error_code(); if ($error == 'http_no_url') { //The source file was not found or is invalid function bizzthemes_framework_update_missing_source_warning() { echo "<div id='source-warning' class='updated fade'><p>Failed: Invalid URL Provided</p></div>"; } add_action('admin_notices', 'bizzthemes_framework_update_missing_source_warning'); } else { function bizzthemes_framework_update_other_upload_warning() { echo "<div id='source-warning' class='updated fade'><p>Failed: Upload - {$error}</p></div>"; } add_action('admin_notices', 'bizzthemes_framework_update_other_upload_warning'); } return; } //Unzipp it $dounzip = unzip_file($temp_file_addr, $to); unlink($temp_file_addr); // Delete Temp File if (is_wp_error($dounzip)) { //DEBUG $error = $dounzip->get_error_code(); $data = $dounzip->get_error_data($error); // echo $error. ' - '; // print_r($data); if ($error == 'incompatible_archive') { //The source file was not found or is invalid function bizzthemes_framework_update_no_archive_warning() { echo "<div id='bizz-no-archive-warning' class='updated fade'><p>Failed: Incompatible archive</p></div>"; } add_action('admin_notices', 'bizzthemes_framework_update_no_archive_warning'); } if ($error == 'empty_archive') { function bizzthemes_framework_update_empty_archive_warning() { echo "<div id='bizz-empty-archive-warning' class='updated fade'><p>Failed: Empty Archive</p></div>"; } add_action('admin_notices', 'bizzthemes_framework_update_empty_archive_warning'); } if ($error == 'mkdir_failed') { function bizzthemes_framework_update_mkdir_warning() { echo "<div id='bizz-mkdir-warning' class='updated fade'><p>Failed: mkdir Failure</p></div>"; } add_action('admin_notices', 'bizzthemes_framework_update_mkdir_warning'); } if ($error == 'copy_failed') { function bizzthemes_framework_update_copy_fail_warning() { echo "<div id='bizz-copy-fail-warning' class='updated fade'><p>Failed: Copy Failed</p></div>"; } add_action('admin_notices', 'bizzthemes_framework_update_copy_fail_warning'); } return; } // Force refresh of theme update information wp_clean_themes_cache(); function bizzthemes_framework_updated_success() { echo "<div id='framework-upgraded' class='updated fade'><p>New files successfully downloaded, extracted and updated.</p></div>"; } add_action('admin_notices', 'bizzthemes_framework_updated_success'); } } //End user input save part of the update }
/** * 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'); }
/** * Install a theme package. * * @param string $package The full local path or URI of the package. * @param bool $is_theme define - is framework or child theme installed * @param array $args * * @return bool|WP_Error True if the install was successful, false or a {@see WP_Error} object otherwise. */ public function install($package, $is_theme = false, $args = array()) { $this->is_theme = $is_theme; $defaults = array('clear_update_cache' => true); $parsed_args = wp_parse_args($args, $defaults); $this->init(); $this->install_strings(); add_filter('upgrader_source_selection', array($this, 'check_package')); add_filter('upgrader_post_install', array($this, 'check_parent_theme_filter'), 10, 3); $this->run(array('package' => $package, 'destination' => get_theme_root(), 'clear_destination' => false, 'clear_working' => true, 'hook_extra' => array('type' => 'theme', 'action' => 'install'))); remove_filter('upgrader_source_selection', array($this, 'check_package')); remove_filter('upgrader_post_install', array($this, 'check_parent_theme_filter')); if (!$this->result || is_wp_error($this->result)) { return $this->result; } // Refresh the Theme Update information wp_clean_themes_cache($parsed_args['clear_update_cache']); return true; }
/** * 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); }
/** * 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'); }
function gitium_upgrader_post_install($res, $hook_extra, $result) { _gitium_make_ssh_git_file_exe(); $type = isset($hook_extra['theme']) ? 'theme' : 'plugin'; $action = isset($hook_extra['action']) ? $hook_extra['action'] : 'updated'; $action = 'install' === $action ? 'installed' : $action; $git_dir = $result['destination']; $version = ''; if (ABSPATH == substr($git_dir, 0, strlen(ABSPATH))) { $git_dir = substr($git_dir, strlen(ABSPATH)); } switch ($type) { case 'theme': wp_clean_themes_cache(); $theme_data = wp_get_theme($result['destination_name']); $name = $theme_data->get('Name'); $version = $theme_data->get('Version'); break; case 'plugin': foreach ($result['source_files'] as $file) { if ('.php' != substr($file, -4)) { continue; } // every .php file is a possible plugin so we check if it's a plugin $filepath = trailingslashit($result['destination']) . $file; $plugin_data = get_plugin_data($filepath); if ($plugin_data['Name']) { $name = $plugin_data['Name']; $version = $plugin_data['Version']; // We get info from the first plugin in the package break; } } break; } if (empty($name)) { $name = $result['destination_name']; } $commit_message = _gitium_format_message($name, $version, "{$action} {$type}"); $commit = _gitium_commit_changes($commit_message, $git_dir, false); gitium_merge_and_push($commit); return $res; }
/** * @depends testUpgradeOneTheme */ public function testUpgradeAllThemes() { global $argv; $argv = array(); $argv[] = 'composer'; $argv[] = 'wp-update'; $argv[] = 'themes'; Container::destroy(); $container = Container::getInstance(); $b = $container->getBootstrap(); $b->update(); $container->getUtils()->includeWordPress(); wp_clean_themes_cache(true); $themes = wp_get_themes(); foreach ($this->tThemes as $key => $versions) { $this->assertTrue(isset($themes[$key])); $this->assertEquals($versions[1], $themes[$key]['Version']); } }