本文整理汇总了PHP中Plugin_Upgrader类的典型用法代码示例。如果您正苦于以下问题:PHP Plugin_Upgrader类的具体用法?PHP Plugin_Upgrader怎么用?PHP Plugin_Upgrader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Plugin_Upgrader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _wprp_upgrade_plugin
/**
* Update a plugin
*
* @access private
* @param mixed $plugin
* @return array
*/
function _wprp_upgrade_plugin($plugin)
{
include_once ABSPATH . 'wp-admin/includes/admin.php';
if (!_wprp_supports_plugin_upgrade()) {
return array('status' => 'error', 'error' => 'WordPress version too old for plugin upgrades');
}
$skin = new WPRP_Plugin_Upgrader_Skin();
$upgrader = new Plugin_Upgrader($skin);
$is_active = is_plugin_active($plugin);
// Do the upgrade
ob_start();
$result = $upgrader->upgrade($plugin);
$data = ob_get_contents();
ob_clean();
if (!$result && !is_null($result) || $data) {
return array('status' => 'error', 'error' => 'file_permissions_error');
} elseif (is_wp_error($result)) {
return array('status' => 'error', 'error' => $result->get_error_code());
}
if ($skin->error) {
return array('status' => 'error', 'error' => $skin->error);
}
// If the plugin was activited, we have to re-activate it
// @todo Shouldn't this use activate_plugin?
if ($is_active) {
$current = get_option('active_plugins', array());
$current[] = plugin_basename(trim($plugin));
sort($current);
update_option('active_plugins', $current);
}
return array('status' => 'success');
}
示例2: hooks_plugin_install_or_update
/**
* @param Plugin_Upgrader $upgrader
* @param array $extra
*/
public function hooks_plugin_install_or_update($upgrader, $extra)
{
if (!isset($extra['type']) || 'plugin' !== $extra['type']) {
return;
}
if ('install' === $extra['action']) {
$path = $upgrader->plugin_info();
if (!$path) {
return;
}
$data = get_plugin_data($upgrader->skin->result['local_destination'] . '/' . $path, true, false);
aal_insert_log(array('action' => 'installed', 'object_type' => 'Plugin', 'object_name' => $data['Name'], 'object_subtype' => $data['Version']));
}
if ('update' === $extra['action']) {
if (isset($extra['bulk']) && true == $extra['bulk']) {
$slugs = $extra['plugins'];
} else {
if (!isset($upgrader->skin->plugin)) {
return;
}
$slugs = array($upgrader->skin->plugin);
}
foreach ($slugs as $slug) {
$data = get_plugin_data(WP_PLUGIN_DIR . '/' . $slug, true, false);
aal_insert_log(array('action' => 'updated', 'object_type' => 'Plugin', 'object_name' => $data['Name'], 'object_subtype' => $data['Version']));
}
}
}
示例3: install
protected function install()
{
foreach ($this->plugins as $index => $slug) {
$skin = new Jetpack_Automatic_Install_Skin();
$upgrader = new Plugin_Upgrader($skin);
$zip_url = self::generate_wordpress_org_plugin_download_link($slug);
$result = $upgrader->install($zip_url);
if (!$this->bulk && is_wp_error($result)) {
return $result;
}
$plugin = self::get_plugin_id_by_slug($slug);
$error_code = 'install_error';
if (!$plugin) {
$error = $this->log[$slug]['error'] = __('There was an error installing your plugin', 'jetpack');
}
if (!$this->bulk && !$result) {
$error_code = $upgrader->skin->get_main_error_code();
$message = $upgrader->skin->get_main_error_message();
$error = $this->log[$slug]['error'] = $message ? $message : __('An unknown error occurred during installation', 'jetpack');
}
$this->log[$plugin][] = $upgrader->skin->get_upgrade_messages();
}
if (!$this->bulk && isset($error)) {
if ('download_failed' === $error_code) {
// For backwards compatibility: versions prior to 3.9 would return no_package instead of download_failed.
$error_code = 'no_package';
}
return new WP_Error($error_code, $this->log[$slug]['error'], 400);
}
// replace the slug with the actual plugin id
$this->plugins[$index] = $plugin;
return true;
}
示例4: rtbiz_install_plugin
public function rtbiz_install_plugin($plugin_slug)
{
include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
$api = plugins_api('plugin_information', array('slug' => $plugin_slug, 'fields' => array('sections' => false)));
if (is_wp_error($api)) {
die(sprintf(__('ERROR: Error fetching plugin information: %s', RTBIZ_TEXT_DOMAIN), $api->get_error_message()));
}
if (!class_exists('Plugin_Upgrader')) {
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
}
if (!class_exists('Rtbiz_Plugin_Upgrader_Skin')) {
require_once RTBIZ_PATH . 'admin/abstract/class-rtbiz-plugin-upgrader-skin.php';
}
$upgrader = new Plugin_Upgrader(new Rtbiz_Plugin_Upgrader_Skin(array('nonce' => 'install-plugin_' . $plugin_slug, 'plugin' => $plugin_slug, 'api' => $api)));
$install_result = $upgrader->install($api->download_link);
if (!$install_result || is_wp_error($install_result)) {
// $install_result can be false if the file system isn't writeable.
$error_message = __('Please ensure the file system is writeable', RTBIZ_TEXT_DOMAIN);
if (is_wp_error($install_result)) {
$error_message = $install_result->get_error_message();
}
die(sprintf(__('ERROR: Failed to install plugin: %s', RTBIZ_TEXT_DOMAIN), $error_message));
}
$activate_result = activate_plugin($this->rtbiz_get_path_for_plugin($plugin_slug));
if (is_wp_error($activate_result)) {
die(sprintf(__('ERROR: Failed to activate plugin: %s', RTBIZ_TEXT_DOMAIN), $activate_result->get_error_message()));
}
}
示例5: install
protected function install()
{
foreach ($this->plugins as $index => $slug) {
$skin = new Automatic_Upgrader_Skin();
$upgrader = new Plugin_Upgrader($skin);
$result = $upgrader->install($this->download_links[$slug]);
if (!$this->bulk && is_wp_error($result)) {
return $result;
}
$plugin = $this::get_plugin_id_by_slug($slug);
if (!$plugin) {
$error = $this->log[$slug]['error'] = __('There was an error installing your plugin', 'jetpack');
}
if (!$this->bulk && !$result) {
$error = $this->log[$slug]['error'] = __('An unknown error occurred during installation', 'jetpack');
}
$this->log[$plugin][] = $upgrader->skin->get_upgrade_messages();
}
if (!$this->bulk && isset($error)) {
return new WP_Error('install_error', $this->log[$slug]['error'], 400);
}
// replace the slug with the actual plugin id
$this->plugins[$index] = $plugin;
return true;
}
示例6: update_plugin
/**
* Update plugin.
*
* @param string $plugin_slug
* @param string $tag
*
* @throws \Exception
*/
public function update_plugin($plugin_slug, $tag = 'master')
{
$plugin = null;
$is_plugin_active = false;
foreach ((array) Plugin::instance()->get_plugin_configs() as $config_entry) {
if ($config_entry->repo === $plugin_slug) {
$plugin = $config_entry;
break;
}
}
if (!$plugin) {
throw new \Exception(esc_html__('Plugin not found or not updatable with GitHub Updater: ', 'github-updater') . $plugin_slug);
}
if (is_plugin_active($plugin->slug)) {
$is_plugin_active = true;
}
$this->get_remote_repo_meta($plugin);
$updates_transient = get_site_transient('update_plugins');
$update = array('slug' => $plugin->repo, 'plugin' => $plugin->slug, 'new_version' => null, 'url' => $plugin->uri, 'package' => $this->repo_api->construct_download_link(false, $tag));
$updates_transient->response[$plugin->slug] = (object) $update;
set_site_transient('update_plugins', $updates_transient);
$upgrader = new \Plugin_Upgrader($this->upgrader_skin);
$upgrader->upgrade($plugin->slug);
if ($is_plugin_active) {
$activate = is_multisite() ? activate_plugin($plugin->slug, null, true) : activate_plugin($plugin->slug);
if (!$activate) {
$this->upgrader_skin->messages[] = esc_html__('Plugin reactivated successfully.', 'github-updater');
}
}
}
示例7: mpi_plugin_handle_download
function mpi_plugin_handle_download($plugin_name, $package, $mpi_action, $whform)
{
global $wp_version;
if (version_compare($wp_version, '3.0', '<')) {
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
$upgrader = new Plugin_Upgrader();
$upgrader->install($package);
if ($upgrader->plugin_info()) {
echo '<a href="' . wp_nonce_url('plugins.php?action=activate&plugin=' . $upgrader->plugin_info(), 'activate-plugin_' . $plugin_file) . '" title="' . esc_attr__('Activate this plugin') . '" target="_parent">' . __('Activate Plugin') . '</a>';
}
} else {
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
$upgrader = new Plugin_Upgrader(new Plugin_Installer_Skin(compact('type', 'title', 'nonce', 'url')));
$res = $upgrader->install($package);
//remove temp files
if ($whform == "upload_locFiles") {
@unlink($package);
}
if (!$upgrader->plugin_info()) {
echo $res;
} elseif ($mpi_action == "activate") {
$mpiplugins = get_option('active_plugins');
if ($mpiplugins) {
$puginsToActiv = array($upgrader->plugin_info());
foreach ($puginsToActiv as $mpiplugin) {
if (!in_array($mpiplugin, $mpiplugins)) {
array_push($mpiplugins, $mpiplugin);
update_option('active_plugins', $mpiplugins);
}
}
}
_e('<b class="mpi_act">Plugin activated successfully.</b><br/>', 'mpi');
}
}
}
示例8: bruteprotect_bulk_update_plugins
/**
* Updates the given list of plugins.
*
* Accepts an array of plugin paths such as 'bruteprotect/bruteprotect.php'
* Returns a detailed array showing the status of each plugin and a log of messages output during the process
*
* @param array $plugins
* @return array
*/
function bruteprotect_bulk_update_plugins($plugins)
{
$skin = new Automatic_Upgrader_Skin();
$upgrader = new Plugin_Upgrader($skin);
$results = $upgrader->bulk_upgrade($plugins);
$messages = $upgrader->skin->get_upgrade_messages();
$o['results'] = $results;
$o['messages'] = $messages;
return $o;
}
示例9: pl_ui_build_body
function pl_ui_build_body($obj)
{
if (isset($_GET['install_faves']) && 'true' == $_GET['install_faves'] || isset($_GET['install_multi']) && 'true' == $_GET['install_multi']) {
if (isset($_GET['install_multi'])) {
$mode = 'multi';
} else {
$mode = 'fav';
}
if ('multi' == $mode) {
$banner = 'Installing Selected Products';
$favs = explode(',', $_GET['slugs']);
foreach ($favs as $k => $fav) {
$favs[$fav] = $fav;
unset($favs[$k]);
}
} else {
$banner = 'Installing Favourite Products';
$favs = (array) get_user_meta(wp_get_current_user()->ID, '_card_fav', true);
}
printf('<h2>%s</2>', $banner);
// lets go!
if (!empty($favs)) {
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
$upgrader = new Plugin_Upgrader(new Plugin_Installer_Skin(compact('type', 'title', 'nonce', 'url')));
$data = PL_Platform()->functions->cache_get('connect_updates');
foreach ($data as $k => $prod) {
$data[$prod->slug] = $prod;
unset($data[$k]);
}
foreach ($favs as $slug => $k) {
$path = sprintf('%s/%s.php', $slug, $slug);
if (PL_Platform()->extend->is_plugin_installed($path)) {
printf('<p>%s is already installed, skipping.</p>', $data[$slug]->post_title);
} else {
printf('<p><i class="%s-spinner fa fa-cog fa-spin"></i><div style="display:none">', $slug);
$link = PL_Platform_Updater::get_download_link($data[$slug]->download_data);
$res = $upgrader->install($link);
printf('</div></p><script>jQuery(".%s-spinner").hide()</script>', $slug);
if ($upgrader->plugin_info()) {
$result = activate_plugin($path);
printf('<p><strong>%s</strong> has been installed successfully and is activated.</p>', $data[$slug]->post_title);
} else {
echo $res;
break;
}
}
}
echo '</p><h3>All Done!</h3></p><script>localStorage.clear();setTimeout(function(){window.location.href=window.PLAdmin.extendURL},3000)</script>';
}
} else {
$obj->build_body();
}
}
示例10: install_wp_super_cache
function install_wp_super_cache()
{
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
// code from wp-admin/update.php
$api = plugins_api('plugin_information', array('slug' => 'wp-super-cache', 'fields' => array('short_description' => false, 'sections' => false, 'requires' => false, 'rating' => false, 'ratings' => false, 'downloaded' => false, 'last_updated' => false, 'added' => false, 'tags' => false, 'compatibility' => false, 'homepage' => false, 'donate_link' => false)));
if (is_wp_error($api)) {
wp_die($api);
}
$upgrader = new Plugin_Upgrader(new Plugin_Installer_Skin(compact('title', 'url', 'nonce', 'plugin', 'api')));
$upgrader->install($api->download_link);
}
示例11: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$env = Validators::validateEnv($input->getOption('env'));
$root = $this->skeleton->getWebRoot();
$plugins = $this->skeleton->get(sprintf('wordpress.%s.plugins', $env));
require $root . '/wp-load.php';
require ABSPATH . 'wp-admin/includes/admin.php';
require ABSPATH . 'wp-admin/includes/plugin-install.php';
foreach ($plugins as $slug => $version) {
$plugin = plugins_api('plugin_information', array('slug' => $slug));
if (is_wp_error($plugin)) {
throw new \Exception('Could not get plugin information for ' . $slug);
}
if ($version) {
list($prefix) = explode($slug, $plugin->download_link);
$link = sprintf('%s%s.%s.zip', $prefix, $slug, $version);
$response = wp_remote_head($link);
if (!isset($response['response']['code']) || $response['response']['code'] != 200) {
throw new \Exception('Unable to verify ' . $link);
}
$plugin->download_link = $link;
$plugin->version = $version;
}
require ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
$status = install_plugin_install_status($plugin);
$upgrader = new \Plugin_Upgrader(new UpgraderSkin($output));
$current = current(get_plugins("/{$slug}"));
switch ($status['status']) {
case 'install':
$output->write(sprintf('Installing <info>%s</info> v<comment>%s</comment>', $plugin->name, $plugin->version));
$upgrader->install($plugin->download_link);
break;
case 'update_available':
if ($plugin->version == $current['Version']) {
$output->writeln(sprintf('<info>%s</info> v<comment>%s</comment> is already installed!', $plugin->name, $plugin->version));
} else {
$output->write(sprintf('Upgrading <info>%s</info> from <comment>%s</comment> to <comment>%s</comment>', $plugin->name, $current['Version'], $plugin->version));
$file = sprintf('%s/%s', $slug, key(get_plugins("/{$slug}")));
$upgrader->upgrade($file);
}
break;
case 'latest_installed':
$output->writeln(sprintf('<info>%s</info> v<comment>%s</comment> is already installed!', $plugin->name, $current['Version']));
break;
case 'newer_installed':
$output->writeln(sprintf('<info>%s</info> v<comment>%s</comment> is installed & newer than <comment>%s</comment>', $plugin->name, $current['Version'], $plugin->version));
break;
}
}
if ($plugins) {
$output->writeln(sprintf('<info>Activate plugins in the WordPress Admin</info>', $plugin->name));
}
}
示例12: siteorigin_plugin_activation_do_plugin_install
/**
* Install a plugin
*/
function siteorigin_plugin_activation_do_plugin_install()
{
/** All plugin information will be stored in an array for processing */
$plugin = array();
/** Checks for actions from hover links to process the installation */
if (isset($_GET[sanitize_key('plugin')]) && (isset($_GET[sanitize_key('siteorigin-pa-install')]) && 'install-plugin' == $_GET[sanitize_key('siteorigin-pa-install')]) && current_user_can('install_plugins')) {
check_admin_referer('siteorigin-pa-install');
$plugin['name'] = $_GET['plugin_name'];
// Plugin name
$plugin['slug'] = $_GET['plugin'];
// Plugin slug
if (!empty($_GET['plugin_source'])) {
$plugin['source'] = $_GET['plugin_source'];
} else {
$plugin['source'] = false;
}
/** Pass all necessary information via URL if WP_Filesystem is needed */
$url = wp_nonce_url(add_query_arg(array('page' => 'siteorigin_plugin_activation', 'plugin' => $plugin['slug'], 'plugin_name' => $plugin['name'], 'plugin_source' => $plugin['source'], 'siteorigin-pa-install' => 'install-plugin'), admin_url('themes.php')), 'siteorigin-pa-install');
$method = '';
// Leave blank so WP_Filesystem can populate it as necessary
$fields = array(sanitize_key('siteorigin-pa-install'));
// Extra fields to pass to WP_Filesystem
if (false === ($creds = request_filesystem_credentials($url, $method, false, false, $fields))) {
return true;
}
if (!WP_Filesystem($creds)) {
request_filesystem_credentials($url, $method, true, false, $fields);
// Setup WP_Filesystem
return true;
}
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
// Need for plugins_api
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
// Need for upgrade classes
/** Prep variables for Plugin_Installer_Skin class */
$title = sprintf(__('Installing %s', 'vantage'), $plugin['name']);
$url = add_query_arg(array('action' => 'install-plugin', 'plugin' => $plugin['slug']), 'update.php');
if (isset($_GET['from'])) {
$url .= add_query_arg('from', urlencode(stripslashes($_GET['from'])), $url);
}
$nonce = 'install-plugin_' . $plugin['slug'];
// Find the source of the plugin
$source = !empty($plugin['source']) ? $plugin['source'] : 'http://downloads.wordpress.org/plugin/' . urlencode($plugin['slug']) . '.zip';
/** Create a new instance of Plugin_Upgrader */
$upgrader = new Plugin_Upgrader($skin = new Plugin_Installer_Skin(compact('type', 'title', 'url', 'nonce', 'plugin', 'api')));
/** Perform the action and install the plugin from the $source urldecode() */
$upgrader->install($source);
/** Flush plugins cache so we can make sure that the installed plugins list is always up to date */
wp_cache_flush();
}
}
示例13: installAddon
/**
* @usage Single click add-on install
*/
function installAddon()
{
if (isset($_POST['updateurl']) && current_user_can(WPDM_ADMIN_CAP)) {
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
$upgrader = new \Plugin_Upgrader(new \Plugin_Installer_Skin(compact('title', 'url', 'nonce', 'plugin', 'api')));
$downloadlink = $_POST['updateurl'] . '&preact=login&user=' . get_option('__wpdm_suname') . '&pass=' . get_option('__wpdm_supass');
$upgrader->install($downloadlink);
$plugininfo = wpdm_plugin_data($_POST['plugin']);
if (file_exists(dirname(WPDM_BASE_DIR) . '/' . $plugininfo['plugin_index_file'])) {
activate_plugin($plugininfo['plugin_index_file']);
}
die("Installed Successfully");
} else {
die("Only site admin is authorized to install add-on");
}
}
示例14: is_uploading_allowed
public function is_uploading_allowed()
{
if (!isset($this->uploading_allowed)) {
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
require_once WP_Installer()->plugin_path() . '/includes/installer-upgrader-skins.php';
$upgrader_skins = new Installer_Upgrader_Skins();
//use our custom (mute) Skin
$upgrader = new Plugin_Upgrader($upgrader_skins);
ob_start();
$res = $upgrader->fs_connect(array(WP_CONTENT_DIR, WP_PLUGIN_DIR));
ob_end_clean();
if (!$res || is_wp_error($res)) {
$this->uploading_allowed = false;
} else {
$this->uploading_allowed = true;
}
}
return $this->uploading_allowed;
}
示例15: download_plugin
/**
* Install plugin from a URL.
*
* A mix of install-plugin and upload-plugin actions from wp-admin/update.php:93.
*/
public function download_plugin()
{
if (!current_user_can('upload_plugins')) {
wp_die(__('You do not have sufficient permissions to install plugins on this site.'));
}
check_admin_referer('plugin-download');
require_once ABSPATH . 'wp-admin/admin-header.php';
$download_url = esc_url_raw($_REQUEST['pluginurl']);
// Remove "-master" from GitHub URL-s
if (false !== strstr($download_url, '//github.com/')) {
add_filter('upgrader_source_selection', array($this, 'remove_github_master'), 9, 3);
}
$type = 'web';
$title = sprintf(__('Installing Plugin from URL: %s'), esc_html($download_url));
$url = 'update.php?action=install-plugin';
$nonce = 'plugin-download';
$upgrader = new Plugin_Upgrader(new Plugin_Installer_Skin(compact('type', 'title', 'url', 'nonce')));
$upgrader->install($download_url);
include ABSPATH . 'wp-admin/admin-footer.php';
}