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


PHP WP_Upgrader::install_package方法代码示例

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


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

示例1: learn_press_install_add_on

/**
 * Install a plugin
 *
 * @param string $plugin_name
 * @return array
 */
function learn_press_install_add_on($plugin_name)
{
    require_once LPR_PLUGIN_PATH . '/inc/admin/class-lpr-upgrader.php';
    $upgrader = new LPR_Upgrader();
    global $wp_filesystem;
    $response = array();
    $package = 'http://thimpress.com/lprepo/' . $plugin_name . '.zip';
    $package = $upgrader->download_package($package);
    if (is_wp_error($package)) {
        $response['error'] = $package;
    } else {
        $working_dir = $upgrader->unpack_package($package, true, $plugin_name);
        if (is_wp_error($working_dir)) {
            $response['error'] = $working_dir;
        } else {
            $wp_upgrader = new WP_Upgrader();
            $options = array('source' => $working_dir, 'destination' => WP_PLUGIN_DIR, 'clear_destination' => false, 'clear_working' => true, 'hook_extra' => array('type' => 'plugin', 'action' => 'install'));
            //$response = array();
            $result = $wp_upgrader->install_package($options);
            if (is_wp_error($result)) {
                $response['error'] = $result;
            } else {
                $response = $result;
                $response['text'] = __('Installed');
            }
        }
    }
    return $response;
}
开发者ID:arshanam,项目名称:LearnPress,代码行数:35,代码来源:lpr-admin-functions.php

示例2: background_installer

 /**
  * Install a plugin from .org in the background via a cron job (used by
  * installer - opt in).
  * @param string $plugin_to_install_id
  * @param array $plugin_to_install
  * @since 2.6.0
  */
 public static function background_installer($plugin_to_install_id, $plugin_to_install)
 {
     if (!empty($plugin_to_install['repo-slug'])) {
         require_once ABSPATH . 'wp-admin/includes/file.php';
         require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
         require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
         require_once ABSPATH . 'wp-admin/includes/plugin.php';
         WP_Filesystem();
         $skin = new Automatic_Upgrader_Skin();
         $upgrader = new WP_Upgrader($skin);
         $installed_plugins = array_map(array(__CLASS__, 'format_plugin_slug'), array_keys(get_plugins()));
         $plugin_slug = $plugin_to_install['repo-slug'];
         $plugin = $plugin_slug . '/' . $plugin_slug . '.php';
         $installed = false;
         $activate = false;
         // See if the plugin is installed already
         if (in_array($plugin_to_install['repo-slug'], $installed_plugins)) {
             $installed = true;
             $activate = !is_plugin_active($plugin);
         }
         // Install this thing!
         if (!$installed) {
             // Suppress feedback
             ob_start();
             try {
                 $plugin_information = plugins_api('plugin_information', array('slug' => $plugin_to_install['repo-slug'], 'fields' => array('short_description' => false, 'sections' => false, 'requires' => false, 'rating' => false, 'ratings' => false, 'downloaded' => false, 'last_updated' => false, 'added' => false, 'tags' => false, 'homepage' => false, 'donate_link' => false, 'author_profile' => false, 'author' => false)));
                 if (is_wp_error($plugin_information)) {
                     throw new Exception($plugin_information->get_error_message());
                 }
                 $package = $plugin_information->download_link;
                 $download = $upgrader->download_package($package);
                 if (is_wp_error($download)) {
                     throw new Exception($download->get_error_message());
                 }
                 $working_dir = $upgrader->unpack_package($download, true);
                 if (is_wp_error($working_dir)) {
                     throw new Exception($working_dir->get_error_message());
                 }
                 $result = $upgrader->install_package(array('source' => $working_dir, 'destination' => WP_PLUGIN_DIR, 'clear_destination' => false, 'abort_if_destination_exists' => false, 'clear_working' => true, 'hook_extra' => array('type' => 'plugin', 'action' => 'install')));
                 if (is_wp_error($result)) {
                     throw new Exception($result->get_error_message());
                 }
                 $activate = true;
             } catch (Exception $e) {
                 WC_Admin_Notices::add_custom_notice($plugin_to_install_id . '_install_error', sprintf(__('%1$s could not be installed (%2$s). <a href="%3$s">Please install it manually by clicking here.</a>', 'woocommerce'), $plugin_to_install['name'], $e->getMessage(), esc_url(admin_url('index.php?wc-install-plugin-redirect=' . $plugin_to_install['repo-slug']))));
             }
             // Discard feedback
             ob_end_clean();
         }
         wp_clean_plugins_cache();
         // Activate this thing
         if ($activate) {
             try {
                 $result = activate_plugin($plugin);
                 if (is_wp_error($result)) {
                     throw new Exception($result->get_error_message());
                 }
             } catch (Exception $e) {
                 WC_Admin_Notices::add_custom_notice($plugin_to_install_id . '_install_error', sprintf(__('%1$s was installed but could not be activated. <a href="%2$s">Please activate it manually by clicking here.</a>', 'woocommerce'), $plugin_to_install['name'], admin_url('plugins.php')));
             }
         }
     }
 }
开发者ID:woocommerce,项目名称:woocommerce,代码行数:70,代码来源:class-wc-install.php

示例3: install_marketpress_dashboard

 /**
  * Downloads the MarketPress Dashboard
  *
  * @since	0.1
  * @uses	WP_Upgrader, wp_safe_redirect, admin_url
  * @return	void
  */
 public function install_marketpress_dashboard()
 {
     // Download
     $package = 'http://marketpress.com/mpdash.zip';
     $upgrader = new WP_Upgrader(new AU_Install_Skin());
     // File System Connect
     $res = $upgrader->fs_connect(array(WP_CONTENT_DIR, WP_PLUGIN_DIR));
     // Download Package
     $download = $upgrader->download_package($package);
     // Don't delete local files
     $delete_package = $download != $package;
     // Unpack the package
     $working_dir = $upgrader->unpack_package($download, $delete_package);
     // Install the package
     $result = $upgrader->install_package(array('source' => $working_dir, 'destination' => WP_PLUGIN_DIR, 'clear_destination' => FALSE, 'clear_working' => TRUE, 'hook_extra' => array()));
     // Redirect
     wp_safe_redirect(network_admin_url('plugins.php?message=marketpress_installed'));
 }
开发者ID:m-godefroid76,项目名称:devrestofactory,代码行数:25,代码来源:class-Multilingual_Press_Auto_Update.php


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