/**
 * 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');
}
 /**
  * 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';
 }
 /**
  * @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']));
         }
     }
 }
 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;
 }
 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()));
     }
 }
Example #6
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 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;
 }
Example #8
0
 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&amp;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');
         }
     }
 }
Example #9
0
/**
 * 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;
}
 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));
     }
 }
Example #11
0
 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();
     }
 }
 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);
 }
/**
 * 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();
    }
}
 function install_package($args = array())
 {
     parent::upgrade_strings();
     // needed for the 'remove_old' string
     $args['clear_destination'] = true;
     $args['abort_if_destination_exists'] = false;
     return parent::install_package($args);
 }
 /**
  * @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='******'__wpdm_suname') . '&pass='******'__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");
     }
 }
Example #16
0
 function download_package($package)
 {
     $package = $this->getDownloadUrl();
     if (is_wp_error($package)) {
         return $package;
     }
     return parent::download_package($package);
 }
 /**
  * If a requested theme/plugin is from wordpress.org -OR- from us, let it through
  * @param array $options
  */
 public function run($options)
 {
     $_options = get_option('gd_quicksetup_options');
     if (preg_match('/(?:(\\.)?wordpress\\.org|' . preg_quote(parse_url($_options['api_url'], PHP_URL_HOST)) . ')$/', parse_url($options['package'], PHP_URL_HOST))) {
         // Some older servers don't have our SSL certs in their bundle
         add_filter('https_ssl_verify', '__return_false');
         parent::run($options);
         remove_filter('https_local_ssl_verify', '__return_false');
     }
 }
 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;
 }
 function install()
 {
     $args = $this->input();
     if (isset($args['zip'][0]['id'])) {
         $plugin_attachment_id = $args['zip'][0]['id'];
         $local_file = get_attached_file($plugin_attachment_id);
         if (!$local_file) {
             return new WP_Error('local-file-does-not-exist');
         }
         $skin = new Jetpack_Automatic_Install_Skin();
         $upgrader = new Plugin_Upgrader($skin);
         $pre_install_plugin_list = get_plugins();
         $result = $upgrader->install($local_file);
         // clean up.
         wp_delete_attachment($plugin_attachment_id, true);
         if (is_wp_error($result)) {
             return $result;
         }
         $after_install_plugin_list = get_plugins();
         $plugin = array_values(array_diff(array_keys($after_install_plugin_list), array_keys($pre_install_plugin_list)));
         if (!$result) {
             $error_code = $upgrader->skin->get_main_error_code();
             $message = $upgrader->skin->get_main_error_message();
             if (empty($message)) {
                 $message = __('An unknown error occurred during installation', 'jetpack');
             }
             if ('download_failed' === $error_code) {
                 $error_code = 'no_package';
             }
             return new WP_Error($error_code, $message, 400);
         }
         if (empty($plugin)) {
             return new WP_Error('plugin_already_installed');
         }
         $this->plugins = $plugin;
         $this->log[$plugin[0]] = $upgrader->skin->get_upgrade_messages();
         return true;
     }
     return new WP_Error('no_plugin_installed');
 }
Example #20
0
 function handle_download($plugin_name, $package)
 {
     global $wp_version;
     if (version_compare($wp_version, '2.8', '<')) {
         $this->update_plugin_advanced($plugin_name, $package);
     } else {
         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&amp;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);
             if (!$upgrader->plugin_info()) {
                 echo $res;
             }
         }
     }
 }
Example #21
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';
 }
Example #22
0
 public static function updateFromZip($fileRaw, $updateInfo)
 {
     N2Loader::import('libraries.zip.zip_read');
     $tmpHandle = tmpfile();
     fwrite($tmpHandle, $fileRaw);
     $metaData = stream_get_meta_data($tmpHandle);
     $tmpFilename = $metaData['uri'];
     $_GET['plugins'] = $updateInfo['plugin'];
     include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     $upgrader = new Plugin_Upgrader(new Plugin_Upgrader_Skin(compact('title', 'nonce', 'url', 'plugin')));
     $upgrader->init();
     $upgrader->upgrade_strings();
     add_filter('upgrader_pre_install', array($upgrader, 'deactivate_plugin_before_upgrade'), 10, 2);
     add_filter('upgrader_clear_destination', array($upgrader, 'delete_old_plugin'), 10, 4);
     $upgrader->run(array('package' => $tmpFilename, 'destination' => WP_PLUGIN_DIR, 'clear_destination' => true, 'clear_working' => true, 'hook_extra' => array('plugin' => $updateInfo['plugin'], 'type' => 'plugin', 'action' => 'update')));
     // Cleanup our hooks, in case something else does a upgrade on this connection.
     remove_filter('upgrader_pre_install', array($upgrader, 'deactivate_plugin_before_upgrade'));
     remove_filter('upgrader_clear_destination', array($upgrader, 'delete_old_plugin'));
     // Force refresh of plugin update information
     wp_clean_plugins_cache(true);
     fclose($tmpHandle);
     include ABSPATH . 'wp-admin/admin-footer.php';
     return true;
 }
Example #23
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);
}
 /**
  * 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;
 }
Example #25
0
/**
 * AJAX handler for updating a plugin.
 *
 * @since 4.2.0
 *
 * @see Plugin_Upgrader
 */
function wp_ajax_update_plugin()
{
    global $wp_filesystem;
    $plugin = urldecode($_POST['plugin']);
    $status = array('update' => 'plugin', 'plugin' => $plugin, 'slug' => sanitize_key($_POST['slug']), 'oldVersion' => '', 'newVersion' => '');
    $plugin_data = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin);
    if ($plugin_data['Version']) {
        $status['oldVersion'] = sprintf(__('Version %s'), $plugin_data['Version']);
    }
    if (!current_user_can('update_plugins')) {
        $status['error'] = __('You do not have sufficient permissions to update plugins for this site.');
        wp_send_json_error($status);
    }
    check_ajax_referer('updates');
    include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    wp_update_plugins();
    $skin = new Automatic_Upgrader_Skin();
    $upgrader = new Plugin_Upgrader($skin);
    $result = $upgrader->bulk_upgrade(array($plugin));
    if (is_array($result) && empty($result[$plugin]) && is_wp_error($skin->result)) {
        $result = $skin->result;
    }
    if (is_array($result) && !empty($result[$plugin])) {
        $plugin_update_data = current($result);
        /*
         * If the `update_plugins` site transient is empty (e.g. when you update
         * two plugins in quick succession before the transient repopulates),
         * this may be the return.
         *
         * Preferably something can be done to ensure `update_plugins` isn't empty.
         * For now, surface some sort of error here.
         */
        if ($plugin_update_data === true) {
            $status['error'] = __('Plugin update failed.');
            wp_send_json_error($status);
        }
        $plugin_data = get_plugins('/' . $result[$plugin]['destination_name']);
        $plugin_data = reset($plugin_data);
        if ($plugin_data['Version']) {
            $status['newVersion'] = sprintf(__('Version %s'), $plugin_data['Version']);
        }
        wp_send_json_success($status);
    } else {
        if (is_wp_error($result)) {
            $status['error'] = $result->get_error_message();
            wp_send_json_error($status);
        } else {
            if (is_bool($result) && !$result) {
                $status['errorCode'] = 'unable_to_connect_to_filesystem';
                $status['error'] = __('Unable to connect to the filesystem. Please confirm your credentials.');
                // Pass through the error from WP_Filesystem if one was raised
                if (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
                    $status['error'] = $wp_filesystem->errors->get_error_message();
                }
                wp_send_json_error($status);
            } else {
                // An unhandled error occured
                $status['error'] = __('Plugin update failed.');
                wp_send_json_error($status);
            }
        }
    }
}
 /**
  * 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'])) {
         check_admin_referer('tgmpa-install');
         $plugin['name'] = $_GET['plugin_name'];
         // Plugin name. // @todo needs sanitizing, figure out how
         $plugin['slug'] = sanitize_title($_GET['plugin']);
         // Plugin slug.
         $plugin['source'] = $_GET['plugin_source'];
         // Plugin source. // @todo needs sanitizing, figure out how
         // 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 (WP_DEBUG === true) {
                     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');
         if (isset($_GET['from'])) {
             $url .= add_query_arg('from', urlencode(stripslashes($_GET['from'])), $url);
         }
         $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($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();
         // 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('themes.php'))), '" 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 = array();
         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[] = $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(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'];
         // @todo needs sanitizing, figure out how
         $plugin['slug'] = sanitize_title($_GET['plugin']);
         $plugin['source'] = $_GET['plugin_source'];
         // @todo needs sanitizing, figure out how
         $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;
 }
Example #27
0
 } elseif ('upload-plugin' == $action) {
     if (!current_user_can('upload_plugins')) {
         wp_die(__('You do not have sufficient permissions to install plugins on this site.'));
     }
     check_admin_referer('plugin-upload');
     $file_upload = new File_Upload_Upgrader('pluginzip', 'package');
     $title = __('Upload Plugin');
     $parent_file = 'plugins.php';
     $submenu_file = 'plugin-install.php';
     require_once ABSPATH . 'wp-admin/admin-header.php';
     $title = sprintf(__('Installing Plugin from uploaded file: %s'), esc_html(basename($file_upload->filename)));
     $nonce = 'plugin-upload';
     $url = add_query_arg(array('package' => $file_upload->id), 'update.php?action=upload-plugin');
     $type = 'upload';
     //Install plugin type, From Web or an Upload.
     $upgrader = new Plugin_Upgrader(new Plugin_Installer_Skin(compact('type', 'title', 'nonce', 'url')));
     $result = $upgrader->install($file_upload->package);
     if ($result || is_wp_error($result)) {
         $file_upload->cleanup();
     }
     include ABSPATH . 'wp-admin/admin-footer.php';
 } elseif ('upgrade-theme' == $action) {
     if (!current_user_can('update_themes')) {
         wp_die(__('You do not have sufficient permissions to update themes for this site.'));
     }
     check_admin_referer('upgrade-theme_' . $theme);
     wp_enqueue_script('customize-loader');
     wp_enqueue_script('updates');
     $title = __('Update Theme');
     $parent_file = 'themes.php';
     $submenu_file = 'themes.php';
Example #28
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';
    }
}
Example #29
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;
 }
Example #30
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);
}