本文整理汇总了PHP中WP_Upgrader::unpack_package方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Upgrader::unpack_package方法的具体用法?PHP WP_Upgrader::unpack_package怎么用?PHP WP_Upgrader::unpack_package使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_Upgrader
的用法示例。
在下文中一共展示了WP_Upgrader::unpack_package方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: background_installer
/**
* 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')));
}
}
}
}
示例2: upgrade_core
/**
* Upgrades WordPress locally
*/
public function upgrade_core($current)
{
ob_start();
if (file_exists(ABSPATH . '/wp-admin/includes/update.php')) {
include_once ABSPATH . '/wp-admin/includes/update.php';
}
@wp_version_check();
$current_update = false;
ob_end_flush();
ob_end_clean();
$core = $this->mmb_get_transient('update_core');
if (isset($core->updates) && !empty($core->updates)) {
$updates = $core->updates[0];
$updated = $core->updates[0];
if (!isset($updated->response) || $updated->response == 'latest') {
return array('upgraded' => ' updated');
}
if ($updated->response == "development" && $current['response'] == "upgrade") {
return array('error' => '<font color="#900">Unexpected error. Please upgrade manually.</font>');
} else {
if ($updated->response == $current['response'] || $updated->response == "upgrade" && $current['response'] == "development") {
if ($updated->locale != $current['locale']) {
foreach ($updates as $update) {
if ($update->locale == $current['locale']) {
$current_update = $update;
break;
}
}
if ($current_update == false) {
return array('error' => ' Localization mismatch. Try again.');
}
} else {
$current_update = $updated;
}
} else {
return array('error' => ' Transient mismatch. Try again.');
}
}
} else {
return array('error' => ' Refresh transient failed. Try again.');
}
if ($current_update != false) {
global $wp_filesystem, $wp_version;
if (version_compare($wp_version, '3.1.9', '>')) {
if (!class_exists('Core_Upgrader')) {
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
}
/** @handled class */
$core = new Core_Upgrader(mwp_container()->getUpdaterSkin());
$result = $core->upgrade($current_update);
$this->mmb_maintenance_mode(false);
if (is_wp_error($result)) {
return array('error' => $this->mmb_get_error($result));
} else {
return array('upgraded' => ' updated');
}
} else {
if (!class_exists('WP_Upgrader')) {
include_once ABSPATH . 'wp-admin/includes/update.php';
if (function_exists('wp_update_core')) {
$result = wp_update_core($current_update);
if (is_wp_error($result)) {
return array('error' => $this->mmb_get_error($result));
} else {
return array('upgraded' => ' updated');
}
}
}
if (class_exists('WP_Upgrader')) {
/** @handled class */
$upgrader_skin = new WP_Upgrader_Skin();
$upgrader_skin->done_header = true;
/** @handled class */
$upgrader = new WP_Upgrader($upgrader_skin);
// Is an update available?
if (!isset($current_update->response) || $current_update->response == 'latest') {
return array('upgraded' => ' updated');
}
$res = $upgrader->fs_connect(array(ABSPATH, WP_CONTENT_DIR));
if (is_wp_error($res)) {
return array('error' => $this->mmb_get_error($res));
}
$wp_dir = trailingslashit($wp_filesystem->abspath());
$core_package = false;
if (isset($current_update->package) && !empty($current_update->package)) {
$core_package = $current_update->package;
} elseif (isset($current_update->packages->full) && !empty($current_update->packages->full)) {
$core_package = $current_update->packages->full;
}
$download = $upgrader->download_package($core_package);
if (is_wp_error($download)) {
return array('error' => $this->mmb_get_error($download));
}
$working_dir = $upgrader->unpack_package($download);
if (is_wp_error($working_dir)) {
return array('error' => $this->mmb_get_error($working_dir));
}
//.........这里部分代码省略.........
示例3: install_marketpress_dashboard
/**
* Downloads the MarketPress Dashboard
*
* @since 0.1
* @uses WP_Upgrader, wp_safe_redirect, admin_url
* @return void
*/
public function install_marketpress_dashboard()
{
// Download
$package = 'http://marketpress.com/mpdash.zip';
$upgrader = new WP_Upgrader(new AU_Install_Skin());
// File System Connect
$res = $upgrader->fs_connect(array(WP_CONTENT_DIR, WP_PLUGIN_DIR));
// Download Package
$download = $upgrader->download_package($package);
// Don't delete local files
$delete_package = $download != $package;
// Unpack the package
$working_dir = $upgrader->unpack_package($download, $delete_package);
// Install the package
$result = $upgrader->install_package(array('source' => $working_dir, 'destination' => WP_PLUGIN_DIR, 'clear_destination' => FALSE, 'clear_working' => TRUE, 'hook_extra' => array()));
// Redirect
wp_safe_redirect(network_admin_url('plugins.php?message=marketpress_installed'));
}
示例4: array
function upgrade_core($current, $userid)
{
global $iwp_activities_log_post_type, $iwp_mmb_activities_log;
ob_start();
if (!function_exists('wp_version_check') || !function_exists('get_core_checksums')) {
include_once ABSPATH . '/wp-admin/includes/update.php';
}
@wp_version_check();
$current_update = false;
ob_end_flush();
ob_end_clean();
$core = $this->iwp_mmb_get_transient('update_core');
if (isset($core->updates) && !empty($core->updates)) {
$updates = $core->updates[0];
$updated = $core->updates[0];
if (!isset($updated->response) || $updated->response == 'latest') {
return array('upgraded' => 'updated');
}
if ($updated->response == "development" && $current->response == "upgrade") {
return array('error' => '<font color="#900">Unexpected error. Please upgrade manually.</font>', 'error_code' => 'unexpected_error_please_upgrade_manually');
} else {
if ($updated->response == $current->response || $updated->response == "upgrade" && $current->response == "development") {
if ($updated->locale != $current->locale) {
foreach ($updates as $update) {
if ($update->locale == $current->locale) {
$current_update = $update;
break;
}
}
if ($current_update == false) {
return array('error' => ' Localization mismatch. Try again.', 'error_code' => 'localization_mismatch');
}
} else {
$current_update = $updated;
}
} else {
return array('error' => ' Transient mismatch. Try again.', 'error_code' => 'transient_mismatch');
}
}
} else {
return array('error' => ' Refresh transient failed. Try again.', 'error_code' => 'refresh_transient_failed');
}
if ($current_update != false) {
global $iwp_mmb_wp_version, $wp_filesystem, $wp_version;
if (version_compare($wp_version, '3.1.9', '>')) {
if (!class_exists('Core_Upgrader')) {
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
}
$core = new Core_Upgrader();
$result = $core->upgrade($current_update);
$this->iwp_mmb_maintenance_mode(false);
if (is_wp_error($result)) {
return array('error' => $this->iwp_mmb_get_error($result), 'error_code' => 'maintenance_mode_upgrade_core');
} else {
$iwp_mmb_activities_log->iwp_mmb_save_iwp_activities('core', 'update', $iwp_activities_log_post_type, $current, $userid);
return array('upgraded' => 'updated');
}
} else {
if (!class_exists('WP_Upgrader')) {
include_once ABSPATH . 'wp-admin/includes/update.php';
if (function_exists('wp_update_core')) {
$result = wp_update_core($current_update);
if (is_wp_error($result)) {
return array('error' => $this->iwp_mmb_get_error($result), 'error_code' => 'wp_update_core_upgrade_core');
} else {
$iwp_mmb_activities_log->iwp_mmb_save_iwp_activities('core', 'update', $iwp_activities_log_post_type, $current, $userid);
return array('upgraded' => 'updated');
}
}
}
if (class_exists('WP_Upgrader')) {
$upgrader_skin = new WP_Upgrader_Skin();
$upgrader_skin->done_header = true;
$upgrader = new WP_Upgrader($upgrader_skin);
// Is an update available?
if (!isset($current_update->response) || $current_update->response == 'latest') {
return array('upgraded' => 'updated');
}
$res = $upgrader->fs_connect(array(ABSPATH, WP_CONTENT_DIR));
if (is_wp_error($res)) {
return array('error' => $this->iwp_mmb_get_error($res), 'error_code' => 'upgrade_core_wp_error_res');
}
$wp_dir = trailingslashit($wp_filesystem->abspath());
$core_package = false;
if (isset($current_update->package) && !empty($current_update->package)) {
$core_package = $current_update->package;
} elseif (isset($current_update->packages->full) && !empty($current_update->packages->full)) {
$core_package = $current_update->packages->full;
}
$download = $upgrader->download_package($core_package);
if (is_wp_error($download)) {
return array('error' => $this->iwp_mmb_get_error($download), 'error_code' => 'download_upgrade_core');
}
$working_dir = $upgrader->unpack_package($download);
if (is_wp_error($working_dir)) {
return array('error' => $this->iwp_mmb_get_error($working_dir), 'error_code' => 'working_dir_upgrade_core');
}
if (!$wp_filesystem->copy($working_dir . '/wordpress/wp-admin/includes/update-core.php', $wp_dir . 'wp-admin/includes/update-core.php', true)) {
$wp_filesystem->delete($working_dir, true);
return array('error' => 'Unable to move update files.', 'error_code' => 'unable_to_move_update_files');
//.........这里部分代码省略.........
示例5: foreach
function unpack_package($package, $delete_package = true)
{
global $wp_filesystem, $updraftplus;
$updraft_dir = $updraftplus->backups_dir_location();
// If not database, then it is a zip - unpack in the usual way
if (!preg_match('/db\\.gz(\\.crypt)?$/i', $package)) {
return parent::unpack_package($updraft_dir . '/' . $package, $delete_package);
}
$backup_dir = $wp_filesystem->find_folder($updraft_dir);
// Unpack a database. The general shape of the following is copied from class-wp-upgrader.php
@set_time_limit(1800);
$this->skin->feedback('unpack_package');
$upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade/';
@$wp_filesystem->mkdir($upgrade_folder, 0775);
//Clean up contents of upgrade directory beforehand.
$upgrade_files = $wp_filesystem->dirlist($upgrade_folder);
if (!empty($upgrade_files)) {
foreach ($upgrade_files as $file) {
$wp_filesystem->delete($upgrade_folder . $file['name'], true);
}
}
//We need a working directory
$working_dir = $upgrade_folder . basename($package, '.crypt');
# $working_dir_filesystem = WP_CONTENT_DIR.'/upgrade/'. basename($package, '.crypt');
// Clean up working directory
if ($wp_filesystem->is_dir($working_dir)) {
$wp_filesystem->delete($working_dir, true);
}
if (!$wp_filesystem->mkdir($working_dir, 0775)) {
return new WP_Error('mkdir_failed', __('Failed to create a temporary directory', 'updraftplus') . ' (' . $working_dir . ')');
}
// Unpack package to working directory
if ($updraftplus->is_db_encrypted($package)) {
$this->skin->feedback('decrypt_database');
$encryption = UpdraftPlus_Options::get_updraft_option('updraft_encryptionphrase');
if (!$encryption) {
return new WP_Error('no_encryption_key', __('Decryption failed. The database file is encrypted, but you have no encryption key entered.', 'updraftplus'));
}
// Encrypted - decrypt it
require_once UPDRAFTPLUS_DIR . '/includes/phpseclib/Crypt/Rijndael.php';
$rijndael = new Crypt_Rijndael();
// Get decryption key
$rijndael->setKey($encryption);
$ciphertext = $rijndael->decrypt($wp_filesystem->get_contents($backup_dir . $package));
if ($ciphertext) {
$this->skin->feedback('decrypted_database');
if (!$wp_filesystem->put_contents($working_dir . '/backup.db.gz', $ciphertext)) {
return new WP_Error('write_failed', __('Failed to write out the decrypted database to the filesystem', 'updraftplus'));
}
} else {
return new WP_Error('decryption_failed', __('Decryption failed. The most likely cause is that you used the wrong key.', 'updraftplus'));
}
} else {
if (!$wp_filesystem->copy($backup_dir . $package, $working_dir . '/backup.db.gz')) {
if ($wp_filesystem->errors->get_error_code()) {
foreach ($wp_filesystem->errors->get_error_messages() as $message) {
show_message($message);
}
}
return new WP_Error('copy_failed', $this->strings['copy_failed']);
}
}
// Once extracted, delete the package if required (non-recursive, is a file)
if ($delete_package) {
$wp_filesystem->delete($backup_dir . $package, false, true);
}
return $working_dir;
}