当前位置: 首页>>代码示例>>PHP>>正文


PHP Plugin_Upgrader::install方法代码示例

本文整理汇总了PHP中Plugin_Upgrader::install方法的典型用法代码示例。如果您正苦于以下问题:PHP Plugin_Upgrader::install方法的具体用法?PHP Plugin_Upgrader::install怎么用?PHP Plugin_Upgrader::install使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Plugin_Upgrader的用法示例。


在下文中一共展示了Plugin_Upgrader::install方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: install

 protected function install()
 {
     foreach ($this->plugins as $index => $slug) {
         $skin = new Jetpack_Automatic_Install_Skin();
         $upgrader = new Plugin_Upgrader($skin);
         $zip_url = self::generate_wordpress_org_plugin_download_link($slug);
         $result = $upgrader->install($zip_url);
         if (!$this->bulk && is_wp_error($result)) {
             return $result;
         }
         $plugin = self::get_plugin_id_by_slug($slug);
         $error_code = 'install_error';
         if (!$plugin) {
             $error = $this->log[$slug]['error'] = __('There was an error installing your plugin', 'jetpack');
         }
         if (!$this->bulk && !$result) {
             $error_code = $upgrader->skin->get_main_error_code();
             $message = $upgrader->skin->get_main_error_message();
             $error = $this->log[$slug]['error'] = $message ? $message : __('An unknown error occurred during installation', 'jetpack');
         }
         $this->log[$plugin][] = $upgrader->skin->get_upgrade_messages();
     }
     if (!$this->bulk && isset($error)) {
         if ('download_failed' === $error_code) {
             // For backwards compatibility: versions prior to 3.9 would return no_package instead of download_failed.
             $error_code = 'no_package';
         }
         return new WP_Error($error_code, $this->log[$slug]['error'], 400);
     }
     // replace the slug with the actual plugin id
     $this->plugins[$index] = $plugin;
     return true;
 }
开发者ID:automattic,项目名称:jetpack,代码行数:33,代码来源:class.jetpack-json-api-plugins-install-endpoint.php

示例2: rtbiz_install_plugin

 public function rtbiz_install_plugin($plugin_slug)
 {
     include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
     $api = plugins_api('plugin_information', array('slug' => $plugin_slug, 'fields' => array('sections' => false)));
     if (is_wp_error($api)) {
         die(sprintf(__('ERROR: Error fetching plugin information: %s', RTBIZ_TEXT_DOMAIN), $api->get_error_message()));
     }
     if (!class_exists('Plugin_Upgrader')) {
         require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     }
     if (!class_exists('Rtbiz_Plugin_Upgrader_Skin')) {
         require_once RTBIZ_PATH . 'admin/abstract/class-rtbiz-plugin-upgrader-skin.php';
     }
     $upgrader = new Plugin_Upgrader(new Rtbiz_Plugin_Upgrader_Skin(array('nonce' => 'install-plugin_' . $plugin_slug, 'plugin' => $plugin_slug, 'api' => $api)));
     $install_result = $upgrader->install($api->download_link);
     if (!$install_result || is_wp_error($install_result)) {
         // $install_result can be false if the file system isn't writeable.
         $error_message = __('Please ensure the file system is writeable', RTBIZ_TEXT_DOMAIN);
         if (is_wp_error($install_result)) {
             $error_message = $install_result->get_error_message();
         }
         die(sprintf(__('ERROR: Failed to install plugin: %s', RTBIZ_TEXT_DOMAIN), $error_message));
     }
     $activate_result = activate_plugin($this->rtbiz_get_path_for_plugin($plugin_slug));
     if (is_wp_error($activate_result)) {
         die(sprintf(__('ERROR: Failed to activate plugin: %s', RTBIZ_TEXT_DOMAIN), $activate_result->get_error_message()));
     }
 }
开发者ID:chandra-patel,项目名称:rtbiz,代码行数:28,代码来源:class-rtbiz-plugin-check.php

示例3: install

 protected function install()
 {
     foreach ($this->plugins as $index => $slug) {
         $skin = new Automatic_Upgrader_Skin();
         $upgrader = new Plugin_Upgrader($skin);
         $result = $upgrader->install($this->download_links[$slug]);
         if (!$this->bulk && is_wp_error($result)) {
             return $result;
         }
         $plugin = $this::get_plugin_id_by_slug($slug);
         if (!$plugin) {
             $error = $this->log[$slug]['error'] = __('There was an error installing your plugin', 'jetpack');
         }
         if (!$this->bulk && !$result) {
             $error = $this->log[$slug]['error'] = __('An unknown error occurred during installation', 'jetpack');
         }
         $this->log[$plugin][] = $upgrader->skin->get_upgrade_messages();
     }
     if (!$this->bulk && isset($error)) {
         return new WP_Error('install_error', $this->log[$slug]['error'], 400);
     }
     // replace the slug with the actual plugin id
     $this->plugins[$index] = $plugin;
     return true;
 }
开发者ID:sdh100shaun,项目名称:pantheon,代码行数:25,代码来源:class.jetpack-json-api-plugins-install-endpoint.php

示例4: elseif

 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');
         }
     }
 }
开发者ID:linniepinski,项目名称:perssistant,代码行数:35,代码来源:mpi-Class.php

示例5: explode

 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();
     }
 }
开发者ID:voomco,项目名称:WordPress,代码行数:53,代码来源:extend.php

示例6: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $env = Validators::validateEnv($input->getOption('env'));
     $root = $this->skeleton->getWebRoot();
     $plugins = $this->skeleton->get(sprintf('wordpress.%s.plugins', $env));
     require $root . '/wp-load.php';
     require ABSPATH . 'wp-admin/includes/admin.php';
     require ABSPATH . 'wp-admin/includes/plugin-install.php';
     foreach ($plugins as $slug => $version) {
         $plugin = plugins_api('plugin_information', array('slug' => $slug));
         if (is_wp_error($plugin)) {
             throw new \Exception('Could not get plugin information for ' . $slug);
         }
         if ($version) {
             list($prefix) = explode($slug, $plugin->download_link);
             $link = sprintf('%s%s.%s.zip', $prefix, $slug, $version);
             $response = wp_remote_head($link);
             if (!isset($response['response']['code']) || $response['response']['code'] != 200) {
                 throw new \Exception('Unable to verify ' . $link);
             }
             $plugin->download_link = $link;
             $plugin->version = $version;
         }
         require ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
         $status = install_plugin_install_status($plugin);
         $upgrader = new \Plugin_Upgrader(new UpgraderSkin($output));
         $current = current(get_plugins("/{$slug}"));
         switch ($status['status']) {
             case 'install':
                 $output->write(sprintf('Installing <info>%s</info> v<comment>%s</comment>', $plugin->name, $plugin->version));
                 $upgrader->install($plugin->download_link);
                 break;
             case 'update_available':
                 if ($plugin->version == $current['Version']) {
                     $output->writeln(sprintf('<info>%s</info> v<comment>%s</comment> is already installed!', $plugin->name, $plugin->version));
                 } else {
                     $output->write(sprintf('Upgrading <info>%s</info> from <comment>%s</comment> to <comment>%s</comment>', $plugin->name, $current['Version'], $plugin->version));
                     $file = sprintf('%s/%s', $slug, key(get_plugins("/{$slug}")));
                     $upgrader->upgrade($file);
                 }
                 break;
             case 'latest_installed':
                 $output->writeln(sprintf('<info>%s</info> v<comment>%s</comment> is already installed!', $plugin->name, $current['Version']));
                 break;
             case 'newer_installed':
                 $output->writeln(sprintf('<info>%s</info> v<comment>%s</comment> is installed & newer than <comment>%s</comment>', $plugin->name, $current['Version'], $plugin->version));
                 break;
         }
     }
     if ($plugins) {
         $output->writeln(sprintf('<info>Activate plugins in the WordPress Admin</info>', $plugin->name));
     }
 }
开发者ID:ericclemmons,项目名称:wordpress-generator,代码行数:53,代码来源:InstallPluginsWordPressCommand.php

示例7: array

 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);
 }
开发者ID:iamtakashi,项目名称:jetpack,代码行数:12,代码来源:test_class.jetpack-sync-plugins.php

示例8: siteorigin_plugin_activation_do_plugin_install

/**
 * Install a plugin
 */
function siteorigin_plugin_activation_do_plugin_install()
{
    /** All plugin information will be stored in an array for processing */
    $plugin = array();
    /** Checks for actions from hover links to process the installation */
    if (isset($_GET[sanitize_key('plugin')]) && (isset($_GET[sanitize_key('siteorigin-pa-install')]) && 'install-plugin' == $_GET[sanitize_key('siteorigin-pa-install')]) && current_user_can('install_plugins')) {
        check_admin_referer('siteorigin-pa-install');
        $plugin['name'] = $_GET['plugin_name'];
        // Plugin name
        $plugin['slug'] = $_GET['plugin'];
        // Plugin slug
        if (!empty($_GET['plugin_source'])) {
            $plugin['source'] = $_GET['plugin_source'];
        } else {
            $plugin['source'] = false;
        }
        /** Pass all necessary information via URL if WP_Filesystem is needed */
        $url = wp_nonce_url(add_query_arg(array('page' => 'siteorigin_plugin_activation', 'plugin' => $plugin['slug'], 'plugin_name' => $plugin['name'], 'plugin_source' => $plugin['source'], 'siteorigin-pa-install' => 'install-plugin'), admin_url('themes.php')), 'siteorigin-pa-install');
        $method = '';
        // Leave blank so WP_Filesystem can populate it as necessary
        $fields = array(sanitize_key('siteorigin-pa-install'));
        // Extra fields to pass to WP_Filesystem
        if (false === ($creds = request_filesystem_credentials($url, $method, false, false, $fields))) {
            return true;
        }
        if (!WP_Filesystem($creds)) {
            request_filesystem_credentials($url, $method, true, false, $fields);
            // Setup WP_Filesystem
            return true;
        }
        require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
        // Need for plugins_api
        require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
        // Need for upgrade classes
        /** Prep variables for Plugin_Installer_Skin class */
        $title = sprintf(__('Installing %s', 'vantage'), $plugin['name']);
        $url = add_query_arg(array('action' => 'install-plugin', 'plugin' => $plugin['slug']), 'update.php');
        if (isset($_GET['from'])) {
            $url .= add_query_arg('from', urlencode(stripslashes($_GET['from'])), $url);
        }
        $nonce = 'install-plugin_' . $plugin['slug'];
        // Find the source of the plugin
        $source = !empty($plugin['source']) ? $plugin['source'] : 'http://downloads.wordpress.org/plugin/' . urlencode($plugin['slug']) . '.zip';
        /** Create a new instance of Plugin_Upgrader */
        $upgrader = new Plugin_Upgrader($skin = new Plugin_Installer_Skin(compact('type', 'title', 'url', 'nonce', 'plugin', 'api')));
        /** Perform the action and install the plugin from the $source urldecode() */
        $upgrader->install($source);
        /** Flush plugins cache so we can make sure that the installed plugins list is always up to date */
        wp_cache_flush();
    }
}
开发者ID:CUPolishSociety,项目名称:campolsoc,代码行数:54,代码来源:plugin-activation.php

示例9: installAddon

 /**
  * @usage Single click add-on install
  */
 function installAddon()
 {
     if (isset($_POST['updateurl']) && current_user_can(WPDM_ADMIN_CAP)) {
         include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
         include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
         $upgrader = new \Plugin_Upgrader(new \Plugin_Installer_Skin(compact('title', 'url', 'nonce', 'plugin', 'api')));
         $downloadlink = $_POST['updateurl'] . '&preact=login&user=' . get_option('__wpdm_suname') . '&pass=' . get_option('__wpdm_supass');
         $upgrader->install($downloadlink);
         $plugininfo = wpdm_plugin_data($_POST['plugin']);
         if (file_exists(dirname(WPDM_BASE_DIR) . '/' . $plugininfo['plugin_index_file'])) {
             activate_plugin($plugininfo['plugin_index_file']);
         }
         die("Installed Successfully");
     } else {
         die("Only site admin is authorized to install add-on");
     }
 }
开发者ID:wilxsv,项目名称:prevensionPublicLibrary,代码行数:20,代码来源:class.WordPressDownloadManagerAdmin.php

示例10: download_plugin

 /**
  * Install plugin from a URL.
  *
  * A mix of install-plugin and upload-plugin actions from wp-admin/update.php:93.
  */
 public function download_plugin()
 {
     if (!current_user_can('upload_plugins')) {
         wp_die(__('You do not have sufficient permissions to install plugins on this site.'));
     }
     check_admin_referer('plugin-download');
     require_once ABSPATH . 'wp-admin/admin-header.php';
     $download_url = esc_url_raw($_REQUEST['pluginurl']);
     // Remove "-master" from GitHub URL-s
     if (false !== strstr($download_url, '//github.com/')) {
         add_filter('upgrader_source_selection', array($this, 'remove_github_master'), 9, 3);
     }
     $type = 'web';
     $title = sprintf(__('Installing Plugin from URL: %s'), esc_html($download_url));
     $url = 'update.php?action=install-plugin';
     $nonce = 'plugin-download';
     $upgrader = new Plugin_Upgrader(new Plugin_Installer_Skin(compact('type', 'title', 'url', 'nonce')));
     $upgrader->install($download_url);
     include ABSPATH . 'wp-admin/admin-footer.php';
 }
开发者ID:vrkansagara,项目名称:wordpress-plugin-construction,代码行数:25,代码来源:plugin-upload-from-url.php

示例11: install

 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');
 }
开发者ID:automattic,项目名称:jetpack,代码行数:40,代码来源:class.jetpack-json-api-plugins-new-endpoint.php

示例12:

 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;
             }
         }
     }
 }
开发者ID:87surendra,项目名称:mbr,代码行数:23,代码来源:plugin-central.class.php

示例13: install

 /**
  * Install GHU
  */
 function install()
 {
     add_filter('upgrader_source_selection', array($this, 'upgrader_source_selection'), 10, 2);
     $skin = new IGU_Plugin_Installer_Skin(array('type' => 'plugin', 'nonce' => wp_nonce_url($this->zip)));
     $upgrader = new Plugin_Upgrader($skin);
     $result = $upgrader->install($this->zip);
     if (is_wp_error($result)) {
         return array('status' => 'error', 'message' => $result->get_error_message());
     }
     wp_cache_flush();
     $result = $this->activate();
     if ('error' == $result['status']) {
         return $result;
     }
     return array('status' => 'ok', 'message' => __('GitHub Updater has been installed and activated.'));
 }
开发者ID:deviodigital,项目名称:install-github-updater,代码行数:19,代码来源:install-github-updater.php

示例14: sprintf

                echo sprintf(__('Please contact your administrator (%1s) to activate the plugin "Maps Marker Pro".', 'lmm'), '<a href="mailto:' . get_bloginfo('admin_email') . '?subject=' . esc_attr__('Please activate the plugin "Maps Marker Pro"', 'lmm') . '">' . get_bloginfo('admin_email') . '</a>');
            }
        }
    }
} else {
    if (!wp_verify_nonce($_POST['_wpnonce'], 'pro-upgrade-nonce')) {
        wp_die('<br/>' . __('Security check failed - please call this function from the according admin page!', 'lmm') . '');
    }
    if ($action == 'upgrade_to_pro_version') {
        include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
        add_filter('https_ssl_verify', '__return_false');
        //info: otherwise SSL error on localhost installs.
        add_filter('https_local_ssl_verify', '__return_false');
        //info: not sure if needed, added to be sure
        $upgrader = new Plugin_Upgrader(new Plugin_Upgrader_Skin());
        $dl = 'https://www.mapsmarker.com/upgrade-pro';
        $upgrader->install($dl);
        //info: check if download was successful
        $lmm_pro_readme = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'leaflet-maps-marker-pro' . DIRECTORY_SEPARATOR . 'readme.txt';
        if (file_exists($lmm_pro_readme)) {
            echo '<p>' . __('Please activate the plugin by clicking the link above', 'lmm') . '</p>';
        } else {
            $dl_l = 'https://www.mapsmarker.com/upgrade-pro';
            $dl_lt = 'www.mapsmarker.com/upgrade-pro';
            echo '<p>' . sprintf(__('The pro plugin package could not be downloaded automatically. Please download the plugin from <a href="%1s">%2s</a> and upload it to the directory /wp-content/plugins on your server manually', 'lmm'), $dl_l, $dl_lt) . '</p>';
        }
    }
}
?>
</div>
<!--wrap-->
开发者ID:jonpetersen,项目名称:PHTC,代码行数:31,代码来源:leaflet-pro-upgrade.php

示例15: do_plugin_install

 /**
  * 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
//.........这里部分代码省略.........
开发者ID:newmight2015,项目名称:psmpsm,代码行数:101,代码来源:class-tgm-plugin-activation.php


注:本文中的Plugin_Upgrader::install方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。