Пример #1
1
/**
 * 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
0
 /**
  * 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');
         }
     }
 }
 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));
     }
 }
 /**
  * @usage Single click add-on update
  */
 function updateAddon()
 {
     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='******'__wpdm_suname') . '&pass='******'__wpdm_supass') . '&__wpdmnocache=' . uniqid();
         $upgrader->upgrade($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("Updated Successfully");
     } else {
         die("Only site admin is authorized to install add-on");
     }
 }
Пример #5
0
 public function svn_update_plugin()
 {
     global $title, $parent_file, $submenu_file;
     if (!current_user_can('update_plugins')) {
         wp_die(__('You do not have sufficient permissions to update plugins for this site.'));
     }
     check_admin_referer('svn_update_plugin');
     $this->plugin = $plugin = isset($_REQUEST['plugin']) ? $_REQUEST['plugin'] : '';
     if (empty($plugin)) {
         wp_die('Plugin name is missing.');
     }
     add_filter('site_transient_update_plugins', array($this, 'rewrite_update_plugins_url'));
     $title = __('Update Plugin');
     $parent_file = 'plugins.php';
     $submenu_file = 'plugins.php';
     wp_enqueue_script('updates');
     require_once ABSPATH . 'wp-admin/admin-header.php';
     $nonce = 'upgrade-plugin_' . $plugin;
     $url = 'update.php?action=upgrade-plugin&plugin=' . urlencode($plugin);
     $upgrader = new Plugin_Upgrader(new Plugin_Upgrader_Skin(compact('title', 'nonce', 'url', 'plugin')));
     $upgrader->upgrade($plugin);
     include ABSPATH . 'wp-admin/admin-footer.php';
 }
 public static function autoUpdate()
 {
     try {
         if (getenv('noabort') != '1' && stristr($_SERVER['SERVER_SOFTWARE'], 'litespeed') !== false) {
             $lastEmail = self::get('lastLiteSpdEmail', false);
             if (!$lastEmail || time() - (int) $lastEmail > 86400 * 30) {
                 self::set('lastLiteSpdEmail', time());
                 wordfence::alert("Wordfence Upgrade not run. Please modify your .htaccess", "To preserve the integrity of your website we are not running Wordfence auto-update.\n" . "You are running the LiteSpeed web server which has been known to cause a problem with Wordfence auto-update.\n" . "Please go to your website now and make a minor change to your .htaccess to fix this.\n" . "You can find out how to make this change at:\n" . "https://support.wordfence.com/solution/articles/1000129050-running-wordfence-under-litespeed-web-server-and-preventing-process-killing-or\n" . "\nAlternatively you can disable auto-update on your website to stop receiving this message and upgrade Wordfence manually.\n", '127.0.0.1');
             }
             return;
         }
         require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
         require_once ABSPATH . 'wp-admin/includes/misc.php';
         /* We were creating show_message here so that WP did not write to STDOUT. This had the strange effect of throwing an error about redeclaring show_message function, but only when a crawler hit the site and triggered the cron job. Not a human. So we're now just require'ing misc.php which does generate output, but that's OK because it is a loopback cron request.  
         			if(! function_exists('show_message')){ 
         				function show_message($msg = 'null'){}
         			}
         			*/
         define('FS_METHOD', 'direct');
         require_once ABSPATH . 'wp-includes/update.php';
         require_once ABSPATH . 'wp-admin/includes/file.php';
         wp_update_plugins();
         ob_start();
         $upgrader = new Plugin_Upgrader();
         $upret = $upgrader->upgrade('wordfence/wordfence.php');
         if ($upret) {
             $cont = file_get_contents(WP_PLUGIN_DIR . '/wordfence/wordfence.php');
             if (wfConfig::get('alertOn_update') == '1' && preg_match('/Version: (\\d+\\.\\d+\\.\\d+)/', $cont, $matches)) {
                 wordfence::alert("Wordfence Upgraded to version " . $matches[1], "Your Wordfence installation has been upgraded to version " . $matches[1], '127.0.0.1');
             }
         }
         $output = @ob_get_contents();
         @ob_end_clean();
     } catch (Exception $e) {
     }
 }
Пример #7
0
 /**
  * Auto-Update Plugin in multisite
  *
  * Manage the non standard upgrade-plugin-multisite action
  *
  * @return void
  *
  * @since    1.0
  * @see      upgrade-plugin action
  * @author   Andrea Grillo <*****@*****.**>
  */
 public function upgrade_plugin_multisite()
 {
     $plugin = isset($_REQUEST['plugin']) ? trim($_REQUEST['plugin']) : '';
     $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
     if ('upgrade-plugin-multisite' != $action) {
         wp_die(__('You can\'t update the plugins for this site.', 'yith-plugin-fw'));
     }
     if (!current_user_can('update_plugins')) {
         wp_die(__('You do not have sufficient permissions to update the plugins for this site.', 'yith-plugin-fw'));
     }
     $this->check_update(get_site_transient('update_plugins'), true);
     check_admin_referer('upgrade-plugin-multisite_' . $plugin);
     $title = __('Update Plugin', 'yith-plugin-fw');
     $parent_file = 'plugins.php';
     $submenu_file = 'plugins.php';
     wp_enqueue_script('updates');
     require_once ABSPATH . 'wp-admin/admin-header.php';
     $nonce = 'upgrade-plugin-multisite_' . $plugin;
     $url = 'update.php?action=upgrade-plugin-multisite&plugin=' . urlencode($plugin);
     $upgrader = new Plugin_Upgrader(new Plugin_Upgrader_Skin(compact('title', 'nonce', 'url', 'plugin')));
     $upgrader->upgrade($plugin);
     include ABSPATH . 'wp-admin/admin-footer.php';
 }
Пример #8
0
 public function download_plugin()
 {
     require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     require_once $this->plugin_path() . '/includes/installer-upgrader-skins.php';
     if (isset($_POST['data'])) {
         $data = json_decode(base64_decode($_POST['data']), true);
     }
     $ret = false;
     $plugin_id = false;
     if ($data['nonce'] == wp_create_nonce('install_plugin_' . $data['url'])) {
         $upgrader_skins = new Installer_Upgrader_Skins();
         //use our custom (mute) Skin
         $upgrader = new Plugin_Upgrader($upgrader_skins);
         remove_action('upgrader_process_complete', array('Language_Pack_Upgrader', 'async_upgrade'), 20);
         $plugins = get_plugins();
         //upgrade or install?
         foreach ($plugins as $id => $plugin) {
             if (dirname($id) == $data['basename']) {
                 $plugin_id = $id;
                 break;
             }
         }
         if ($plugin_id) {
             //upgrade
             $response['upgrade'] = 1;
             $plugin_is_active = is_plugin_active($plugin_id);
             $ret = $upgrader->upgrade($plugin_id);
             if ($plugin_is_active) {
                 activate_plugin($plugin_id);
             }
         } else {
             //install
             $response['install'] = 1;
             $ret = $upgrader->install($data['url']);
         }
         $plugins = get_plugins();
         //read again
         if ($ret && !empty($_POST['activate'])) {
             foreach ($plugins as $id => $plugin) {
                 if (dirname($id) == $data['basename']) {
                     $plugin_version = $plugin['Version'];
                     $plugin_id = $id;
                     break;
                 }
             }
         }
     }
     $response['version'] = isset($plugin_version) ? $plugin_version : 0;
     $response['plugin_id'] = $plugin_id;
     $response['nonce'] = wp_create_nonce('activate_' . $plugin_id);
     $response['success'] = $ret;
     echo json_encode($response);
     exit;
 }
Пример #9
0
function wpdm_activate_shop()
{
    if (current_user_can('manage_options')) {
        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 = 'http://www.wpdownloadmanager.com/?wpdmdl=15671';
        ob_start();
        echo "<div id='acto'>";
        if (file_exists(dirname(dirname(__FILE__)) . '/wpdm-premium-packages/')) {
            $upgrader->upgrade($downloadlink);
        } else {
            $upgrader->install($downloadlink);
        }
        echo '</div><style>#acto .wrap { display: none; }</style>';
        @ob_clean();
        activate_plugin('wpdm-premium-packages/wpdm-premium-packages.php');
        echo "Congratulation! Your Digital Store is Activated. <a href='' class='btn btn-warning'>Refresh The Page!</a>";
        die;
    } else {
        die("Only site admin is authorized to install add-on");
    }
}
Пример #10
0
function wptouch_free_upgrade_plugin()
{
    global $wptouch_pro;
    $wptouch_pro->bnc_api = false;
    $settings = wptouch_get_settings('bncid');
    $wptouch_pro->setup_bncapi($settings->bncid, $settings->wptouch_license_key, true);
    $bnc_api = $wptouch_pro->get_bnc_api();
    $plugin_name = 'wptouch/wptouch.php';
    // Check for WordPress 3.0 function
    if (function_exists('is_super_admin')) {
        $option = get_site_transient('update_plugins');
    } else {
        $option = function_exists('get_transient') ? get_transient('update_plugins') : get_option('update_plugins');
    }
    $version_available = false;
    $latest_info = $bnc_api->get_product_version();
    if ($latest_info && $latest_info['version'] != WPTOUCH_VERSION) {
        WPTOUCH_DEBUG(WPTOUCH_INFO, 'A new product update is available [' . $latest_info['version'] . ']');
        if (isset($latest_info['upgrade_url']) && wptouch_has_license()) {
            if (!isset($option->response[$plugin_name])) {
                $option->response[$plugin_name] = new stdClass();
            }
            // Update upgrade options
            $option->response[$plugin_name]->url = 'http://www.wptouch.com/';
            $option->response[$plugin_name]->package = $latest_info['upgrade_url'];
            $option->response[$plugin_name]->new_version = $latest_info['version'];
            $option->response[$plugin_name]->id = '0';
            $option->response[$plugin_name]->slug = WPTOUCH_ROOT_NAME;
        } else {
            if (is_object($option) && isset($option->response)) {
                unset($option->response[$plugin_name]);
            }
        }
        $wptouch_pro->latest_version_info = $latest_info;
        $upgrade_available = $latest_info['version'];
    } else {
        if (is_object($option) && isset($option->response)) {
            unset($option->response[$plugin_name]);
        }
    }
    if (isset($option->response[$plugin_name])) {
        // WordPress 3.0 changed some stuff, so we check for a WP 3.0 function
        if (function_exists('is_super_admin')) {
            set_site_transient('update_plugins', $option);
        } else {
            if (function_exists('set_transient')) {
                set_transient('update_plugins', $option);
            }
        }
        // Do Upgrade
        include_once ABSPATH . 'wp-admin/includes/admin.php';
        include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
        $upgrader = new Plugin_Upgrader(new Automatic_Upgrader_Skin());
        $upgrader->upgrade('wptouch/wptouch.php');
        if (is_array($upgrader->skin->result)) {
            deactivate_plugins('wptouch/wptouch.php');
            $new_plugin_identifier = 'wptouch-pro/wptouch-pro.php';
            $active_plugins = get_option('active_plugins', array());
            if (!in_array($new_plugin_identifier, $active_plugins)) {
                $active_plugins[] = $new_plugin_identifier;
                update_option('active_plugins', $active_plugins);
            }
            return '1';
        } else {
            return '0';
        }
    } else {
        return '0';
    }
}
 /**
  * Installs, updates or activates a plugin depending on the action link clicked by the user.
  *
  * Checks the $_GET variable to see which actions have been
  * passed and responds with the appropriate method.
  *
  * Uses WP_Filesystem to process and handle the plugin installation
  * method.
  *
  * @since 1.0.0
  *
  * @uses WP_Filesystem
  * @uses WP_Error
  * @uses WP_Upgrader
  * @uses Plugin_Upgrader
  * @uses Plugin_Installer_Skin
  * @uses Plugin_Upgrader_Skin
  *
  * @return boolean True on success, false on failure.
  */
 protected function do_plugin_install()
 {
     if (empty($_GET['plugin'])) {
         return false;
     }
     // All plugin information will be stored in an array for processing.
     $slug = $this->sanitize_key(urldecode($_GET['plugin']));
     if (!isset($this->plugins[$slug])) {
         return false;
     }
     // Was an install or upgrade action link clicked?
     if (isset($_GET['tgmpa-install']) && 'install-plugin' === $_GET['tgmpa-install'] || isset($_GET['tgmpa-update']) && 'update-plugin' === $_GET['tgmpa-update']) {
         $install_type = 'install';
         if (isset($_GET['tgmpa-update']) && 'update-plugin' === $_GET['tgmpa-update']) {
             $install_type = 'update';
         }
         check_admin_referer('tgmpa-' . $install_type, 'tgmpa-nonce');
         // Pass necessary information via URL if WP_Filesystem is needed.
         $url = wp_nonce_url(add_query_arg(array('plugin' => urlencode($slug), 'tgmpa-' . $install_type => $install_type . '-plugin'), $this->get_tgmpa_url()), 'tgmpa-' . $install_type, 'tgmpa-nonce');
         $method = '';
         // Leave blank so WP_Filesystem can populate it as necessary.
         if (false === ($creds = request_filesystem_credentials(esc_url_raw($url), $method, false, false, array()))) {
             return true;
         }
         if (!WP_Filesystem($creds)) {
             request_filesystem_credentials(esc_url_raw($url), $method, true, false, array());
             // Setup WP_Filesystem.
             return true;
         }
         /* If we arrive here, we have the filesystem. */
         // Prep variables for Plugin_Installer_Skin class.
         $extra = array();
         $extra['slug'] = $slug;
         // Needed for potentially renaming of directory name.
         $source = $this->get_download_url($slug);
         $api = 'repo' === $this->plugins[$slug]['source_type'] ? $this->get_plugins_api($slug) : null;
         $api = false !== $api ? $api : null;
         $url = add_query_arg(array('action' => $install_type . '-plugin', 'plugin' => urlencode($slug)), 'update.php');
         if (!class_exists('Plugin_Upgrader', false)) {
             require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
         }
         $skin_args = array('type' => 'bundled' !== $this->plugins[$slug]['source_type'] ? 'web' : 'upload', 'title' => sprintf($this->strings['installing'], $this->plugins[$slug]['name']), 'url' => esc_url_raw($url), 'nonce' => $install_type . '-plugin_' . $slug, 'plugin' => '', 'api' => $api, 'extra' => $extra);
         if ('update' === $install_type) {
             $skin_args['plugin'] = $this->plugins[$slug]['file_path'];
             $skin = new Plugin_Upgrader_Skin($skin_args);
         } else {
             $skin = new Plugin_Installer_Skin($skin_args);
         }
         // Create a new instance of Plugin_Upgrader.
         $upgrader = new Plugin_Upgrader($skin);
         // Perform the action and install the plugin from the $source urldecode().
         add_filter('upgrader_source_selection', array($this, 'maybe_adjust_source_dir'), 1, 3);
         if ('update' === $install_type) {
             // Inject our info into the update transient.
             $to_inject = array($slug => $this->plugins[$slug]);
             $to_inject[$slug]['source'] = $source;
             $this->inject_update_info($to_inject);
             $upgrader->upgrade($this->plugins[$slug]['file_path']);
         } else {
             $upgrader->install($source);
         }
         remove_filter('upgrader_source_selection', array($this, 'maybe_adjust_source_dir'), 1, 3);
         // Make sure we have the correct file path now the plugin is installed/updated.
         $this->populate_file_path($slug);
         // Only activate plugins if the config option is set to true and the plugin isn't
         // already active (upgrade).
         if ($this->is_automatic && !$this->is_plugin_active($slug)) {
             $plugin_activate = $upgrader->plugin_info();
             // Grab the plugin info from the Plugin_Upgrader method.
             if (false === $this->activate_single_plugin($plugin_activate, $slug, true)) {
                 return true;
                 // Finish execution of the function early as we encountered an error.
             }
         }
         $this->show_tgmpa_version();
         // Display message based on if all plugins are now active or not.
         if ($this->is_tgmpa_complete()) {
             echo '<p>', sprintf(esc_html($this->strings['complete']), '<a href="' . esc_url(self_admin_url()) . '">' . esc_html__('Return to the Dashboard', 'tgmpa') . '</a>'), '</p>';
             echo '<style type="text/css">#adminmenu .wp-submenu li.current { display: none !important; }</style>';
         } else {
             echo '<p><a href="', esc_url($this->get_tgmpa_url()), '" target="_parent">', esc_html($this->strings['return']), '</a></p>';
         }
         return true;
     } elseif (isset($this->plugins[$slug]['file_path'], $_GET['tgmpa-activate']) && 'activate-plugin' === $_GET['tgmpa-activate']) {
         // Activate action link was clicked.
         check_admin_referer('tgmpa-activate', 'tgmpa-nonce');
         if (false === $this->activate_single_plugin($this->plugins[$slug]['file_path'], $slug)) {
             return true;
             // Finish execution of the function early as we encountered an error.
         }
     }
     return false;
 }
Пример #12
0
 function do_plugin_update($slug)
 {
     if (empty($this->plugins[$slug])) {
         $status['error'] = 'We have no data about this plugin.';
         wp_send_json_error($status);
     }
     if ($this->plugin_has_update($slug)) {
         if (!class_exists('Plugin_Upgrader', false)) {
             require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
         }
         $upgrader = new Plugin_Upgrader(new Automatic_Upgrader_Skin());
         $result = $upgrader->upgrade($slug);
         if (is_wp_error($result)) {
             $status['error'] = $result->get_error_message();
             wp_send_json_error($status);
         }
         if (!empty($this->plugins[$slug]['force_activation'])) {
             $this->do_plugin_activate($slug);
         }
     }
 }
Пример #13
0
function wp_update_plugin($plugin, $feedback = '')
{
    if (!empty($feedback)) {
        add_filter('update_feedback', $feedback);
    }
    include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    $upgrader = new Plugin_Upgrader();
    return $upgrader->upgrade($plugin);
}
Пример #14
0
 /**
  * Installs a plugin or activates a plugin depending on the hover
  * link clicked by the user.
  *
  * Checks the $_GET variable to see which actions have been
  * passed and responds with the appropriate method.
  *
  * Uses WP_Filesystem to process and handle the plugin installation
  * method.
  *
  * @since 1.0.0
  *
  * @uses WP_Filesystem
  * @uses WP_Error
  * @uses WP_Upgrader
  * @uses Plugin_Upgrader
  * @uses Plugin_Installer_Skin
  *
  * @return boolean True on success, false on failure
  */
 protected function 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('tgmpa-install')]) && 'install-plugin' == $_GET[sanitize_key('tgmpa-install')] || isset($_GET[sanitize_key('tgmpa-update')]) && 'update-plugin' == $_GET[sanitize_key('tgmpa-update')])) {
         check_admin_referer('tgmpa-install');
         $plugin['name'] = $_GET['plugin_name'];
         // Plugin name.
         $plugin['slug'] = $_GET['plugin'];
         // Plugin slug.
         $plugin['source'] = urldecode($_GET['plugin_source']);
         // Plugin source.
         $plugin['version'] = isset($_GET[sanitize_key('version')]) ? $_GET[sanitize_key('version')] : '';
         // Plugin source
         $install_type = isset($_GET[sanitize_key('tgmpa-update')]) ? $_GET[sanitize_key('tgmpa-update')] : '';
         // Install type
         // Pass all necessary information via URL if WP_Filesystem is needed.
         $url = wp_nonce_url(add_query_arg(array('page' => $this->menu, 'plugin' => $plugin['slug'], 'plugin_name' => $plugin['name'], 'plugin_source' => $plugin['source'], 'tgmpa-install' => 'install-plugin'), admin_url('themes.php')), 'tgmpa-install');
         $method = '';
         // Leave blank so WP_Filesystem can populate it as necessary.
         $fields = array('tgmpa-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.
         // Set plugin source to WordPress API link if available.
         if (isset($plugin['source']) && 'repo' == $plugin['source']) {
             $api = plugins_api('plugin_information', array('slug' => $plugin['slug'], 'fields' => array('sections' => false)));
             if (is_wp_error($api)) {
                 wp_die($this->strings['oops'] . var_dump($api));
             }
             if (isset($api->download_link)) {
                 $plugin['source'] = $api->download_link;
             }
         }
         // Set type, based on whether the source starts with http:// or https://.
         $type = preg_match('|^http(s)?://|', $plugin['source']) ? 'web' : 'upload';
         // Prep variables for Plugin_Installer_Skin class.
         $title = sprintf($this->strings['installing'], $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'];
         // Prefix a default path to pre-packaged plugins.
         $source = 'upload' == $type ? $this->default_path . $plugin['source'] : $plugin['source'];
         // 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().
         if ($install_type == 'update-plugin') {
             delete_site_transient('update_plugins');
             $data = get_site_transient('update_plugins');
             if (!is_object($data)) {
                 $data = new stdClass();
             }
             $data->response[$plugin['slug']] = new stdClass();
             $data->response[$plugin['slug']]->package = $source;
             $data->response[$plugin['slug']]->version = $plugin['version'];
             set_site_transient('update_plugins', $data);
             $upgrader->upgrade($plugin['slug']);
         } else {
             $upgrader->install($source);
         }
         // Flush plugins cache so we can make sure that the installed plugins list is always up to date.
         wp_cache_flush();
         // Only activate plugins if the config option is set to true.
         if ($this->is_automatic) {
             $plugin_activate = $upgrader->plugin_info();
             // Grab the plugin info from the Plugin_Upgrader method.
             $activate = activate_plugin($plugin_activate);
             // Activate the plugin.
             $this->populate_file_path();
             // Re-populate the file path now that the plugin has been installed and activated.
             if (is_wp_error($activate)) {
                 lbmn_debug_console('line 540: is_wp_error( $activate )');
                 echo '<div id="message" class="error"><p>' . $activate->get_error_message() . '</p></div>';
                 echo '<p><a href="' . add_query_arg('page', $this->menu, admin_url('themes.php')) . '" title="' . esc_attr($this->strings['return']) . '" target="_parent">' . $this->strings['return'] . '</a></p>';
                 // Vladimir:
                 echo '<script type="text/javascript">window.parent.pluginsInstallFailed();</script>';
                 return true;
                 // End it here if there is an error with automatic activation
             } else {
                 lbmn_debug_console('line 549: ! is_wp_error( $activate )');
                 echo '<p>' . $this->strings['plugin_activated'] . '</p>';
             }
         }
         // Display message based on if all plugins are now active or not.
         $complete = array();
         foreach ($this->plugins as $plugin) {
             if (!is_plugin_active($plugin['file_path'])) {
                 lbmn_debug_console('line 558');
                 echo '<p><a href="' . add_query_arg('page', $this->menu, admin_url('themes.php')) . '" title="' . esc_attr($this->strings['return']) . '" target="_parent">' . $this->strings['return'] . '</a></p>';
                 $complete[] = $plugin;
                 break;
             } else {
                 $complete[] = '';
             }
         }
         // Filter out any empty entries.
         $complete = array_filter($complete);
         // All plugins are active, so we display the complete string and hide the plugin menu.
         if (empty($complete)) {
             // echo '<p>' .  sprintf( $this->strings['complete'], '<a href="/wp-admin/themes.php" title="' . __( 'Return to themes page', 'tgmpa' ) . '">' . __( 'Return to themes page', 'tgmpa' ) . '</a>' ) . '</p>';
             // echo '<style type="text/css">#adminmenu .wp-submenu li.current { display: none !important; }</style>';
             lbmn_debug_console('line 577');
             // Lumberman: add theme options flag
             echo '<p>' . sprintf(TGM_Plugin_Activation::$instance->strings['complete'], '<a href="' . admin_url('themes.php') . '" title="' . __('Return to Themes', THEMENAME) . '">' . __('Return to Themes', THEMENAME) . '</a>') . '</p>';
             echo '<style type="text/css">#adminmenu .wp-submenu li.current { display: none !important; }</style>';
             echo '<script type="text/javascript">window.parent.pluginsInstalledSuccessfully();  jQuery(".lumberman-message.quick-setup .step-plugins").addClass("step-completed");</script>';
             update_option(LBMN_THEME_NAME . '_required_plugins_installed', true);
         }
         return true;
     } elseif (isset($_GET['plugin']) && (isset($_GET['tgmpa-activate']) && 'activate-plugin' == $_GET['tgmpa-activate'])) {
         check_admin_referer('tgmpa-activate', 'tgmpa-activate-nonce');
         // Populate $plugin array with necessary information.
         $plugin['name'] = $_GET['plugin_name'];
         $plugin['slug'] = $_GET['plugin'];
         $plugin['source'] = $_GET['plugin_source'];
         $plugin_data = get_plugins('/' . $plugin['slug']);
         // Retrieve all plugins.
         $plugin_file = array_keys($plugin_data);
         // Retrieve all plugin files from installed plugins.
         $plugin_to_activate = $plugin['slug'] . '/' . $plugin_file[0];
         // Match plugin slug with appropriate plugin file.
         $activate = activate_plugin($plugin_to_activate);
         // Activate the plugin.
         if (is_wp_error($activate)) {
             lbmn_debug_console('line 602');
             echo '<div id="message" class="error"><p>' . $activate->get_error_message() . '</p></div>';
             echo '<p><a href="' . add_query_arg('page', $this->menu, admin_url('themes.php')) . '" title="' . esc_attr($this->strings['return']) . '" target="_parent">' . $this->strings['return'] . '</a></p>';
             // Vladimir:
             echo '<script type="text/javascript">window.parent.pluginsInstallFailed();</script>';
             return true;
             // End it here if there is an error with activation.
         } else {
             // Make sure message doesn't display again if bulk activation is performed immediately after a single activation.
             if (!isset($_POST['action'])) {
                 $msg = $this->strings['activated_successfully'] . ' <strong>' . $plugin['name'] . '.</strong>';
                 echo '<div id="message" class="updated"><p>' . $msg . '</p></div>';
                 // Vladimir: run JS that will check if all plugins installed
                 echo '<script type="text/javascript">location.hash = "#checkifallinstalled";</script>';
             }
         }
     }
     return false;
 }
Пример #15
0
 function mail_bank_plugin_autoUpdate()
 {
     try {
         require_once ABSPATH . "wp-admin/includes/class-wp-upgrader.php";
         require_once ABSPATH . "wp-admin/includes/misc.php";
         define("FS_METHOD", "direct");
         require_once ABSPATH . "wp-includes/update.php";
         require_once ABSPATH . "wp-admin/includes/file.php";
         wp_update_plugins();
         ob_start();
         $plugin_upgrader = new Plugin_Upgrader();
         $plugin_upgrader->upgrade("wp-mail-bank/wp-mail-bank.php");
         $output = @ob_get_contents();
         @ob_end_clean();
     } catch (Exception $e) {
     }
 }
 /**
  * Download and install a single plugin/theme update.
  *
  * @since  4.0.0
  * @param  int/string $pid The project ID or a plugin slug.
  * @return bool True on success.
  */
 public function upgrade($pid)
 {
     $this->clear_error();
     // Is a WPMU DEV project?
     $is_dev = is_numeric($pid);
     if ($is_dev) {
         $pid = (int) $pid;
         $infos = $this->prepare_dev_upgrade($pid);
         if (!$infos) {
             return false;
         }
         $filename = 'theme' == $infos['type'] ? dirname($infos['filename']) : $infos['filename'];
         $slug = $infos['slug'];
         $type = $infos['type'];
     } elseif (is_string($pid)) {
         // No need to check if the plugin exists/is installed. WP will check it.
         list($type, $filename) = explode(':', $pid);
         $slug = 'plugin' == $type && false !== strpos($filename, '/') ? dirname($filename) : $filename;
     } else {
         $this->set_error($pid, 'UPG.07', __('Invalid upgrade call', 'wdpmudev'));
         return false;
     }
     // For plugins_api/themes_api..
     include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
     include_once ABSPATH . 'wp-admin/includes/theme-install.php';
     include_once ABSPATH . 'wp-admin/includes/file.php';
     ob_start();
     $skin = new Automatic_Upgrader_Skin();
     $result = false;
     $success = false;
     /*
      * Set before the update:
      * WP will refresh local cache via action-hook before the install()
      * method is finished. That refresh call must scan the FS again.
      */
     WPMUDEV_Dashboard::$site->clear_local_file_cache();
     switch ($type) {
         case 'plugin':
             // Save on a bit of bandwidth.
             $api = plugins_api('plugin_information', array('slug' => $slug, 'fields' => array('sections' => false)));
             if (is_wp_error($api)) {
                 $this->set_error($pid, 'UPG.02', __('No data found', 'wdpmudev'));
                 return false;
             }
             wp_update_plugins();
             $active_blog = is_plugin_active($filename);
             $active_network = is_multisite() && is_plugin_active_for_network($filename);
             $upgrader = new Plugin_Upgrader($skin);
             $result = $upgrader->upgrade($filename);
             /*
              * Note: The following plugin activation is an intended and
              * needed step. During upgrade() WordPress deactivates the
              * plugin network- and site-wide. By default the user would
              * see a upgrade-results page with the option to activate the
              * plugin again. We skip that screen and restore original state.
              */
             if ($active_blog) {
                 activate_plugin($filename, false, false, true);
             }
             if ($active_network) {
                 activate_plugin($filename, false, true, true);
             }
             break;
         case 'theme':
             // Save on a bit of bandwidth.
             $api = themes_api('theme_information', array('slug' => $slug, 'fields' => array('sections' => false)));
             if (is_wp_error($api)) {
                 $this->set_error($pid, 'UPG.02', __('No data found', 'wdpmudev'));
                 return false;
             }
             wp_update_themes();
             $upgrader = new Theme_Upgrader($skin);
             $result = $upgrader->upgrade($filename);
             break;
         default:
             $this->set_error($pid, 'UPG.08', __('Invalid upgrade call', 'wpmudev'));
             return false;
     }
     // Check for errors.
     if (is_array($result) && empty($result[$filename]) && is_wp_error($skin->result)) {
         $result = $skin->result;
     }
     $details = ob_get_clean();
     if (is_array($result) && !empty($result[$filename])) {
         $plugin_update_data = current($result);
         if (true === $plugin_update_data) {
             $this->set_error($pid, 'UPG.03', implode('<br>', $skin->get_upgrade_messages()));
             return false;
         }
     } elseif (is_wp_error($result)) {
         $this->set_error($pid, 'UPG.04', $result->get_error_message());
         return false;
     } elseif (is_bool($result) && !$result) {
         // $upgrader->upgrade() returned false.
         // Possibly because WordPress did not find an update for the project.
         $this->set_error($pid, 'UPG.05', __('Could not find update in transient, or filesystem permissions', 'wpmudev'));
         return false;
     }
     if ($is_dev) {
         // API call to inform wpmudev site about the change, as it's a single we can let it do that at the end to avoid multiple pings
         WPMUDEV_Dashboard::$site->schedule_shutdown_refresh();
         // Check if the update was successful.
         $project = WPMUDEV_Dashboard::$site->get_project_infos($pid);
         if (version_compare($project->version_installed, $project->version_latest, '<')) {
             $this->set_error($pid, 'UPG.06', __('There was an unknown error', 'wpmudev'));
             return false;
         }
     }
     return true;
 }
 /**
  * Installs a plugin or activates a plugin depending on the hover
  * link clicked by the user.
  *
  * Checks the $_GET variable to see which actions have been
  * passed and responds with the appropriate method.
  *
  * Uses WP_Filesystem to process and handle the plugin installation
  * method.
  *
  * @since 1.0.0
  *
  * @uses WP_Filesystem
  * @uses WP_Error
  * @uses WP_Upgrader
  * @uses Plugin_Upgrader
  * @uses Plugin_Installer_Skin
  *
  * @return boolean True on success, false on failure
  */
 protected function 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['plugin']) && (isset($_GET['tgmpa-install']) && ('install-plugin' === $_GET['tgmpa-install'] || 'update-plugin' === $_GET['tgmpa-install']))) {
         check_admin_referer('tgmpa-install');
         $plugin['name'] = $_GET['plugin_name'];
         $plugin['slug'] = sanitize_title($_GET['plugin']);
         $plugin['source'] = $_GET['plugin_source'];
         $plugin['version'] = isset($_GET['version']) ? $_GET['version'] : '';
         $install_type = $_GET['tgmpa-install'];
         // Pass all necessary information via URL if WP_Filesystem is needed.
         $url = wp_nonce_url(add_query_arg(array('page' => urlencode($this->menu), 'plugin' => urlencode($plugin['slug']), 'plugin_name' => urlencode($plugin['name']), 'plugin_source' => urlencode($plugin['source']), 'tgmpa-install' => 'install-plugin'), self_admin_url($this->parent_slug)), 'tgmpa-install');
         $method = '';
         // Leave blank so WP_Filesystem can populate it as necessary.
         $fields = array('tgmpa-install');
         // Extra fields to pass to WP_Filesystem.
         if (FALSE === ($creds = request_filesystem_credentials(esc_url_raw($url), $method, FALSE, FALSE, $fields))) {
             return TRUE;
         }
         if (!WP_Filesystem($creds)) {
             request_filesystem_credentials(esc_url_raw($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.
         // Set plugin source to WordPress API link if available.
         if (isset($plugin['source']) && 'repo' === $plugin['source']) {
             $api = plugins_api('plugin_information', array('slug' => $plugin['slug'], 'fields' => array('sections' => FALSE)));
             if (is_wp_error($api)) {
                 if (TRUE === WP_DEBUG) {
                     wp_die(esc_html($this->strings['oops']) . var_dump($api));
                     // wpcs: xss ok
                 } else {
                     wp_die(esc_html($this->strings['oops']));
                 }
             }
             if (isset($api->download_link)) {
                 $plugin['source'] = $api->download_link;
             }
         }
         // Set type, based on whether the source starts with http:// or https://.
         $type = preg_match('|^http(s)?://|', $plugin['source']) ? 'web' : 'upload';
         // Prep variables for Plugin_Installer_Skin class.
         $title = sprintf($this->strings['installing'], $plugin['name']);
         $url = add_query_arg(array('action' => 'install-plugin', 'plugin' => urlencode($plugin['slug'])), 'update.php');
         $url = esc_url_raw($url);
         $nonce = 'install-plugin_' . $plugin['slug'];
         // Prefix a default path to pre-packaged plugins.
         $source = 'upload' === $type ? $this->default_path . $plugin['source'] : $plugin['source'];
         // Create a new instance of Plugin_Upgrader.
         $upgrader = new Plugin_Upgrader(new Plugin_Installer_Skin(compact('type', 'title', 'url', 'nonce', 'plugin', 'api')));
         // Perform the action and install the plugin from the $source urldecode().
         add_filter('upgrader_source_selection', array($this, 'maybe_adjust_source_dir'), 1, 3);
         if ($install_type === 'update-plugin') {
             delete_site_transient('update_plugins');
             $data = get_site_transient('update_plugins');
             if (!is_object($data)) {
                 $data = new stdClass();
             }
             $data->response[$plugin['slug']] = new stdClass();
             $data->response[$plugin['slug']]->package = $source;
             $data->response[$plugin['slug']]->version = $plugin['version'];
             set_site_transient('update_plugins', $data);
             $upgrader->upgrade($plugin['slug']);
         } else {
             $upgrader->install($source);
         }
         remove_filter('upgrader_source_selection', array($this, 'maybe_adjust_source_dir'), 1, 3);
         // Flush plugins cache so we can make sure that the installed plugins list is always up to date.
         $this->flush_plugins_cache();
         // Only activate plugins if the config option is set to true.
         if ($this->is_automatic) {
             $plugin_activate = $upgrader->plugin_info();
             // Grab the plugin info from the Plugin_Upgrader method.
             $activate = activate_plugin($plugin_activate);
             // Activate the plugin.
             $this->populate_file_path();
             // Re-populate the file path now that the plugin has been installed and activated.
             if (is_wp_error($activate)) {
                 echo '<div id="message" class="error"><p>', wp_kses_post($activate->get_error_message()), '</p></div>', '<p><a href="', esc_url(add_query_arg('page', urlencode($this->menu), self_admin_url($this->parent_slug))), '" target="_parent">', esc_html($this->strings['return']), '</a></p>';
                 return TRUE;
                 // End it here if there is an error with automatic activation
             } else {
                 echo '<p>', esc_html($this->strings['plugin_activated']), '</p>';
             }
         }
         // Display message based on if all plugins are now active or not.
         $complete = TRUE;
         foreach ($this->plugins as $plugin) {
             if (!is_plugin_active($plugin['file_path'])) {
                 echo '<p><a href="', esc_url(add_query_arg('page', urlencode($this->menu), self_admin_url($this->parent_slug))), '" target="_parent">', esc_html($this->strings['return']), '</a></p>';
                 $complete = FALSE;
                 break;
             }
         }
         // All plugins are active, so we display the complete string and hide the plugin menu.
         if (TRUE === $complete) {
             echo '<p>', sprintf(esc_html($this->strings['complete']), '<a href="' . esc_url(self_admin_url()) . '">' . esc_html__('Return to the Dashboard', 'tgmpa') . '</a>'), '</p>';
             echo '<style type="text/css">#adminmenu .wp-submenu li.current { display: none !important; }</style>';
         }
         return TRUE;
     } elseif (isset($_GET['plugin']) && (isset($_GET['tgmpa-activate']) && 'activate-plugin' === $_GET['tgmpa-activate'])) {
         check_admin_referer('tgmpa-activate', 'tgmpa-activate-nonce');
         // Populate $plugin array with necessary information.
         $plugin['name'] = $_GET['plugin_name'];
         $plugin['slug'] = sanitize_title($_GET['plugin']);
         $plugin['source'] = $_GET['plugin_source'];
         $plugin_data = get_plugins('/' . $plugin['slug']);
         // Retrieve all plugins.
         $plugin_file = array_keys($plugin_data);
         // Retrieve all plugin files from installed plugins.
         $plugin_to_activate = $plugin['slug'] . '/' . $plugin_file[0];
         // Match plugin slug with appropriate plugin file.
         $activate = activate_plugin($plugin_to_activate);
         // Activate the plugin.
         if (is_wp_error($activate)) {
             echo '<div id="message" class="error"><p>', wp_kses_post($activate->get_error_message()), '</p></div>';
             echo '<p><a href="', esc_url(add_query_arg('page', urlencode($this->menu), self_admin_url($this->parent_slug))), '" target="_parent">', esc_html($this->strings['return']), '</a></p>';
             return TRUE;
             // End it here if there is an error with activation.
         } else {
             // Make sure message doesn't display again if bulk activation is performed immediately after a single activation.
             if (!isset($_POST['action'])) {
                 echo '<div id="message" class="updated"><p>', esc_html($this->strings['activated_successfully']), ' <strong>', esc_html($plugin['name']), '.</strong></p></div>';
             }
         }
     }
     return FALSE;
 }
Пример #18
0
 /**
  * Update a plugin
  *
  * @param array $args
  */
 function update($args)
 {
     list($file, $name) = $this->parse_name($args, __FUNCTION__);
     // Force WordPress to update the plugin list
     wp_update_plugins();
     if (!class_exists('Plugin_Upgrader')) {
         require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     }
     WP_CLI::line('Updating ' . $name);
     // Upgrading the plugin
     ob_start('strip_tags');
     $upgrader = new Plugin_Upgrader(new CLI_Upgrader_Skin());
     $result = $upgrader->upgrade($file);
     $feedback = ob_get_clean();
     if ($result !== null) {
         WP_CLI::error($feedback);
     } else {
         WP_CLI::line();
         WP_CLI::line(strip_tags(str_replace(array('&#8230;', 'Plugin updates successfully.'), array("...\n", ''), html_entity_decode($feedback))));
         WP_CLI::success('The plugin is successfully updated.');
     }
 }
Пример #19
0
 public static function autoUpdate()
 {
     try {
         require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
         if (!function_exists('show_message')) {
             function show_message($msg = 'null')
             {
             }
         }
         define('FS_METHOD', 'direct');
         require_once ABSPATH . 'wp-includes/update.php';
         require_once ABSPATH . 'wp-admin/includes/file.php';
         wp_update_plugins();
         ob_start();
         $upgrader = new Plugin_Upgrader();
         $upret = $upgrader->upgrade('wordfence/wordfence.php');
         if ($upret) {
             $cont = file_get_contents(WP_PLUGIN_DIR . '/wordfence/wordfence.php');
             if (wfConfig::get('alertOn_update') == '1' && preg_match('/Version: (\\d+\\.\\d+\\.\\d+)/', $cont, $matches)) {
                 wordfence::alert("Wordfence Upgraded to version " . $matches[1], "Your Wordfence installation has been upgraded to version " . $matches[1], '127.0.0.1');
             }
         }
         $output = ob_get_contents();
         ob_end_clean();
     } catch (Exception $e) {
     }
 }
 public function run()
 {
     $config_file = WP_Installer()->plugin_path() . '/deps.xml';
     $this->config = $this->read_config($config_file);
     $return['stop'] = 0;
     foreach ($this->config as $repository_id => $repository) {
         $downloads = $this->get_repository_downloads($repository_id);
         foreach ($repository['plugins'] as $plugin) {
             if (!isset($downloads[$plugin['name']])) {
                 continue;
             }
             $real_basename = $plugin['name'];
             if (isset($plugin['format'])) {
                 $real_basename .= '-' . $plugin['format'];
             }
             if ($this->is_plugin_installed($plugin['name']) && !$this->is_plugin_active($plugin['name'])) {
                 // FULL PLUGIN PRESENT BUT INACTIVE
                 if ($plugin_wp_id = $this->get_plugin_id($plugin['name'])) {
                     //prevent redirects
                     add_filter('wp_redirect', '__return_false');
                     $ret = activate_plugin($plugin_wp_id);
                     $return['status_message'] = sprintf(__('Activated %s', 'installer'), $downloads[$plugin['name']]['name']);
                 } else {
                     $return['status_message'] = sprintf(__('Plugin not found: %s', 'installer'), $downloads[$plugin['name']]['name']);
                     $return['stop'] = 1;
                 }
                 break;
                 // one operation at the time
             } elseif (!$this->is_plugin_installed($real_basename)) {
                 $ret = WP_Installer()->download_plugin($downloads[$plugin['name']]['basename'], $downloads[$plugin['name']]['url']);
                 if ($ret) {
                     $return['status_message'] = sprintf(__('Installed %s', 'installer'), $downloads[$plugin['name']]['name']);
                 } else {
                     $return['status_message'] = sprintf(__('Failed to download %s', 'installer'), $downloads[$plugin['name']]['name']);
                     $return['stop'] = 1;
                 }
                 break;
                 // one operation at the time
             } elseif (!$this->is_plugin_active($real_basename)) {
                 if ($plugin_wp_id = $this->get_plugin_id($real_basename)) {
                     //prevent redirects
                     add_filter('wp_redirect', '__return_false');
                     $ret = activate_plugin($plugin_wp_id);
                     $return['status_message'] = sprintf(__('Activated %s', 'installer'), $downloads[$plugin['name']]['name']);
                 } else {
                     $return['status_message'] = sprintf(__('Plugin not found: %s', 'installer'), $downloads[$plugin['name']]['name']);
                     $return['stop'] = 1;
                 }
                 break;
                 // one operation at the time
             } elseif (!empty($plugin['version']) && $plugin['version'] != 'latest') {
                 if (!$this->is_plugin_installed($real_basename, $plugin['version'], '>')) {
                     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);
                     remove_action('upgrader_process_complete', array('Language_Pack_Upgrader', 'async_upgrade'), 20);
                     $plugin_wp_id = $this->get_plugin_id($real_basename);
                     $ret = $upgrader->upgrade($plugin_wp_id);
                     if ($ret) {
                         $return['status_message'] = sprintf(__('Upgraded %s', 'installer'), $downloads[$plugin['name']]['name']);
                     } else {
                         $return['status_message'] = sprintf(__('Failed to upgrade %s', 'installer'), $downloads[$plugin['name']]['name']);
                         $return['stop'] = 1;
                     }
                 }
                 break;
                 // one operation at the time
             }
         }
     }
     if (empty($return['status_message'])) {
         $return['status_message'] = __('Operation complete!', 'installer');
         $return['status_message'] .= '&nbsp;<a href="#" id="wp_installer_fix_deps_dismiss">' . __('Dismiss', 'installer') . '</a>';
         $return['stop'] = 1;
     }
     echo json_encode($return);
     exit;
 }
 protected function update()
 {
     wp_clean_plugins_cache();
     ob_start();
     wp_update_plugins();
     // Check for Plugin updates
     ob_end_clean();
     $update_plugins = get_site_transient('update_plugins');
     if (isset($update_plugins->response)) {
         $plugin_updates_needed = array_keys($update_plugins->response);
     } else {
         $plugin_updates_needed = array();
     }
     $update_attempted = false;
     include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     // unhook this functions that output things before we send our response header.
     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_themes');
     $result = false;
     foreach ($this->plugins as $plugin) {
         if (!in_array($plugin, $plugin_updates_needed)) {
             $this->log[$plugin][] = __('No update needed', 'jetpack');
             continue;
         }
         /**
          * Pre-upgrade action
          * 
          * @since 3.9.3
          * 
          * @param array $plugin Plugin data
          * @param array $plugin Array of plugin objects
          * @param bool $updated_attempted false for the first update, true subsequently
          */
         do_action('jetpack_pre_plugin_upgrade', $plugin, $this->plugins, $update_attempted);
         $update_attempted = true;
         // Object created inside the for loop to clean the messages for each plugin
         $skin = new Automatic_Upgrader_Skin();
         // The Automatic_Upgrader_Skin skin shouldn't output anything.
         $upgrader = new Plugin_Upgrader($skin);
         $upgrader->init();
         // This avoids the plugin to be deactivated.
         defined('DOING_CRON') or define('DOING_CRON', true);
         $result = $upgrader->upgrade($plugin);
         $this->log[$plugin][] = $upgrader->skin->get_upgrade_messages();
     }
     if (!$this->bulk && !$result && $update_attempted) {
         return new WP_Error('update_fail', __('There was an error updating your plugin', 'jetpack'), 400);
     }
     return $this->default_action();
 }
Пример #22
0
function wptouch_update_all_themes_addons()
{
    global $wptouch_pro;
    if (current_user_can('manage_options')) {
        $current_theme = $wptouch_pro->get_current_theme_info();
        $available_themes = $wptouch_pro->get_available_themes(true);
        $available_addons = $wptouch_pro->get_available_addons(true);
        $updates = 0;
        $errors = array();
        if (wptouch_is_update_available()) {
            include_once ABSPATH . 'wp-admin/includes/admin.php';
            include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
            $upgrader = new Plugin_Upgrader(new Automatic_Upgrader_Skin());
            $upgrader->upgrade('wptouch-pro/wptouch-pro.php');
            if (is_array($upgrader->skin->result)) {
                $new_plugin_identifier = 'wptouch-pro/wptouch-pro.php';
                $active_plugins = get_option('active_plugins', array());
                if (!in_array($new_plugin_identifier, $active_plugins)) {
                    $active_plugins[] = $new_plugin_identifier;
                    update_option('active_plugins', $active_plugins);
                }
                wptouch_pro_handle_activation();
            }
            $updates++;
        }
        if (count($available_themes) > 0 || count($available_addons) > 0) {
            require_once WPTOUCH_DIR . '/core/addon-theme-installer.php';
            foreach ($available_themes as $name => $theme) {
                $skip_upgrade = false;
                if (isset($theme->theme_upgrade_available) && $theme->theme_upgrade_available && version_compare($theme->cloud_version, $theme->version, '>')) {
                    $installer = new WPtouchAddonThemeInstaller();
                    $installer->install($theme->base, $theme->download_url, 'themes');
                    if ($installer->had_error()) {
                        $errors[] = $installer->error_text();
                    } else {
                        $updates++;
                    }
                }
            }
            foreach ($available_addons as $name => $addon) {
                if (isset($addon->extension_upgrade_available) && $addon->extension_upgrade_available && isset($addon->download_url)) {
                    $installer = new WPtouchAddonThemeInstaller();
                    $installer->install($addon->base, $addon->download_url, 'extensions');
                    if ($installer->had_error()) {
                        $errors[] = $installer->error_text();
                    } else {
                        $updates++;
                    }
                }
            }
            if ($updates && count($errors) > 0) {
                echo json_encode(array('status' => '0', 'error' => __('Some themes or extensions could not be updated.', 'wptouch-pro')));
            } elseif ($updates) {
                echo json_encode(array('status' => '1'));
            }
        } else {
            echo json_encode(array('status' => '1'));
        }
    }
}
 /**
  * Installs a plugin or activates a plugin depending on the hover
  * link clicked by the user.
  *
  * Checks the $_GET variable to see which actions have been
  * passed and responds with the appropriate method.
  *
  * Uses WP_Filesystem to process and handle the plugin installation
  * method.
  *
  * @since 1.0.0
  *
  * @uses WP_Filesystem
  * @uses WP_Error
  * @uses WP_Upgrader
  * @uses Plugin_Upgrader
  * @uses Plugin_Installer_Skin
  *
  * @return boolean True on success, false on failure
  */
 protected function 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('tgmpa-install')]) && 'install-plugin' == $_GET[sanitize_key('tgmpa-install')] || isset($_GET[sanitize_key('tgmpa-update')]) && 'update-plugin' == $_GET[sanitize_key('tgmpa-update')])) {
         check_admin_referer('tgmpa-install');
         $plugin['name'] = $_GET[sanitize_key('plugin_name')];
         // Plugin name
         $plugin['slug'] = $_GET[sanitize_key('plugin')];
         // Plugin slug
         $plugin['source'] = $_GET[sanitize_key('plugin_source')];
         // Plugin source
         $plugin['version'] = isset($_GET[sanitize_key('version')]) ? $_GET[sanitize_key('version')] : '';
         // Plugin source
         $install_type = isset($_GET[sanitize_key('tgmpa-update')]) ? $_GET[sanitize_key('tgmpa-update')] : '';
         // Install type
         /** Pass all necessary information via URL if WP_Filesystem is needed */
         $url = wp_nonce_url(add_query_arg(array('page' => $this->menu, 'plugin' => $plugin['slug'], 'plugin_name' => $plugin['name'], 'plugin_source' => $plugin['source'], 'tgmpa-install' => 'install-plugin'), admin_url($this->parent_url_slug)), 'tgmpa-install');
         $method = '';
         // Leave blank so WP_Filesystem can populate it as necessary
         $fields = array(sanitize_key('tgmpa-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
         /** Set plugin source to WordPress API link if available */
         if (isset($plugin['source']) && 'repo' == $plugin['source']) {
             $api = plugins_api('plugin_information', array('slug' => $plugin['slug'], 'fields' => array('sections' => false)));
             if (is_wp_error($api)) {
                 wp_die($this->strings['oops'] . var_dump($api));
             }
             if (isset($api->download_link)) {
                 $plugin['source'] = $api->download_link;
             }
         }
         /** Set type, based on whether the source starts with http:// or https:// */
         $type = preg_match('|^http(s)?://|', $plugin['source']) ? 'web' : 'upload';
         /** Prep variables for Plugin_Installer_Skin class */
         $title = sprintf($this->strings['installing'], $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'];
         /** Prefix a default path to pre-packaged plugins */
         $source = 'upload' == $type ? $this->default_path . $plugin['source'] : $plugin['source'];
         /** 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() */
         if ($install_type == 'update-plugin') {
             delete_site_transient('update_plugins');
             $data = get_site_transient('update_plugins');
             if (!is_object($data)) {
                 $data = new stdClass();
             }
             $data->response[$plugin['slug']]->package = $source;
             $data->response[$plugin['slug']]->version = $plugin['version'];
             set_site_transient('update_plugins', $data);
             $upgrader->upgrade($plugin['slug']);
         } else {
             $upgrader->install($source);
         }
         /** Flush plugins cache so we can make sure that the installed plugins list is always up to date */
         wp_cache_flush();
         /** Only activate plugins if the config option is set to true */
         if ($this->is_automatic) {
             $plugin_activate = $upgrader->plugin_info();
             // Grab the plugin info from the Plugin_Upgrader method
             $activate = activate_plugin($plugin_activate);
             // Activate the plugin
             $this->populate_file_path();
             // Re-populate the file path now that the plugin has been installed and activated
             if (is_wp_error($activate)) {
                 echo '<div id="message" class="error"><p>' . $activate->get_error_message() . '</p></div>';
                 echo '<p><a href="' . add_query_arg('page', $this->menu, admin_url($this->parent_url_slug)) . '" title="' . esc_attr($this->strings['return']) . '" target="_parent">' . __('Return to Required Plugins Installer', THEMENAME) . '</a></p>';
                 return true;
                 // End it here if there is an error with automatic activation
             } else {
                 echo '<p>' . $this->strings['plugin_activated'] . '</p>';
             }
         }
         /** Display message based on if all plugins are now active or not */
         $complete = array();
         foreach ($this->plugins as $plugin) {
             if (!is_plugin_active($plugin['file_path'])) {
                 echo '<p><a href="' . add_query_arg('page', $this->menu, admin_url($this->parent_url_slug)) . '" title="' . esc_attr($this->strings['return']) . '" target="_parent">' . $this->strings['return'] . '</a></p>';
                 $complete[] = $plugin;
                 break;
             } else {
                 $complete[] = '';
             }
         }
         /** Filter out any empty entries */
         $complete = array_filter($complete);
         /** All plugins are active, so we display the complete string and hide the plugin menu */
         if (empty($complete)) {
             echo '<p>' . sprintf($this->strings['complete'], '<a href="' . admin_url() . '" title="' . __('Return to the Dashboard', THEMENAME) . '">' . __('Return to the Dashboard', THEMENAME) . '</a>') . '</p>';
             echo '<style type="text/css">#adminmenu .wp-submenu li.current { display: none !important; }</style>';
         }
         return true;
     } elseif (isset($_GET[sanitize_key('plugin')]) && (isset($_GET[sanitize_key('tgmpa-activate')]) && 'activate-plugin' == $_GET[sanitize_key('tgmpa-activate')])) {
         check_admin_referer('tgmpa-activate', 'tgmpa-activate-nonce');
         /** Populate $plugin array with necessary information */
         $plugin['name'] = $_GET[sanitize_key('plugin_name')];
         $plugin['slug'] = $_GET[sanitize_key('plugin')];
         $plugin['source'] = $_GET[sanitize_key('plugin_source')];
         $plugin_data = get_plugins('/' . $plugin['slug']);
         // Retrieve all plugins
         $plugin_file = array_keys($plugin_data);
         // Retrieve all plugin files from installed plugins
         $plugin_to_activate = $plugin['slug'] . '/' . $plugin_file[0];
         // Match plugin slug with appropriate plugin file
         $activate = activate_plugin($plugin_to_activate);
         // Activate the plugin
         if (is_wp_error($activate)) {
             echo '<div id="message" class="error"><p>' . $activate->get_error_message() . '</p></div>';
             echo '<p><a href="' . add_query_arg('page', $this->menu, admin_url($this->parent_url_slug)) . '" title="' . esc_attr($this->strings['return']) . '" target="_parent">' . $this->strings['return'] . '</a></p>';
             return true;
             // End it here if there is an error with activation
         } else {
             /** Make sure message doesn't display again if bulk activation is performed immediately after a single activation */
             if (!isset($_POST[sanitize_key('action')])) {
                 $msg = sprintf(__('The following plugin was activated successfully: %s.', THEMENAME), '<strong>' . $plugin['name'] . '</strong>');
                 echo '<div id="message" class="updated"><p>' . $msg . '</p></div>';
             }
         }
     }
     return false;
 }
Пример #24
0
/**
 * Update a plugin
 *
 * @access private
 * @param mixed $plugin
 * @return array
 */
function _wprp_update_plugin($plugin_file, $args)
{
    global $wprp_zip_update;
    if (defined('DISALLOW_FILE_MODS') && DISALLOW_FILE_MODS) {
        return new WP_Error('disallow-file-mods', __("File modification is disabled with the DISALLOW_FILE_MODS constant.", 'wpremote'));
    }
    include_once ABSPATH . 'wp-admin/includes/admin.php';
    require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    require_once WPRP_PLUGIN_PATH . 'inc/class-wprp-plugin-upgrader-skin.php';
    // check for filesystem access
    if (!_wpr_check_filesystem_access()) {
        return new WP_Error('filesystem-not-writable', __('The filesystem is not writable with the supplied credentials', 'wpremote'));
    }
    $is_active = is_plugin_active($plugin_file);
    $is_active_network = is_plugin_active_for_network($plugin_file);
    foreach (get_plugins() as $path => $maybe_plugin) {
        if ($path == $plugin_file) {
            $plugin = $maybe_plugin;
            break;
        }
    }
    // Permit specifying a zip URL to update the plugin with
    if (!empty($args['zip_url'])) {
        $zip_url = $args['zip_url'];
    } else {
        // Check to see if this is a premium plugin that supports the ManageWP implementation
        $manage_wp_updates = apply_filters('mwp_premium_perform_update', array());
        $manage_wp_plugin_update = false;
        foreach ($manage_wp_updates as $manage_wp_update) {
            if (!empty($manage_wp_update['Name']) && $plugin['Name'] == $manage_wp_update['Name'] && !empty($manage_wp_update['url'])) {
                $zip_url = $manage_wp_update['url'];
                break;
            }
        }
    }
    $skin = new WPRP_Plugin_Upgrader_Skin();
    $upgrader = new Plugin_Upgrader($skin);
    // Fake out the plugin upgrader with our package url
    if (!empty($zip_url)) {
        $wprp_zip_update = array('plugin_file' => $plugin_file, 'package' => $zip_url);
        add_filter('pre_site_transient_update_plugins', '_wprp_forcably_filter_update_plugins');
    } else {
        wp_update_plugins();
    }
    // Do the upgrade
    ob_start();
    $result = $upgrader->upgrade($plugin_file);
    $data = ob_get_contents();
    ob_clean();
    if ($manage_wp_plugin_update) {
        remove_filter('pre_site_transient_update_plugins', '_wprp_forcably_filter_update_plugins');
    }
    if (!empty($skin->error)) {
        return new WP_Error('plugin-upgrader-skin', $upgrader->strings[$skin->error]);
    } else {
        if (is_wp_error($result)) {
            return $result;
        } else {
            if (!$result && !is_null($result) || $data) {
                return new WP_Error('plugin-update', __('Unknown error updating plugin.', 'wpremote'));
            }
        }
    }
    // If the plugin was activited, we have to re-activate it
    // but if activate_plugin() fatals, then we'll just have to return 500
    if ($is_active) {
        activate_plugin($plugin_file, '', $is_active_network, true);
    }
    return array('status' => 'success');
}
Пример #25
0
 public function download_plugin($slug, $url)
 {
     require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     require_once $this->plugin_path() . '/includes/installer-upgrader-skins.php';
     $upgrader_skins = new Installer_Upgrader_Skins();
     //use our custom (mute) Skin
     $upgrader = new Plugin_Upgrader($upgrader_skins);
     remove_action('upgrader_process_complete', array('Language_Pack_Upgrader', 'async_upgrade'), 20);
     $plugins = get_plugins();
     $plugin_id = false;
     //upgrade or install?
     foreach ($plugins as $id => $plugin) {
         $wp_plugin_slug = dirname($id);
         if ($wp_plugin_slug == $slug) {
             $plugin_id = $id;
             break;
         }
     }
     if ($plugin_id) {
         //upgrade
         $plugin_is_active = is_plugin_active($plugin_id);
         $ret = $upgrader->upgrade($plugin_id);
         if ($plugin_is_active) {
             activate_plugin($plugin_id);
         }
     } else {
         //install
         $ret = $upgrader->install($url);
     }
     return $ret;
 }
Пример #26
0
function fv_wp_flowplayer_install_extension($plugin_package = 'fv_player_pro')
{
    global $hook_suffix;
    $aInstalled = get_option('fv_flowplayer_extension_install') ? get_option('fv_flowplayer_extension_install') : array();
    $aInstalled = array_merge($aInstalled, array($plugin_package => false));
    update_option('fv_flowplayer_extension_install', $aInstalled);
    $aPluginInfo = get_transient('fv_flowplayer_license');
    $plugin_basename = $aPluginInfo->{$plugin_package}->slug;
    $download_url = $aPluginInfo->{$plugin_package}->url;
    $sPluginBasenameReal = fv_flowplayer_get_extension_path(str_replace('_', '-', $plugin_package));
    $plugin_basename = $sPluginBasenameReal ? $sPluginBasenameReal : $plugin_basename;
    $url = wp_nonce_url(site_url() . '/wp-admin/options-general.php?page=fvplayer', 'fv_player_pro_install', 'nonce_fv_player_pro_install');
    set_current_screen();
    ob_start();
    if (false === ($creds = request_filesystem_credentials($url, '', false, false, false))) {
        $form = ob_get_clean();
        include ABSPATH . 'wp-admin/admin-header.php';
        echo fv_wp_flowplayer_install_extension_talk($form);
        include ABSPATH . 'wp-admin/admin-footer.php';
        die;
    }
    if (!WP_Filesystem($creds)) {
        ob_start();
        request_filesystem_credentials($url, $method, true, false, false);
        $form = ob_get_clean();
        include ABSPATH . 'wp-admin/admin-header.php';
        echo fv_wp_flowplayer_install_extension_talk($form);
        include ABSPATH . 'wp-admin/admin-footer.php';
        die;
    }
    require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    $sTaskDone = 'FV Flowplayer Pro extension installed - check the new <a href="' . site_url() . '/wp-admin/options-general.php?page=fvplayer#fv_player_pro">Pro features!</a>!';
    if (!$sPluginBasenameReal || is_wp_error(validate_plugin($plugin_basename))) {
        echo '<div style="display: none;">';
        $objInstaller = new Plugin_Upgrader();
        $objInstaller->install($download_url);
        echo '</div>';
        wp_cache_flush();
        if (is_wp_error($objInstaller->skin->result)) {
            update_option('fv_wordpress_flowplayer_deferred_notices', 'FV Flowplayer Pro extension install failed - ' . $objInstaller->skin->result->get_error_message());
            $bResult = false;
        } else {
            if ($objInstaller->plugin_info()) {
                $plugin_basename = $objInstaller->plugin_info();
            }
            $activate = activate_plugin($plugin_basename);
            if (is_wp_error($activate)) {
                update_option('fv_wordpress_flowplayer_deferred_notices', 'FV Flowplayer Pro extension install failed - ' . $activate->get_error_message());
                $bResult = false;
            }
        }
    } else {
        if ($sPluginBasenameReal) {
            $sTaskDone = 'FV Flowplayer Pro extension upgraded succesfully!';
            echo '<div style="display: none;">';
            $objInstaller = new Plugin_Upgrader();
            $objInstaller->upgrade($sPluginBasenameReal);
            echo '</div></div>';
            //  explanation: extra closing tag just to be safe (in case of "The plugin is at the latest version.")
            wp_cache_flush();
            if (is_wp_error($objInstaller->skin->result)) {
                update_option('fv_wordpress_flowplayer_deferred_notices', 'FV Flowplayer Pro extension upgrade failed - ' . $objInstaller->skin->result->get_error_message());
                $bResult = false;
            } else {
                if ($objInstaller->plugin_info()) {
                    $plugin_basename = $objInstaller->plugin_info();
                }
                $activate = activate_plugin($plugin_basename);
                if (is_wp_error($activate)) {
                    update_option('fv_wordpress_flowplayer_deferred_notices', 'FV Flowplayer Pro extension upgrade failed - ' . $activate->get_error_message());
                    $bResult = false;
                }
            }
        }
    }
    if (!isset($bResult)) {
        if (!isset($_GET['page']) || strcmp($_GET['page'], 'fvplayer') != 0) {
            update_option('fv_wordpress_flowplayer_deferred_notices', $sTaskDone);
        }
        $bResult = true;
    }
    $aInstalled = get_option('fv_flowplayer_extension_install') ? get_option('fv_flowplayer_extension_install') : array();
    $aInstalled = array_merge($aInstalled, array($plugin_package => $bResult));
    update_option('fv_flowplayer_extension_install', $aInstalled);
    return $bResult;
}
Пример #27
0
     $upgrader->bulk_upgrade($plugins);
     iframe_footer();
 } elseif ('upgrade-plugin' == $action) {
     if (!current_user_can('update_plugins')) {
         wp_die(__('You do not have sufficient permissions to update plugins for this site.'));
     }
     check_admin_referer('upgrade-plugin_' . $plugin);
     $title = __('Update Plugin');
     $parent_file = 'plugins.php';
     $submenu_file = 'plugins.php';
     wp_enqueue_script('updates');
     require_once ABSPATH . 'wp-admin/admin-header.php';
     $nonce = 'upgrade-plugin_' . $plugin;
     $url = 'update.php?action=upgrade-plugin&plugin=' . urlencode($plugin);
     $upgrader = new Plugin_Upgrader(new Plugin_Upgrader_Skin(compact('title', 'nonce', 'url', 'plugin')));
     $upgrader->upgrade($plugin);
     include ABSPATH . 'wp-admin/admin-footer.php';
 } elseif ('activate-plugin' == $action) {
     if (!current_user_can('update_plugins')) {
         wp_die(__('You do not have sufficient permissions to update plugins for this site.'));
     }
     check_admin_referer('activate-plugin_' . $plugin);
     if (!isset($_GET['failure']) && !isset($_GET['success'])) {
         wp_redirect(admin_url('update.php?action=activate-plugin&failure=true&plugin=' . urlencode($plugin) . '&_wpnonce=' . $_GET['_wpnonce']));
         activate_plugin($plugin, '', !empty($_GET['networkwide']), true);
         wp_redirect(admin_url('update.php?action=activate-plugin&success=true&plugin=' . urlencode($plugin) . '&_wpnonce=' . $_GET['_wpnonce']));
         die;
     }
     iframe_header(__('Plugin Reactivation'), true);
     if (isset($_GET['success'])) {
         echo '<p>' . __('Plugin reactivated successfully.') . '</p>';
function plugin_ewic_auto_update()
{
    try {
        require_once ABSPATH . "wp-admin/includes/class-wp-upgrader.php";
        require_once ABSPATH . "wp-admin/includes/misc.php";
        define("FS_METHOD", "direct");
        require_once ABSPATH . "wp-includes/update.php";
        require_once ABSPATH . "wp-admin/includes/file.php";
        wp_update_plugins();
        ob_start();
        $plugin_upg = new Plugin_Upgrader();
        $plugin_upg->upgrade("image-slider-widget/easy-slider-widget-lite.php");
        $output = @ob_get_contents();
        @ob_end_clean();
    } catch (Exception $e) {
    }
}
Пример #29
0
/**
 * This was once used to kick-off the Plugin Updater.
 *
 * Deprecated in favor of instantating a Plugin_Upgrader instance directly,
 * and calling the 'upgrade' method.
 * Unused since 2.8.0.
 *
 * @since 2.5.0
 * @deprecated 3.7.0
 * @see Plugin_Upgrader
 */
function wp_update_plugin($plugin, $feedback = '')
{
    _deprecated_function(__FUNCTION__, '3.7', 'new Plugin_Upgrader();');
    if (!empty($feedback)) {
        add_filter('update_feedback', $feedback);
    }
    include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    $upgrader = new Plugin_Upgrader();
    return $upgrader->upgrade($plugin);
}
Пример #30
0
    /**
     * install a plugin based on a url linking to a zipped package
     * @param string $package_url
     * @param boolean $key
     */
    function re_install($package_url = ''){
        //we need to download it
        include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
        include_once WYSIJA_INC . 'wp-special'.DS.'wp-upgrader-skin.php';

        // based on the plugin there is a different title
        switch($package_url){
            case 'wysija-newsletters/index.php':
                $title=__('Downloading Wysija',WYSIJA);
                break;
            case 'wysija-newsletters-premium/index.php':
                $title=__('Downloading Wysija Premium',WYSIJA);
                break;
        }

        $upgrader = new Plugin_Upgrader( new WysijaPlugin_Upgrader_Skin( compact('title', 'url', 'nonce', 'plugin', 'api') ));

        $response=$upgrader->upgrade($package_url);
    }