本文整理汇总了PHP中WP_Upgrader::fs_connect方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Upgrader::fs_connect方法的具体用法?PHP WP_Upgrader::fs_connect怎么用?PHP WP_Upgrader::fs_connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_Upgrader
的用法示例。
在下文中一共展示了WP_Upgrader::fs_connect方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: download
/**
* A mimic of the `WP_Upgrader::download_package` method that adds a step to store the temp file with a shorter
* file name.
*
* @see WP_Upgrader::download_package()
*
* @param string $package The URI of the package. If this is the full path to an
* existing local file, it will be returned untouched.
*
* @return string|WP_Error The full path to the downloaded package file, or a WP_Error object.
*/
protected function download($package)
{
if (empty($this->filesystem)) {
// try to connect
$this->upgrader->fs_connect(array(WP_CONTENT_DIR, WP_PLUGIN_DIR));
global $wp_filesystem;
// still empty?
if (empty($wp_filesystem)) {
// bail
return false;
}
$this->filesystem = $wp_filesystem;
}
$this->upgrader->skin->feedback('downloading_package', $package);
$download_file = download_url($package);
if (is_wp_error($download_file)) {
return new WP_Error('download_failed', $this->upgrader->strings['download_failed'], $download_file->get_error_message());
}
$file = $this->get_short_filename($download_file);
$moved = $this->filesystem->move($download_file, $file);
if (empty($moved)) {
// we tried, we failed, we bail and let WP do its job
return false;
}
return $file;
}
示例2: array
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);
//.........这里部分代码省略.........
示例3: 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));
}
//.........这里部分代码省略.........
示例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: 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'));
}
示例6: array
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;
}