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


PHP WP_Upgrader::init方法代码示例

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


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

示例1: install_remote_file

 public function install_remote_file($params)
 {
     global $wp_filesystem;
     extract($params);
     if (!isset($package) || empty($package)) {
         return array('error' => '<p>No files received. Internal error.</p>');
     }
     if (!$this->is_server_writable()) {
         return array('error' => 'Failed, please <a target="_blank" href="http://managewp.com/user-guide/faq/my-pluginsthemes-fail-to-update-or-i-receive-a-yellow-ftp-warning">add FTP details</a>');
     }
     if (defined('WP_INSTALLING') && file_exists(ABSPATH . '.maintenance')) {
         return array('error' => '<p>Site under maintanace.</p>');
     }
     if (!class_exists('WP_Upgrader')) {
         include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     }
     /** @handled class */
     $upgrader = new WP_Upgrader(mwp_container()->getUpdaterSkin());
     $upgrader->init();
     $destination = $type == 'themes' ? WP_CONTENT_DIR . '/themes' : WP_PLUGIN_DIR;
     $clear_destination = isset($clear_destination) ? $clear_destination : false;
     foreach ($package as $package_url) {
         $key = basename($package_url);
         $install_info[$key] = @$upgrader->run(array('package' => $package_url, 'destination' => $destination, 'clear_destination' => $clear_destination, 'clear_working' => true, 'hook_extra' => array()));
     }
     if ($activate) {
         if ($type == 'plugins') {
             include_once ABSPATH . 'wp-admin/includes/plugin.php';
             $all_plugins = get_plugins();
             foreach ($all_plugins as $plugin_slug => $plugin) {
                 $plugin_dir = preg_split('/\\//', $plugin_slug);
                 foreach ($install_info as $key => $install) {
                     if (!$install || is_wp_error($install)) {
                         continue;
                     }
                     if ($install['destination_name'] == $plugin_dir[0]) {
                         $install_info[$key]['activated'] = activate_plugin($plugin_slug, '', false);
                     }
                 }
             }
         } else {
             if (count($install_info) == 1) {
                 global $wp_themes;
                 include_once ABSPATH . 'wp-includes/theme.php';
                 $wp_themes = null;
                 unset($wp_themes);
                 //prevent theme data caching
                 if (function_exists('wp_get_themes')) {
                     $all_themes = wp_get_themes();
                     foreach ($all_themes as $theme_name => $theme_data) {
                         foreach ($install_info as $key => $install) {
                             if (!$install || is_wp_error($install)) {
                                 continue;
                             }
                             if ($theme_data->Template == $install['destination_name']) {
                                 $install_info[$key]['activated'] = switch_theme($theme_data->Template, $theme_data->Stylesheet);
                             }
                         }
                     }
                 } else {
                     $all_themes = get_themes();
                     foreach ($all_themes as $theme_name => $theme_data) {
                         foreach ($install_info as $key => $install) {
                             if (!$install || is_wp_error($install)) {
                                 continue;
                             }
                             if ($theme_data['Template'] == $install['destination_name']) {
                                 $install_info[$key]['activated'] = switch_theme($theme_data['Template'], $theme_data['Stylesheet']);
                             }
                         }
                     }
                 }
             }
         }
     }
     // Can generate "E_NOTICE: ob_clean(): failed to delete buffer. No buffer to delete."
     @ob_clean();
     $this->mmb_maintenance_mode(false);
     if (mwp_container()->getRequestStack()->getMasterRequest()->getProtocol() >= 1) {
         // WP_Error won't get JSON encoded, so unwrap the error here.
         foreach ($install_info as $key => $value) {
             if ($value instanceof WP_Error) {
                 $install_info[$key] = array('error' => $value->get_error_message(), 'code' => $value->get_error_code());
             }
         }
     }
     return $install_info;
 }
开发者ID:onedaylabs,项目名称:onedaylabs.com,代码行数:88,代码来源:Installer.php


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