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


PHP WP_Upgrader::run方法代码示例

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


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

示例1: installPlugin

 public static function installPlugin($url, $activatePlugin = false)
 {
     $hasWPFileSystem = MainWP_Utility::getWPFilesystem();
     /** @global WP_Filesystem_Base $wp_filesystem */
     global $wp_filesystem;
     if (file_exists(ABSPATH . '/wp-admin/includes/screen.php')) {
         include_once ABSPATH . '/wp-admin/includes/screen.php';
     }
     include_once ABSPATH . '/wp-admin/includes/template.php';
     include_once ABSPATH . '/wp-admin/includes/misc.php';
     include_once ABSPATH . '/wp-admin/includes/class-wp-upgrader.php';
     include_once ABSPATH . '/wp-admin/includes/plugin.php';
     $installer = new WP_Upgrader();
     $ssl_verifyhost = get_option('mainwp_sslVerifyCertificate');
     $ssl_api_verifyhost = get_option('mainwp_api_sslVerifyCertificate') === false || get_option('mainwp_api_sslVerifyCertificate') == 1 ? 1 : 0;
     if ($ssl_verifyhost === '0' || $ssl_api_verifyhost == 0) {
         add_filter('http_request_args', array(MainWP_Extensions::getClassName(), 'noSSLFilterFunction'), 99, 2);
     }
     add_filter('http_request_args', array(MainWP_Extensions::getClassName(), 'http_request_reject_unsafe_urls'), 99, 2);
     $result = $installer->run(array('package' => $url, 'destination' => WP_PLUGIN_DIR, 'clear_destination' => false, 'clear_working' => true, 'hook_extra' => array()));
     remove_filter('http_request_args', array(MainWP_Extensions::getClassName(), 'http_request_reject_unsafe_urls'), 99, 2);
     if ($ssl_verifyhost === '0') {
         remove_filter('http_request_args', array(MainWP_Extensions::getClassName(), 'noSSLFilterFunction'), 99);
     }
     $error = $output = $plugin_slug = null;
     if (is_wp_error($result)) {
         $error = $result->get_error_codes();
         if (is_array($error)) {
             if ($error[0] == 'folder_exists') {
                 $error = __('Destination folder already exists.', 'mainwp');
             } else {
                 $error = implode(', ', $error);
             }
         }
     } else {
         $path = $result['destination'];
         foreach ($result['source_files'] as $srcFile) {
             // to fix bug
             if ($srcFile == 'readme.txt') {
                 continue;
             }
             $thePlugin = get_plugin_data($path . $srcFile);
             if ($thePlugin != null && $thePlugin != '' && $thePlugin['Name'] != '') {
                 $output .= __('Successfully installed the plugin', 'mainwp') . ' ' . $thePlugin['Name'] . ' ' . $thePlugin['Version'];
                 $plugin_slug = $result['destination_name'] . '/' . $srcFile;
                 if ($activatePlugin) {
                     activate_plugin($path . $srcFile, '', false, true);
                     do_action('mainwp_api_extension_activated', $path . $srcFile);
                 }
                 break;
             }
         }
     }
     if (!empty($error)) {
         $return['error'] = $error;
     } else {
         MainWP_Extensions::enableExtension($plugin_slug);
         $return['result'] = 'SUCCESS';
         $return['output'] = $output;
         $return['slug'] = $plugin_slug;
     }
     return $return;
 }
开发者ID:jexmex,项目名称:mainwp,代码行数:63,代码来源:page-mainwp-extensions.php

示例2: upgrade_premium

 public function upgrade_premium($premium = false)
 {
     if (!class_exists('WP_Upgrader')) {
         include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
     }
     if (!$premium || empty($premium)) {
         return array('error' => 'No premium files for upgrade.');
     }
     $upgrader = false;
     $pr_update = array();
     $themes = array();
     $plugins = array();
     $result = array();
     $premium_update = array();
     $premium_update = apply_filters('mwp_premium_perform_update', $premium_update);
     if (!empty($premium_update)) {
         foreach ($premium as $pr) {
             foreach ($premium_update as $key => $update) {
                 $update = array_change_key_case($update, CASE_LOWER);
                 if ($update['name'] == $pr['name']) {
                     // prepare bulk updates for premiums that use WordPress upgrader
                     if (isset($update['type'])) {
                         if ($update['type'] == 'plugin') {
                             if (isset($update['slug']) && !empty($update['slug'])) {
                                 $plugins[$update['slug']] = $update;
                             }
                         }
                         if ($update['type'] == 'theme') {
                             if (isset($update['template']) && !empty($update['template'])) {
                                 $themes[$update['template']] = $update;
                             }
                         }
                     }
                 } else {
                     unset($premium_update[$key]);
                 }
             }
         }
         // try default wordpress upgrader
         if (!empty($plugins)) {
             $updateplugins = $this->upgrade_plugins(array_values($plugins));
             if (!empty($updateplugins) && isset($updateplugins['upgraded'])) {
                 foreach ($premium_update as $key => $update) {
                     $update = array_change_key_case($update, CASE_LOWER);
                     foreach ($updateplugins['upgraded'] as $slug => $upgrade) {
                         if (isset($update['slug']) && $update['slug'] == $slug) {
                             if ($upgrade == 1) {
                                 unset($premium_update[$key]);
                             }
                             $pr_update['plugins']['upgraded'][md5($update['name'])] = $upgrade;
                         }
                     }
                 }
             }
         }
         //try direct install with overwrite
         if (!empty($premium_update)) {
             foreach ($premium_update as $update) {
                 $update = array_change_key_case($update, CASE_LOWER);
                 $update_result = false;
                 if (isset($update['url'])) {
                     if (defined('WP_INSTALLING') && file_exists(ABSPATH . '.maintenance')) {
                         $pr_update[$update['type'] . 's']['upgraded'][md5($update['name'])] = 'Site under maintanace.';
                     }
                     /** @handled class */
                     $upgrader_skin = new WP_Upgrader_Skin();
                     $upgrader_skin->done_header = true;
                     /** @handled class */
                     $upgrader = new WP_Upgrader();
                     @($update_result = $upgrader->run(array('package' => $update['url'], 'destination' => isset($update['type']) && $update['type'] == 'theme' ? WP_CONTENT_DIR . '/themes' : WP_PLUGIN_DIR, 'clear_destination' => true, 'clear_working' => true, 'is_multi' => true, 'hook_extra' => array())));
                     $update_result = !$update_result || is_wp_error($update_result) ? $this->mmb_get_error($update_result) : 1;
                 } else {
                     if (isset($update['callback'])) {
                         if (is_array($update['callback'])) {
                             $update_result = call_user_func(array($update['callback'][0], $update['callback'][1]));
                         } else {
                             if (is_string($update['callback'])) {
                                 $update_result = call_user_func($update['callback']);
                             } else {
                                 $update_result = 'Upgrade function "' . $update['callback'] . '" does not exists.';
                             }
                         }
                         $update_result = $update_result !== true ? $this->mmb_get_error($update_result) : 1;
                     } else {
                         $update_result = 'Bad update params.';
                     }
                 }
                 $pr_update[$update['type'] . 's']['upgraded'][md5($update['name'])] = $update_result;
             }
         }
         return $pr_update;
     } else {
         foreach ($premium as $pr) {
             $result[$pr['type'] . 's']['upgraded'][md5($pr['name'])] = 'This premium update is not registered.';
         }
         return $result;
     }
 }
开发者ID:onedaylabs,项目名称:onedaylabs.com,代码行数:98,代码来源:Installer.php

示例3: upgradePluginTheme


//.........这里部分代码省略.........
             if (count($themes) > 0) {
                 // To fix: optimizePressTheme update
                 $addFilterToFixUpdate_optimizePressTheme = false;
                 if (in_array('optimizePressTheme', $themes)) {
                     $addFilterToFixUpdate_optimizePressTheme = true;
                     add_filter('site_transient_update_themes', array($this, 'hookFixOptimizePressThemeUpdate'), 99);
                 }
                 //@see wp-admin/update.php
                 $upgrader = new Theme_Upgrader(new Bulk_Theme_Upgrader_Skin(compact('nonce', 'url')));
                 $result = $upgrader->bulk_upgrade($themes);
                 if ($addFilterToFixUpdate_optimizePressTheme) {
                     remove_filter('site_transient_update_themes', array($this, 'hookFixOptimizePressThemeUpdate'), 99);
                 }
                 if (!empty($result)) {
                     foreach ($result as $theme => $info) {
                         if (empty($info)) {
                             $information['upgrades'][$theme] = false;
                         } else {
                             $information['upgrades'][$theme] = true;
                         }
                     }
                 } else {
                     MainWP_Helper::error(__('Bad request', 'mainwp-child'));
                 }
             }
             if (count($premiumThemes) > 0) {
                 $mwp_premium_updates = apply_filters('mwp_premium_perform_update', array());
                 $mwp_premium_updates_todo = array();
                 $mwp_premium_updates_todo_slugs = array();
                 if (is_array($premiumThemes) && is_array($mwp_premium_updates)) {
                     foreach ($premiumThemes as $premiumTheme) {
                         foreach ($mwp_premium_updates as $key => $update) {
                             $slug = isset($update['slug']) ? $update['slug'] : $update['Name'];
                             if (0 === strcmp($slug, $premiumTheme)) {
                                 $mwp_premium_updates_todo[$key] = $update;
                                 $mwp_premium_updates_todo_slugs[] = $slug;
                             }
                         }
                     }
                 }
                 unset($mwp_premium_updates);
                 $premiumUpgrader = new Theme_Upgrader(new Bulk_Theme_Upgrader_Skin(compact('nonce', 'url')));
             }
             if (count($themes) <= 0 && count($premiumThemes) <= 0) {
                 MainWP_Helper::error(__('Bad request', 'mainwp-child'));
             }
             if (null !== $this->filterFunction) {
                 remove_filter('pre_site_transient_update_themes', $this->filterFunction, 99);
             }
         } else {
             MainWP_Helper::error(__('Bad request', 'mainwp-child'));
         }
     }
     if (count($mwp_premium_updates_todo) > 0) {
         //Upgrade via WP
         //@see wp-admin/update.php
         $result = $premiumUpgrader->bulk_upgrade($mwp_premium_updates_todo_slugs);
         if (!empty($result)) {
             foreach ($result as $plugin => $info) {
                 if (!empty($info)) {
                     $information['upgrades'][$plugin] = true;
                     foreach ($mwp_premium_updates_todo as $key => $update) {
                         $slug = isset($update['slug']) ? $update['slug'] : $update['Name'];
                         if (0 === strcmp($slug, $plugin)) {
                             //unset($mwp_premium_updates_todo[$key]);
                         }
                     }
                 }
             }
         }
         //Upgrade via callback
         foreach ($mwp_premium_updates_todo as $update) {
             $slug = isset($update['slug']) ? $update['slug'] : $update['Name'];
             if (isset($update['url'])) {
                 $installer = new WP_Upgrader();
                 //@see wp-admin/includes/class-wp-upgrader.php
                 $result = $installer->run(array('package' => $update['url'], 'destination' => 'plugin' === $update['type'] ? WP_PLUGIN_DIR : WP_CONTENT_DIR . '/themes', 'clear_destination' => true, 'clear_working' => true, 'hook_extra' => array()));
                 $information['upgrades'][$slug] = !is_wp_error($result) && !empty($result);
             } else {
                 if (isset($update['callback'])) {
                     if (is_array($update['callback']) && isset($update['callback'][0]) && isset($update['callback'][1])) {
                         $update_result = @call_user_func(array($update['callback'][0], $update['callback'][1]));
                         $information['upgrades'][$slug] = $update_result && true;
                     } else {
                         if (is_string($update['callback'])) {
                             $update_result = @call_user_func($update['callback']);
                             $information['upgrades'][$slug] = $update_result && true;
                         } else {
                             $information['upgrades'][$slug] = false;
                         }
                     }
                 } else {
                     $information['upgrades'][$slug] = false;
                 }
             }
         }
     }
     $information['sync'] = $this->getSiteStats(array(), false);
     MainWP_Helper::write($information);
 }
开发者ID:jexmex,项目名称:mainwp-child,代码行数:101,代码来源:class-mainwp-child.php

示例4: settings_panel

    public static function settings_panel()
    {
        if (isset($_GET['wpak_action']) && $_GET['wpak_action'] == 'upload-theme') {
            if (!current_user_can('upload_plugins') && !current_user_can('wpak_edit_apps')) {
                wp_die(__('You do not have sufficient permissions to install WP AppKit themes on this site.', WpAppKit::i18n_domain));
            }
            check_admin_referer('wpak-theme-upload');
            include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
            $file_upload = new File_Upload_Upgrader('themezip', 'package');
            $file_type = wp_check_filetype($file_upload->filename);
            if ($file_type['ext'] == 'zip' && $file_type['type'] == 'application/zip') {
                $title = sprintf(__('Installing WP AppKit from uploaded file: %s', WpAppKit::i18n_domain), esc_html(basename($file_upload->filename)));
                $nonce = 'wpak-theme-upload';
                $url = add_query_arg(array('package' => $file_upload->id));
                // A nonce is passed to WP_Upgrader_Skin class, so wp_nonce_url() is called and url is escaped there...
                $upgrader = new WP_Upgrader(new WP_Upgrader_Skin(compact('title', 'nonce', 'url')));
                $destination_folder_name = basename(sanitize_file_name($file_upload->filename), ".zip");
                $result = $upgrader->run(array('package' => $file_upload->package, 'destination' => WpakThemes::get_themes_directory() . '/' . $destination_folder_name, 'clear_destination' => true, 'clear_working' => true, 'hook_extra' => array()));
                if ($result || is_wp_error($result)) {
                    $file_upload->cleanup();
                }
                if (!is_wp_error($result)) {
                    echo sprintf(__("WP AppKit theme '%s' installed successfully!", WpAppKit::i18n_domain), $destination_folder_name);
                } else {
                    _e('An error occured', WpAppKit::i18n_domain);
                    echo ' : ' . $result->get_error_message();
                }
                echo '<br/><br/><a href="' . esc_url(remove_query_arg('wpak_action')) . '">' . __('Back to theme upload form', WpAppKit::i18n_domain) . '</a>';
                echo '<br/><br/><a href="' . admin_url() . '/edit.php?post_type=wpak_apps">' . __('Go to my WP AppKit app list', WpAppKit::i18n_domain) . '</a>';
            } else {
                _e("Uploaded file must be a valid zip file", WpAppKit::i18n_domain);
            }
        } else {
            ?>
			<div class="wrap" id="wpak-settings">
				<h2><?php 
            _e('WP AppKit Themes upload', WpAppKit::i18n_domain);
            ?>
</h2>

				<?php 
            if (!empty($result['message'])) {
                ?>
					<div class="<?php 
                echo $result['type'];
                ?>
" ><p><?php 
                echo $result['message'];
                ?>
</p></div>
				<?php 
            }
            ?>

				<div class="upload-plugin">
					<p class="install-help"><?php 
            _e('If you have a WP AppKit theme in a .zip format, you may install it by uploading it here.');
            ?>
</p>
					<form method="post" enctype="multipart/form-data" class="wp-upload-form" action="<?php 
            echo esc_url(add_query_arg(array('wpak_action' => 'upload-theme')));
            ?>
">
						<?php 
            wp_nonce_field('wpak-theme-upload');
            ?>
						<label class="screen-reader-text" for="themezip"><?php 
            _e('WP AppKit Theme zip file', WpAppKit::i18n_domain);
            ?>
</label>
						<input type="file" id="themezip" name="themezip" />
						<?php 
            submit_button(__('Install Now'), 'button', 'install-theme-submit', false);
            ?>
					</form>
				</div>

			</div>
			<?php 
        }
    }
开发者ID:hiddenpearls,项目名称:wp-appkit,代码行数:81,代码来源:upload-themes.php


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