當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。