function install_package($args = array()) { parent::upgrade_strings(); // needed for the 'remove_old' string $args['clear_destination'] = true; $args['abort_if_destination_exists'] = false; return parent::install_package($args); }
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; }
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; } } }
/** * Initialize the upgrade strings. * * @since 2.8.0 */ public function upgrade_strings() { parent::upgrade_strings(); $this->strings['no_package'] = sprintf(__('Please (re)activate your license in %sMaster Slider > setting page%s. Valid license is required in order to update this plugin.'), '<a href="' . admin_url('admin.php?page=' . $this->slug . '-setting') . '">', '</a>'); $this->strings['downloading_package'] = __('Downloading package ...'); $this->strings['download_item_package'] = __('Downloading package ...'); }
/** * Initialize the upgrade strings. * * @since 1.0.0 */ public function upgrade_strings() { parent::upgrade_strings(); $this->strings['downloading_package'] = __('Downloading the Envato Market upgrade package…', 'envato-market'); }