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


PHP WP_CLI::get_upgrader方法代码示例

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


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

示例1: update_multiple

 private function update_multiple($args, $assoc_args)
 {
     // Grab all items that need updates
     // If we have no sub-arguments, add them to the output list.
     $item_list = "Available {$this->item_type} updates:";
     $items_to_update = array();
     foreach ($this->get_item_list() as $file) {
         if ($this->get_update_status($file)) {
             $items_to_update[] = $file;
             if (empty($assoc_args)) {
                 if (false === strpos($file, '/')) {
                     $name = str_replace('.php', '', basename($file));
                 } else {
                     $name = dirname($file);
                 }
                 $item_list .= "\n\t%y{$name}%n";
             }
         }
     }
     if (empty($items_to_update)) {
         WP_CLI::line("No {$this->item_type} updates available.");
         return;
     }
     // If --all, UPDATE ALL THE THINGS
     if (isset($assoc_args['all'])) {
         $upgrader = WP_CLI::get_upgrader($this->upgrader);
         $result = $upgrader->bulk_upgrade($items_to_update);
         // Let the user know the results.
         $num_to_update = count($items_to_update);
         $num_updated = count(array_filter($result));
         $line = "Updated {$num_updated}/{$num_to_update} {$this->item_type}s.";
         if ($num_to_update == $num_updated) {
             WP_CLI::success($line);
         } else {
             if ($num_updated > 0) {
                 WP_CLI::warning($line);
             } else {
                 WP_CLI::error($line);
             }
         }
         // Else list items that require updates
     } else {
         WP_CLI::line($item_list);
     }
 }
开发者ID:bytewang,项目名称:wp-cli,代码行数:45,代码来源:class-wp-cli-command-with-upgrade.php

示例2: update

 /**
  * Update the WordPress core
  *
  * @param array $args
  */
 function update($args)
 {
     wp_version_check();
     $from_api = get_site_transient('update_core');
     if (empty($from_api->updates)) {
         $update = false;
     } else {
         list($update) = $from_api->updates;
     }
     require_once ABSPATH . 'wp-admin/includes/upgrade.php';
     $upgrader = WP_CLI::get_upgrader('Core_Upgrader');
     $result = $upgrader->upgrade($update);
     if (is_wp_error($result)) {
         $msg = WP_CLI::errorToString($result);
         if ('up_to_date' != $result->get_error_code()) {
             WP_CLI::error($msg);
         } else {
             WP_CLI::success($msg);
         }
     } else {
         WP_CLI::success('WordPress updated successfully.');
     }
 }
开发者ID:noahmuller,项目名称:wp-cli,代码行数:28,代码来源:core.php

示例3: update

 /**
  * Update the WordPress core
  *
  * @param array $args
  * @param array $assoc_args
  */
 function update($args, $assoc_args)
 {
     global $wp_version;
     $update = $from_api = null;
     $upgrader = 'Core_Upgrader';
     if (empty($assoc_args['version'])) {
         wp_version_check();
         $from_api = get_site_transient('update_core');
         if (empty($from_api->updates)) {
             $update = false;
         } else {
             list($update) = $from_api->updates;
         }
     } else {
         if (version_compare($wp_version, $assoc_args['version'], '<') || isset($assoc_args['force'])) {
             $new_package = null;
             if (empty($args[0])) {
                 $new_package = 'https://wordpress.org/wordpress-' . $assoc_args['version'] . '.zip';
                 WP_CLI::line(sprintf('Downloading WordPress %s (%s)...', $assoc_args['version'], 'en_US'));
             } else {
                 $new_package = $args[0];
                 $upgrader = 'Non_Destructive_Core_Upgrader';
             }
             $update = (object) array('response' => 'upgrade', 'current' => $assoc_args['version'], 'download' => $new_package, 'packages' => (object) array('partial' => null, 'new_bundled' => null, 'no_content' => null, 'full' => $new_package));
         } else {
             WP_CLI::success('WordPress is up to date.');
             return;
         }
     }
     require_once ABSPATH . 'wp-admin/includes/upgrade.php';
     $result = WP_CLI::get_upgrader($upgrader)->upgrade($update);
     if (is_wp_error($result)) {
         $msg = WP_CLI::error_to_string($result);
         if ('up_to_date' != $result->get_error_code()) {
             WP_CLI::error($msg);
         } else {
             WP_CLI::success($msg);
         }
     } else {
         WP_CLI::success('WordPress updated successfully.');
     }
 }
开发者ID:rpeterson,项目名称:wp-cli,代码行数:48,代码来源:core.php

示例4: install

 /**
  * Install a new plugin
  *
  * @param array $args
  * @param array $assoc_args
  */
 function install($args, $assoc_args)
 {
     if (empty($args)) {
         WP_CLI::line("usage: wp plugin install <plugin-name>");
         exit;
     }
     $slug = stripslashes($args[0]);
     // Force WordPress to update the plugin list
     wp_update_plugins();
     $api = plugins_api('plugin_information', array('slug' => $slug));
     if (!$api) {
         WP_CLI::error('Can\'t find the plugin in the WordPress.org plugins repository.');
         exit;
     }
     if (isset($assoc_args['dev'])) {
         list($link) = explode($slug, $api->download_link);
         $api->download_link = $link . $slug . '.zip';
         $api->version = 'Development Version';
     }
     $status = install_plugin_install_status($api);
     WP_CLI::line(sprintf('Installing %s (%s)', $api->name, $api->version));
     switch ($status['status']) {
         case 'update_available':
         case 'install':
             $upgrader = WP_CLI::get_upgrader('Plugin_Upgrader');
             $result = $upgrader->install($api->download_link);
             if ($result) {
                 if (isset($assoc_args['activate'])) {
                     system("wp plugin activate " . WP_CLI::compose_args($args, $assoc_args));
                 }
             }
             break;
         case 'newer_installed':
             WP_CLI::error(sprintf('Newer version (%s) installed', $status['version']));
             break;
         case 'latest_installed':
             WP_CLI::error('Latest version already installed');
             break;
     }
 }
开发者ID:bytewang,项目名称:wp-cli,代码行数:46,代码来源:plugin.php

示例5: install_from_repo

 protected function install_from_repo($slug, $assoc_args)
 {
     $result = NULL;
     $api = themes_api('theme_information', array('slug' => $slug));
     if (is_wp_error($api)) {
         if (null === maybe_unserialize($api->get_error_data())) {
             WP_CLI::error("Can't find the theme in the WordPress.org repository.");
         } else {
             WP_CLI::error($api);
         }
     }
     // Check to see if we should update, rather than install.
     if ($this->get_update_status($slug)) {
         WP_CLI::line(sprintf('Updating %s (%s)', $api->name, $api->version));
         $result = WP_CLI::get_upgrader($this->upgrader)->upgrade($slug);
         /**
          *  Else, if there's no update, it's either not installed,
          *  or it's newer than what we've got.
          */
     } else {
         if (!is_readable($this->get_stylesheet_path($slug))) {
             WP_CLI::line(sprintf('Installing %s (%s)', $api->name, $api->version));
             $result = WP_CLI::get_upgrader($this->upgrader)->install($api->download_link);
         } else {
             WP_CLI::error('Theme already installed and up to date.');
         }
     }
     // Finally, activate theme if requested.
     if ($result && isset($assoc_args['activate'])) {
         WP_CLI::line("Activating '{$slug}'...");
         $this->activate(array($slug));
     }
 }
开发者ID:roelven,项目名称:wp-cli,代码行数:33,代码来源:theme.php

示例6: update

 /**
  * Update a plugin
  *
  * @param array $args
  */
 function update($args)
 {
     list($file, $name) = $this->parse_name($args, __FUNCTION__);
     // Force WordPress to update the plugin list
     wp_update_plugins();
     $upgrader = WP_CLI::get_upgrader('Plugin_Upgrader');
     $result = $upgrader->upgrade($file);
 }
开发者ID:noahmuller,项目名称:wp-cli,代码行数:13,代码来源:plugin.php

示例7: install_from_repo

 protected function install_from_repo($slug, $assoc_args)
 {
     $api = plugins_api('plugin_information', array('slug' => $slug));
     if (is_wp_error($api)) {
         if (null === maybe_unserialize($api->get_error_data())) {
             WP_CLI::error("Can't find the plugin in the WordPress.org repository.");
         } else {
             WP_CLI::error($api);
         }
     }
     if (isset($assoc_args['version'])) {
         list($link) = explode($slug, $api->download_link);
         if ('dev' == $assoc_args['version']) {
             $api->download_link = $link . $slug . '.zip';
             $api->version = 'Development Version';
         } else {
             $api->download_link = $link . $slug . '.' . $assoc_args['version'] . '.zip';
             $api->version = $assoc_args['version'];
             // check if the requested version exists
             $response = wp_remote_head($api->download_link);
             if (!$response || $response['headers']['content-type'] != 'application/octet-stream') {
                 WP_CLI::error("Can't find the requested plugin's version " . $assoc_args['version'] . " in the WordPress.org plugins repository.");
             }
         }
     }
     $status = install_plugin_install_status($api);
     WP_CLI::line(sprintf('Installing %s (%s)', $api->name, $api->version));
     switch ($status['status']) {
         case 'update_available':
         case 'install':
             $upgrader = WP_CLI::get_upgrader($this->upgrader);
             $result = $upgrader->install($api->download_link);
             if ($result && isset($assoc_args['activate'])) {
                 WP_CLI::line("Activating '{$slug}'...");
                 $this->activate(array($slug));
             }
             break;
         case 'newer_installed':
             WP_CLI::error(sprintf('Newer version (%s) installed.', $status['version']));
             break;
         case 'latest_installed':
             WP_CLI::error('Latest version already installed.');
             break;
     }
 }
开发者ID:roelven,项目名称:wp-cli,代码行数:45,代码来源:plugin.php


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